Skip to content

Commit 1dfbca0

Browse files
author
Luca Toniolo
committed
Fix jerk calculation units in getStraightJerk()
Use cubic root for characteristic time (t = cbrt(d/j)) and cube of time for path jerk (jerk = d/t³) to match jerk-limited motion physics.
1 parent 8f5a2e3 commit 1dfbca0

1 file changed

Lines changed: 25 additions & 22 deletions

File tree

src/emc/task/emccanon.cc

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -704,13 +704,16 @@ static double getStraightJerk(double x, double y, double z,
704704
}
705705

706706
// Pure linear move:
707+
// For jerk-limited motion: d = (1/6)*j*t³, so t = cbrt(6*d/j)
708+
// We use t = cbrt(d/j) as a characteristic time (omitting the constant factor,
709+
// which cancels out when we compute path jerk = dtot / tmax³)
707710
if (canon.cartesian_move && !canon.angular_move) {
708-
tx = dx? (dx / FROM_EXT_LEN(emcAxisGetMaxJerk(0))): 0.0;
709-
ty = dy? (dy / FROM_EXT_LEN(emcAxisGetMaxJerk(1))): 0.0;
710-
tz = dz? (dz / FROM_EXT_LEN(emcAxisGetMaxJerk(2))): 0.0;
711-
tu = du? (du / FROM_EXT_LEN(emcAxisGetMaxJerk(6))): 0.0;
712-
tv = dv? (dv / FROM_EXT_LEN(emcAxisGetMaxJerk(7))): 0.0;
713-
tw = dw? (dw / FROM_EXT_LEN(emcAxisGetMaxJerk(8))): 0.0;
711+
tx = dx? cbrt(dx / FROM_EXT_LEN(emcAxisGetMaxJerk(0))): 0.0;
712+
ty = dy? cbrt(dy / FROM_EXT_LEN(emcAxisGetMaxJerk(1))): 0.0;
713+
tz = dz? cbrt(dz / FROM_EXT_LEN(emcAxisGetMaxJerk(2))): 0.0;
714+
tu = du? cbrt(du / FROM_EXT_LEN(emcAxisGetMaxJerk(6))): 0.0;
715+
tv = dv? cbrt(dv / FROM_EXT_LEN(emcAxisGetMaxJerk(7))): 0.0;
716+
tw = dw? cbrt(dw / FROM_EXT_LEN(emcAxisGetMaxJerk(8))): 0.0;
714717
out.tmax = MAX3(tx, ty ,tz);
715718
out.tmax = MAX4(tu, tv, tw, out.tmax);
716719

@@ -720,38 +723,38 @@ static double getStraightJerk(double x, double y, double z,
720723
out.dtot = sqrt(du * du + dv * dv + dw * dw);
721724

722725
if (out.tmax > 0.0) {
723-
out.jerk = out.dtot / (out.tmax * out.tmax);
726+
out.jerk = out.dtot / (out.tmax * out.tmax * out.tmax);
724727
}
725728
}
726729
// Pure angular move:
727730
else if (!canon.cartesian_move && canon.angular_move) {
728-
ta = da? (da / FROM_EXT_ANG(emcAxisGetMaxJerk(3))): 0.0;
729-
tb = db? (db / FROM_EXT_ANG(emcAxisGetMaxJerk(4))): 0.0;
730-
tc = dc? (dc / FROM_EXT_ANG(emcAxisGetMaxJerk(5))): 0.0;
731+
ta = da? cbrt(da / FROM_EXT_ANG(emcAxisGetMaxJerk(3))): 0.0;
732+
tb = db? cbrt(db / FROM_EXT_ANG(emcAxisGetMaxJerk(4))): 0.0;
733+
tc = dc? cbrt(dc / FROM_EXT_ANG(emcAxisGetMaxJerk(5))): 0.0;
731734
out.tmax = MAX3(ta, tb, tc);
732735

733736
out.dtot = sqrt(da * da + db * db + dc * dc);
734737
if (out.tmax > 0.0) {
735-
out.jerk = out.dtot / (out.tmax * out.tmax);
738+
out.jerk = out.dtot / (out.tmax * out.tmax * out.tmax);
736739
}
737740
}
738741
// Combination angular and linear move:
739742
else if (canon.cartesian_move && canon.angular_move) {
740-
tx = dx? (dx / FROM_EXT_LEN(emcAxisGetMaxJerk(0))): 0.0;
741-
ty = dy? (dy / FROM_EXT_LEN(emcAxisGetMaxJerk(1))): 0.0;
742-
tz = dz? (dz / FROM_EXT_LEN(emcAxisGetMaxJerk(2))): 0.0;
743-
ta = da? (da / FROM_EXT_ANG(emcAxisGetMaxJerk(3))): 0.0;
744-
tb = db? (db / FROM_EXT_ANG(emcAxisGetMaxJerk(4))): 0.0;
745-
tc = dc? (dc / FROM_EXT_ANG(emcAxisGetMaxJerk(5))): 0.0;
746-
tu = du? (du / FROM_EXT_LEN(emcAxisGetMaxJerk(6))): 0.0;
747-
tv = dv? (dv / FROM_EXT_LEN(emcAxisGetMaxJerk(7))): 0.0;
748-
tw = dw? (dw / FROM_EXT_LEN(emcAxisGetMaxJerk(8))): 0.0;
743+
tx = dx? cbrt(dx / FROM_EXT_LEN(emcAxisGetMaxJerk(0))): 0.0;
744+
ty = dy? cbrt(dy / FROM_EXT_LEN(emcAxisGetMaxJerk(1))): 0.0;
745+
tz = dz? cbrt(dz / FROM_EXT_LEN(emcAxisGetMaxJerk(2))): 0.0;
746+
ta = da? cbrt(da / FROM_EXT_ANG(emcAxisGetMaxJerk(3))): 0.0;
747+
tb = db? cbrt(db / FROM_EXT_ANG(emcAxisGetMaxJerk(4))): 0.0;
748+
tc = dc? cbrt(dc / FROM_EXT_ANG(emcAxisGetMaxJerk(5))): 0.0;
749+
tu = du? cbrt(du / FROM_EXT_LEN(emcAxisGetMaxJerk(6))): 0.0;
750+
tv = dv? cbrt(dv / FROM_EXT_LEN(emcAxisGetMaxJerk(7))): 0.0;
751+
tw = dw? cbrt(dw / FROM_EXT_LEN(emcAxisGetMaxJerk(8))): 0.0;
749752
out.tmax = MAX9(tx, ty, tz,
750753
ta, tb, tc,
751754
tu, tv, tw);
752755

753756
if(debug_velacc)
754-
printf("getStraightJerk t^2 tx %g ty %g tz %g ta %g tb %g tc %g tu %g tv %g tw %g\n",
757+
printf("getStraightJerk t tx %g ty %g tz %g ta %g tb %g tc %g tu %g tv %g tw %g\n",
755758
tx, ty, tz, ta, tb, tc, tu, tv, tw);
756759

757760
if(dx || dy || dz)
@@ -760,7 +763,7 @@ static double getStraightJerk(double x, double y, double z,
760763
out.dtot = sqrt(du * du + dv * dv + dw * dw);
761764

762765
if (out.tmax > 0.0) {
763-
out.jerk = out.dtot / (out.tmax * out.tmax);
766+
out.jerk = out.dtot / (out.tmax * out.tmax * out.tmax);
764767
}
765768
}
766769
//if(debug_velacc)

0 commit comments

Comments
 (0)