@@ -784,7 +784,7 @@ void Planner::calculate_trapezoid_for_block(block_t* const block, const float &e
784
784
NOLESS (initial_rate, uint32_t (MINIMAL_STEP_RATE));
785
785
NOLESS (final_rate, uint32_t (MINIMAL_STEP_RATE));
786
786
787
- #if ENABLED (S_CURVE_ACCELERATION)
787
+ #if EITHER (S_CURVE_ACCELERATION, LIN_ADVANCE )
788
788
uint32_t cruise_rate = initial_rate;
789
789
#endif
790
790
@@ -805,7 +805,7 @@ void Planner::calculate_trapezoid_for_block(block_t* const block, const float &e
805
805
accelerate_steps = _MIN (uint32_t (_MAX (accelerate_steps_float, 0 )), block->step_event_count );
806
806
plateau_steps = 0 ;
807
807
808
- #if ENABLED (S_CURVE_ACCELERATION)
808
+ #if EITHER (S_CURVE_ACCELERATION, LIN_ADVANCE )
809
809
// We won't reach the cruising rate. Let's calculate the speed we will reach
810
810
cruise_rate = final_speed (initial_rate, accel, accelerate_steps);
811
811
#endif
@@ -837,6 +837,14 @@ void Planner::calculate_trapezoid_for_block(block_t* const block, const float &e
837
837
#endif
838
838
block->final_rate = final_rate;
839
839
840
+ #if ENABLED(LIN_ADVANCE)
841
+ if (block->la_advance_rate ) {
842
+ const float comp = extruder_advance_K[block->extruder ] * block->steps .e / block->step_event_count ;
843
+ block->max_adv_steps = cruise_rate * comp;
844
+ block->final_adv_steps = final_rate * comp;
845
+ }
846
+ #endif
847
+
840
848
/* *
841
849
* Laser trapezoid calculations
842
850
*
@@ -1183,13 +1191,6 @@ void Planner::recalculate_trapezoids() {
1183
1191
const float current_nominal_speed = SQRT (block->nominal_speed_sqr ),
1184
1192
nomr = 1 .0f / current_nominal_speed;
1185
1193
calculate_trapezoid_for_block (block, current_entry_speed * nomr, next_entry_speed * nomr);
1186
- #if ENABLED(LIN_ADVANCE)
1187
- if (block->use_advance_lead ) {
1188
- const float comp = block->e_D_ratio * extruder_advance_K[active_extruder] * settings.axis_steps_per_mm [E_AXIS];
1189
- block->max_adv_steps = current_nominal_speed * comp;
1190
- block->final_adv_steps = next_entry_speed * comp;
1191
- }
1192
- #endif
1193
1194
}
1194
1195
1195
1196
// Reset current only to ensure next trapezoid is computed - The
@@ -1222,13 +1223,6 @@ void Planner::recalculate_trapezoids() {
1222
1223
const float next_nominal_speed = SQRT (next->nominal_speed_sqr ),
1223
1224
nomr = 1 .0f / next_nominal_speed;
1224
1225
calculate_trapezoid_for_block (next, next_entry_speed * nomr, float (MINIMUM_PLANNER_SPEED) * nomr);
1225
- #if ENABLED(LIN_ADVANCE)
1226
- if (next->use_advance_lead ) {
1227
- const float comp = next->e_D_ratio * extruder_advance_K[active_extruder] * settings.axis_steps_per_mm [E_AXIS];
1228
- next->max_adv_steps = next_nominal_speed * comp;
1229
- next->final_adv_steps = (MINIMUM_PLANNER_SPEED) * comp;
1230
- }
1231
- #endif
1232
1226
}
1233
1227
1234
1228
// Reset next only to ensure its trapezoid is computed - The stepper is free to use
@@ -2216,10 +2210,12 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
2216
2210
// Compute and limit the acceleration rate for the trapezoid generator.
2217
2211
const float steps_per_mm = block->step_event_count * inverse_millimeters;
2218
2212
uint32_t accel;
2213
+ #if ENABLED(LIN_ADVANCE)
2214
+ bool use_advance_lead = false ;
2215
+ #endif
2219
2216
if (!block->steps .a && !block->steps .b && !block->steps .c ) {
2220
2217
// convert to: acceleration steps/sec^2
2221
2218
accel = CEIL (settings.retract_acceleration * steps_per_mm);
2222
- TERN_ (LIN_ADVANCE, block->use_advance_lead = false );
2223
2219
}
2224
2220
else {
2225
2221
#define LIMIT_ACCEL_LONG (AXIS,INDX ) do { \
@@ -2252,27 +2248,23 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
2252
2248
*
2253
2249
* de > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
2254
2250
*/
2255
- block->use_advance_lead = esteps
2256
- && extruder_advance_K[active_extruder]
2257
- && de > 0 ;
2258
-
2259
- if (block->use_advance_lead ) {
2260
- block->e_D_ratio = (target_float.e - position_float.e ) /
2261
- #if IS_KINEMATIC
2262
- block->millimeters
2263
- #else
2251
+ use_advance_lead = esteps && extruder_advance_K[extruder] && de > 0 ;
2252
+
2253
+ if (use_advance_lead) {
2254
+ float e_D_ratio = (target_float.e - position_float.e ) /
2255
+ TERN (IS_KINEMATIC, block->millimeters ,
2264
2256
SQRT (sq (target_float.x - position_float.x )
2265
2257
+ sq (target_float.y - position_float.y )
2266
2258
+ sq (target_float.z - position_float.z ))
2267
- #endif
2268
- ;
2259
+ );
2269
2260
2270
2261
// Check for unusual high e_D ratio to detect if a retract move was combined with the last print move due to min. steps per segment. Never execute this with advance!
2271
2262
// This assumes no one will use a retract length of 0mm < retr_length < ~0.2mm and no one will print 100mm wide lines using 3mm filament or 35mm wide lines using 1.75mm filament.
2272
- if (block-> e_D_ratio > 3 .0f )
2273
- block-> use_advance_lead = false ;
2263
+ if (e_D_ratio > 3 .0f )
2264
+ use_advance_lead = false ;
2274
2265
else {
2275
- const uint32_t max_accel_steps_per_s2 = MAX_E_JERK (extruder) / (extruder_advance_K[active_extruder] * block->e_D_ratio ) * steps_per_mm;
2266
+ // Scale E acceleration so that it will be possible to jump to the advance speed.
2267
+ const uint32_t max_accel_steps_per_s2 = MAX_E_JERK (extruder) / (extruder_advance_K[extruder] * e_D_ratio) * steps_per_mm;
2276
2268
if (TERN0 (LA_DEBUG, accel > max_accel_steps_per_s2))
2277
2269
SERIAL_ECHOLNPGM (" Acceleration limited." );
2278
2270
NOMORE (accel, max_accel_steps_per_s2);
@@ -2300,13 +2292,20 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
2300
2292
block->acceleration_rate = (uint32_t )(accel * (4096 .0f * 4096 .0f / (STEPPER_TIMER_RATE)));
2301
2293
#endif
2302
2294
#if ENABLED(LIN_ADVANCE)
2303
- if (block->use_advance_lead ) {
2304
- block->advance_speed = (STEPPER_TIMER_RATE) / (extruder_advance_K[active_extruder] * block->e_D_ratio * block->acceleration * settings.axis_steps_per_mm [E_AXIS_N (extruder)]);
2295
+ block->la_advance_rate = 0 ;
2296
+ block->la_scaling = 0 ;
2297
+
2298
+ if (use_advance_lead) {
2299
+ // the Bresenham algorithm will convert this step rate into extruder steps
2300
+ block->la_advance_rate = extruder_advance_K[extruder] * block->acceleration_steps_per_s2 ;
2301
+
2302
+ // reduce LA ISR frequency by calling it only often enough to ensure that there will
2303
+ // never be more than four extruder steps per call
2304
+ for (uint32_t dividend = block->steps .e << 1 ; dividend <= (block->step_event_count >> 2 ); dividend <<= 1 )
2305
+ block->la_scaling ++;
2305
2306
#if ENABLED(LA_DEBUG)
2306
- if (extruder_advance_K[active_extruder] * block->e_D_ratio * block->acceleration * 2 < SQRT (block->nominal_speed_sqr ) * block->e_D_ratio )
2307
- SERIAL_ECHOLNPGM (" More than 2 steps per eISR loop executed." );
2308
- if (block->advance_speed < 200 )
2309
- SERIAL_ECHOLNPGM (" eISR running at > 10kHz." );
2307
+ if (block->la_advance_rate >> block->la_scaling > 10000 )
2308
+ SERIAL_ECHOLNPGM (" eISR running at > 10kHz: " , block->la_advance_rate );
2310
2309
#endif
2311
2310
}
2312
2311
#endif
0 commit comments