Skip to content

Commit 3a50c1e

Browse files
queeupCloudedQuartz
authored andcommitted
1 parent bc15ef2 commit 3a50c1e

File tree

4 files changed

+235
-266
lines changed

4 files changed

+235
-266
lines changed

source/Marlin/src/module/planner.cpp

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ void Planner::calculate_trapezoid_for_block(block_t* const block, const float &e
784784
NOLESS(initial_rate, uint32_t(MINIMAL_STEP_RATE));
785785
NOLESS(final_rate, uint32_t(MINIMAL_STEP_RATE));
786786

787-
#if ENABLED(S_CURVE_ACCELERATION)
787+
#if EITHER(S_CURVE_ACCELERATION, LIN_ADVANCE)
788788
uint32_t cruise_rate = initial_rate;
789789
#endif
790790

@@ -805,7 +805,7 @@ void Planner::calculate_trapezoid_for_block(block_t* const block, const float &e
805805
accelerate_steps = _MIN(uint32_t(_MAX(accelerate_steps_float, 0)), block->step_event_count);
806806
plateau_steps = 0;
807807

808-
#if ENABLED(S_CURVE_ACCELERATION)
808+
#if EITHER(S_CURVE_ACCELERATION, LIN_ADVANCE)
809809
// We won't reach the cruising rate. Let's calculate the speed we will reach
810810
cruise_rate = final_speed(initial_rate, accel, accelerate_steps);
811811
#endif
@@ -837,6 +837,14 @@ void Planner::calculate_trapezoid_for_block(block_t* const block, const float &e
837837
#endif
838838
block->final_rate = final_rate;
839839

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+
840848
/**
841849
* Laser trapezoid calculations
842850
*
@@ -1183,13 +1191,6 @@ void Planner::recalculate_trapezoids() {
11831191
const float current_nominal_speed = SQRT(block->nominal_speed_sqr),
11841192
nomr = 1.0f / current_nominal_speed;
11851193
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
11931194
}
11941195

11951196
// Reset current only to ensure next trapezoid is computed - The
@@ -1222,13 +1223,6 @@ void Planner::recalculate_trapezoids() {
12221223
const float next_nominal_speed = SQRT(next->nominal_speed_sqr),
12231224
nomr = 1.0f / next_nominal_speed;
12241225
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
12321226
}
12331227

12341228
// 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,
22162210
// Compute and limit the acceleration rate for the trapezoid generator.
22172211
const float steps_per_mm = block->step_event_count * inverse_millimeters;
22182212
uint32_t accel;
2213+
#if ENABLED(LIN_ADVANCE)
2214+
bool use_advance_lead = false;
2215+
#endif
22192216
if (!block->steps.a && !block->steps.b && !block->steps.c) {
22202217
// convert to: acceleration steps/sec^2
22212218
accel = CEIL(settings.retract_acceleration * steps_per_mm);
2222-
TERN_(LIN_ADVANCE, block->use_advance_lead = false);
22232219
}
22242220
else {
22252221
#define LIMIT_ACCEL_LONG(AXIS,INDX) do{ \
@@ -2252,27 +2248,23 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
22522248
*
22532249
* de > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
22542250
*/
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,
22642256
SQRT(sq(target_float.x - position_float.x)
22652257
+ sq(target_float.y - position_float.y)
22662258
+ sq(target_float.z - position_float.z))
2267-
#endif
2268-
;
2259+
);
22692260

22702261
// 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!
22712262
// 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;
22742265
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;
22762268
if (TERN0(LA_DEBUG, accel > max_accel_steps_per_s2))
22772269
SERIAL_ECHOLNPGM("Acceleration limited.");
22782270
NOMORE(accel, max_accel_steps_per_s2);
@@ -2300,13 +2292,20 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
23002292
block->acceleration_rate = (uint32_t)(accel * (4096.0f * 4096.0f / (STEPPER_TIMER_RATE)));
23012293
#endif
23022294
#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++;
23052306
#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);
23102309
#endif
23112310
}
23122311
#endif

source/Marlin/src/module/planner.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,10 @@ typedef struct block_t {
192192

193193
// Advance extrusion
194194
#if ENABLED(LIN_ADVANCE)
195-
bool use_advance_lead;
196-
uint16_t advance_speed, // STEP timer value for extruder speed offset ISR
197-
max_adv_steps, // max. advance steps to get cruising speed pressure (not always nominal_speed!)
198-
final_adv_steps; // advance steps due to exit speed
199-
float e_D_ratio;
195+
uint32_t la_advance_rate; // The rate at which steps are added whilst accelerating
196+
uint8_t la_scaling; // Scale ISR frequency down and step frequency up by 2 ^ la_scaling
197+
uint16_t max_adv_steps, // Max advance steps to get cruising speed pressure
198+
final_adv_steps; // Advance steps for exit speed pressure
200199
#endif
201200

202201
uint32_t nominal_rate, // The nominal step rate for this block in step_events/sec
@@ -937,7 +936,7 @@ class Planner {
937936
return target_velocity_sqr - 2 * accel * distance;
938937
}
939938

940-
#if ENABLED(S_CURVE_ACCELERATION)
939+
#if EITHER(S_CURVE_ACCELERATION, LIN_ADVANCE)
941940
/**
942941
* Calculate the speed reached given initial speed, acceleration and distance
943942
*/

0 commit comments

Comments
 (0)