Skip to content

Commit 8f96374

Browse files
mh-dmthinkyhead
authored andcommitted
Combined jerk calculation.
1 parent eaa9fff commit 8f96374

1 file changed

Lines changed: 43 additions & 44 deletions

File tree

Marlin/src/module/planner.cpp

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,31 +2773,46 @@ bool Planner::_populate_block(
27732773
* Heavily modified. Originally adapted from Průša firmware.
27742774
* https://github.com/prusa3d/Prusa-Firmware
27752775
*/
2776+
#if defined(TRAVEL_EXTRA_XYJERK) || ENABLED(LIN_ADVANCE)
2777+
xyze_float_t max_j = max_jerk;
2778+
#else
2779+
const xyze_float_t &max_j = max_jerk;
2780+
#endif
2781+
27762782
#ifdef TRAVEL_EXTRA_XYJERK
2777-
#define HAS_TRAVEL_EXTRA_XYJERK 1
27782783
const float extra_xyjerk = TERN0(HAS_EXTRUDERS, dist.e <= 0) ? TRAVEL_EXTRA_XYJERK : 0.0f;
2784+
max_j[X_AXIS] += extra_xyjerk;
2785+
max_j[Y_AXIS] += extra_xyjerk;
27792786
#endif
27802787

2781-
if (!moves_queued || UNEAR_ZERO(previous_nominal_speed)) {
2782-
// Compute "safe" speed, limited by a jerk to/from full halt.
2783-
2784-
float v_factor = 1.0f;
2785-
LOOP_LOGICAL_AXES(i) {
2786-
const float jerk = ABS(current_speed[i]); // Starting from zero, change in speed for this axis
2787-
float maxj = max_jerk[i];
2788-
TERN_(HAS_TRAVEL_EXTRA_XYJERK, if (i == X_AXIS || i == Y_AXIS) maxj += extra_xyjerk);
2789-
if (jerk * v_factor > maxj) v_factor = maxj / jerk;
2788+
#if ENABLED(LIN_ADVANCE)
2789+
// Advance affects E_AXIS speed and therefore jerk. Add a speed correction whenever
2790+
// LA is turned OFF. No correction is applied when LA is turned ON (because it didn't
2791+
// perform well; it takes more time/effort to push/melt filament than the reverse).
2792+
static uint32_t previous_advance_rate;
2793+
static float previous_e_mm_per_step;
2794+
if (dist.e < 0 && previous_advance_rate) {
2795+
// Retract move after a segment with LA that ended with an E speed decrease.
2796+
// Correct for this to allow a faster junction speed. Since the decrease always helps to
2797+
// get E to nominal retract speed, the equation simplifies to an increase in max jerk.
2798+
max_j[E_AXIS] = previous_advance_rate * previous_e_mm_per_step;
27902799
}
2791-
vmax_junction_sqr = sq(block->nominal_speed * v_factor);
2792-
minimum_planner_speed_sqr = vmax_junction_sqr;
2793-
}
2794-
else {
2800+
// Prepare for next segment.
2801+
previous_advance_rate = block->la_advance_rate;
2802+
previous_e_mm_per_step = mm_per_step[E_AXIS_N(extruder)];
2803+
#endif
2804+
2805+
xyze_float_t speed_diff;
2806+
float vmax_junction;
2807+
if (!moves_queued || UNEAR_ZERO(previous_nominal_speed)) {
2808+
// Limited by a jerk to/from full halt.
2809+
vmax_junction = block->nominal_speed;
2810+
speed_diff = current_speed;
2811+
} else {
27952812
// Compute the maximum velocity allowed at a joint of two successive segments.
27962813

27972814
// The junction velocity will be shared between successive segments. Limit the junction velocity to their minimum.
27982815
// Scale per-axis velocities for the same vmax_junction.
2799-
float vmax_junction;
2800-
xyze_float_t speed_diff;
28012816
if (block->nominal_speed < previous_nominal_speed) {
28022817
vmax_junction = block->nominal_speed;
28032818
xyze_float_t v_exit = previous_speed * (vmax_junction / previous_nominal_speed);
@@ -2808,36 +2823,20 @@ bool Planner::_populate_block(
28082823
xyze_float_t v_entry = current_speed * (vmax_junction / block->nominal_speed);
28092824
speed_diff = v_entry - previous_speed;
28102825
}
2826+
}
28112827

2812-
#if ENABLED(LIN_ADVANCE)
2813-
// Advance affects E_AXIS speed and therefore jerk. Add a speed correction whenever
2814-
// LA is turned OFF. No correction is applied when LA is turned ON (because it didn't
2815-
// perform well; it takes more time/effort to push/melt filament than the reverse).
2816-
static uint32_t previous_advance_rate;
2817-
static float previous_e_mm_per_step;
2818-
float advance_correction_mm_s = 0.0f;
2819-
if (dist.e < 0 && previous_advance_rate) {
2820-
// Retract move after a segment with LA that ended with an E speed decrease.
2821-
// Correct for this to allow a faster junction speed. Since the decrease always helps to
2822-
// get E to nominal retract speed, the equation simplifies to an increase in max jerk.
2823-
advance_correction_mm_s = previous_advance_rate * previous_e_mm_per_step;
2824-
}
2825-
// Prepare for next segment.
2826-
previous_advance_rate = block->la_advance_rate;
2827-
previous_e_mm_per_step = mm_per_step[E_AXIS_N(extruder)];
2828-
#endif
2828+
// Now limit the jerk in all axes.
2829+
float v_factor = 1.0f;
2830+
LOOP_LOGICAL_AXES(i) {
2831+
// Jerk is the per-axis velocity difference.
2832+
const float jerk = ABS(speed_diff[i]);
2833+
float maxj = max_j[i];
2834+
if (jerk * v_factor > maxj) v_factor = maxj / jerk;
2835+
}
2836+
vmax_junction_sqr = sq(vmax_junction * v_factor);
28292837

2830-
// Now limit the jerk in all axes.
2831-
float v_factor = 1.0f;
2832-
LOOP_LOGICAL_AXES(i) {
2833-
// Jerk is the per-axis velocity difference.
2834-
const float jerk = ABS(speed_diff[i]);
2835-
float maxj = max_jerk[i];
2836-
TERN_(HAS_TRAVEL_EXTRA_XYJERK, if (i == X_AXIS || i == Y_AXIS) maxj += extra_xyjerk);
2837-
TERN_(LIN_ADVANCE, if (i == E_AXIS) maxj += advance_correction_mm_s);
2838-
if (jerk * v_factor > maxj) v_factor = maxj / jerk;
2839-
}
2840-
vmax_junction_sqr = sq(vmax_junction * v_factor);
2838+
if (!moves_queued || UNEAR_ZERO(previous_nominal_speed)) {
2839+
minimum_planner_speed_sqr = vmax_junction_sqr;
28412840
}
28422841

28432842
#endif // CLASSIC_JERK

0 commit comments

Comments
 (0)