[2.0.x] LIN_ADVANCE v1.5 (#9712)
This commit is contained in:
@ -185,11 +185,8 @@ float Planner::previous_speed[NUM_AXIS],
|
||||
#endif
|
||||
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
float Planner::extruder_advance_k, // Initialized by settings.load()
|
||||
Planner::advance_ed_ratio, // Initialized by settings.load()
|
||||
Planner::position_float[XYZE], // Needed for accurate maths. Steps cannot be used!
|
||||
Planner::lin_dist_xy,
|
||||
Planner::lin_dist_e;
|
||||
float Planner::extruder_advance_K, // Initialized by settings.load()
|
||||
Planner::position_float[XYZE]; // Needed for accurate maths. Steps cannot be used!
|
||||
#endif
|
||||
|
||||
#if ENABLED(ULTRA_LCD)
|
||||
@ -364,6 +361,13 @@ void Planner::recalculate_trapezoids() {
|
||||
// NOTE: Entry and exit factors always > 0 by all previous logic operations.
|
||||
const float nomr = 1.0 / current->nominal_speed;
|
||||
calculate_trapezoid_for_block(current, current->entry_speed * nomr, next->entry_speed * nomr);
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
if (current->use_advance_lead) {
|
||||
const float comp = current->e_D_ratio * extruder_advance_K * axis_steps_per_mm[E_AXIS];
|
||||
current->max_adv_steps = current->nominal_speed * comp;
|
||||
current->final_adv_steps = next->entry_speed * comp;
|
||||
}
|
||||
#endif
|
||||
CBI(current->flag, BLOCK_BIT_RECALCULATE); // Reset current only to ensure next trapezoid is computed
|
||||
}
|
||||
}
|
||||
@ -373,6 +377,13 @@ void Planner::recalculate_trapezoids() {
|
||||
if (next) {
|
||||
const float nomr = 1.0 / next->nominal_speed;
|
||||
calculate_trapezoid_for_block(next, next->entry_speed * nomr, (MINIMUM_PLANNER_SPEED) * nomr);
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
if (next->use_advance_lead) {
|
||||
const float comp = next->e_D_ratio * extruder_advance_K * axis_steps_per_mm[E_AXIS];
|
||||
next->max_adv_steps = next->nominal_speed * comp;
|
||||
next->final_adv_steps = (MINIMUM_PLANNER_SPEED) * comp;
|
||||
}
|
||||
#endif
|
||||
CBI(next->flag, BLOCK_BIT_RECALCULATE);
|
||||
}
|
||||
}
|
||||
@ -730,7 +741,12 @@ void Planner::check_axes_activity() {
|
||||
* fr_mm_s - (target) speed of the move
|
||||
* extruder - target extruder
|
||||
*/
|
||||
void Planner::_buffer_steps(const int32_t (&target)[ABCE], float fr_mm_s, const uint8_t extruder, const float &millimeters /*= 0.0*/) {
|
||||
void Planner::_buffer_steps(const int32_t (&target)[XYZE]
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
, const float (&target_float)[XYZE]
|
||||
#endif
|
||||
, float fr_mm_s, const uint8_t extruder, const float &millimeters/*=0.0*/
|
||||
) {
|
||||
|
||||
const int32_t da = target[A_AXIS] - position[A_AXIS],
|
||||
db = target[B_AXIS] - position[B_AXIS],
|
||||
@ -751,13 +767,14 @@ void Planner::_buffer_steps(const int32_t (&target)[ABCE], float fr_mm_s, const
|
||||
SERIAL_ECHOLNPGM(" steps)");
|
||||
//*/
|
||||
|
||||
// If LIN_ADVANCE is disabled then do E move prevention with integers
|
||||
// Otherwise it's done in _buffer_segment.
|
||||
#if DISABLED(LIN_ADVANCE) && (ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE))
|
||||
#if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
|
||||
if (de) {
|
||||
#if ENABLED(PREVENT_COLD_EXTRUSION)
|
||||
if (thermalManager.tooColdToExtrude(extruder)) {
|
||||
position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
position_float[E_AXIS] = target_float[E_AXIS];
|
||||
#endif
|
||||
de = 0; // no difference
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
|
||||
@ -766,13 +783,16 @@ void Planner::_buffer_steps(const int32_t (&target)[ABCE], float fr_mm_s, const
|
||||
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
|
||||
if (labs(de * e_factor[extruder]) > (int32_t)axis_steps_per_mm[E_AXIS_N] * (EXTRUDE_MAXLENGTH)) { // It's not important to get max. extrusion length in a precision < 1mm, so save some cycles and cast to int
|
||||
position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
position_float[E_AXIS] = target_float[E_AXIS];
|
||||
#endif
|
||||
de = 0; // no difference
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
|
||||
}
|
||||
#endif // PREVENT_LENGTHY_EXTRUDE
|
||||
}
|
||||
#endif // !LIN_ADVANCE && (PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE)
|
||||
#endif // PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE
|
||||
|
||||
// Compute direction bit-mask for this block
|
||||
uint8_t dm = 0;
|
||||
@ -1189,6 +1209,9 @@ void Planner::_buffer_steps(const int32_t (&target)[ABCE], float fr_mm_s, const
|
||||
if (!block->steps[A_AXIS] && !block->steps[B_AXIS] && !block->steps[C_AXIS]) {
|
||||
// convert to: acceleration steps/sec^2
|
||||
accel = CEIL(retract_acceleration * steps_per_mm);
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
block->use_advance_lead = false;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#define LIMIT_ACCEL_LONG(AXIS,INDX) do{ \
|
||||
@ -1208,6 +1231,47 @@ void Planner::_buffer_steps(const int32_t (&target)[ABCE], float fr_mm_s, const
|
||||
// Start with print or travel acceleration
|
||||
accel = CEIL((esteps ? acceleration : travel_acceleration) * steps_per_mm);
|
||||
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
/**
|
||||
*
|
||||
* Use LIN_ADVANCE for blocks if all these are true:
|
||||
*
|
||||
* esteps : This is a print move, because we checked for A, B, C steps before.
|
||||
*
|
||||
* extruder_advance_K : There is an advance factor set.
|
||||
*
|
||||
* de > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
|
||||
*/
|
||||
block->use_advance_lead = esteps
|
||||
&& extruder_advance_K
|
||||
&& de > 0;
|
||||
|
||||
if (block->use_advance_lead) {
|
||||
block->e_D_ratio = (target_float[E_AXIS] - position_float[E_AXIS]) /
|
||||
#if IS_KINEMATIC
|
||||
block->millimeters
|
||||
#else
|
||||
SQRT(sq(target_float[X_AXIS] - position_float[X_AXIS])
|
||||
+ sq(target_float[Y_AXIS] - position_float[Y_AXIS])
|
||||
+ sq(target_float[Z_AXIS] - position_float[Z_AXIS]))
|
||||
#endif
|
||||
;
|
||||
|
||||
// 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!
|
||||
// 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.
|
||||
if (block->e_D_ratio > 3.0)
|
||||
block->use_advance_lead = false;
|
||||
else {
|
||||
const uint32_t max_accel_steps_per_s2 = max_jerk[E_AXIS] / (extruder_advance_K * block->e_D_ratio) * steps_per_mm;
|
||||
#if ENABLED(LA_DEBUG)
|
||||
if (accel > max_accel_steps_per_s2)
|
||||
SERIAL_ECHOLNPGM("Acceleration limited.");
|
||||
#endif
|
||||
NOMORE(accel, max_accel_steps_per_s2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLED(DISTINCT_E_FACTORS)
|
||||
#define ACCEL_IDX extruder
|
||||
#else
|
||||
@ -1230,7 +1294,18 @@ void Planner::_buffer_steps(const int32_t (&target)[ABCE], float fr_mm_s, const
|
||||
}
|
||||
block->acceleration_steps_per_s2 = accel;
|
||||
block->acceleration = accel / steps_per_mm;
|
||||
block->acceleration_rate = (long)(accel * 16777216.0 / (HAL_STEPPER_TIMER_RATE)); // 16777216 = <<24
|
||||
block->acceleration_rate = (long)(accel * 16777216.0 / ((F_CPU) * 0.125)); // * 8.388608
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
if (block->use_advance_lead) {
|
||||
block->advance_speed = ((F_CPU) * 0.125) / (extruder_advance_K * block->e_D_ratio * block->acceleration * axis_steps_per_mm[E_AXIS_N]);
|
||||
#if ENABLED(LA_DEBUG)
|
||||
if (extruder_advance_K * block->e_D_ratio * block->acceleration * 2 < block->nominal_speed * block->e_D_ratio)
|
||||
SERIAL_ECHOLNPGM("More than 2 steps per eISR loop executed.");
|
||||
if (block->advance_speed < 200)
|
||||
SERIAL_ECHOLNPGM("eISR running at > 10kHz.");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// Initial limit on the segment entry velocity
|
||||
float vmax_junction;
|
||||
@ -1386,41 +1461,15 @@ void Planner::_buffer_steps(const int32_t (&target)[ABCE], float fr_mm_s, const
|
||||
previous_nominal_speed = block->nominal_speed;
|
||||
previous_safe_speed = safe_speed;
|
||||
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
/**
|
||||
*
|
||||
* Use LIN_ADVANCE for blocks if all these are true:
|
||||
*
|
||||
* esteps && (block->steps[X_AXIS] || block->steps[Y_AXIS]) : This is a print move
|
||||
*
|
||||
* extruder_advance_k : There is an advance factor set.
|
||||
*
|
||||
* esteps != block->step_event_count : A problem occurs if the move before a retract is too small.
|
||||
* In that case, the retract and move will be executed together.
|
||||
* This leads to too many advance steps due to a huge e_acceleration.
|
||||
* The math is good, but we must avoid retract moves with advance!
|
||||
* lin_dist_e > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
|
||||
*/
|
||||
block->use_advance_lead = esteps && (block->steps[X_AXIS] || block->steps[Y_AXIS])
|
||||
&& extruder_advance_k
|
||||
&& (uint32_t)esteps != block->step_event_count
|
||||
&& lin_dist_e > 0;
|
||||
if (block->use_advance_lead)
|
||||
block->abs_adv_steps_multiplier8 = LROUND(
|
||||
extruder_advance_k
|
||||
* (UNEAR_ZERO(advance_ed_ratio) ? lin_dist_e / lin_dist_xy : advance_ed_ratio) // Use the fixed ratio, if set
|
||||
* (block->nominal_speed / (float)block->nominal_rate)
|
||||
* axis_steps_per_mm[E_AXIS_N] * 256.0
|
||||
);
|
||||
|
||||
#endif // LIN_ADVANCE
|
||||
|
||||
// Move buffer head
|
||||
block_buffer_head = next_buffer_head;
|
||||
|
||||
// Update the position (only when a move was queued)
|
||||
static_assert(COUNT(target) > 1, "Parameter to _buffer_steps must be (&target)[XYZE]!");
|
||||
COPY(position, target);
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
COPY(position_float, target_float);
|
||||
#endif
|
||||
|
||||
recalculate();
|
||||
|
||||
@ -1438,7 +1487,7 @@ void Planner::_buffer_steps(const int32_t (&target)[ABCE], float fr_mm_s, const
|
||||
* extruder - target extruder
|
||||
* millimeters - the length of the movement, if known
|
||||
*/
|
||||
void Planner::buffer_segment(const float &a, const float &b, const float &c, const float &e, const float &fr_mm_s, const uint8_t extruder, const float &millimeters /*= 0.0*/) {
|
||||
void Planner::buffer_segment(const float &a, const float &b, const float &c, const float &e, const float &fr_mm_s, const uint8_t extruder, const float &millimeters/*=0.0*/) {
|
||||
// When changing extruders recalculate steps corresponding to the E position
|
||||
#if ENABLED(DISTINCT_E_FACTORS)
|
||||
if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) {
|
||||
@ -1456,6 +1505,18 @@ void Planner::buffer_segment(const float &a, const float &b, const float &c, con
|
||||
LROUND(e * axis_steps_per_mm[E_AXIS_N])
|
||||
};
|
||||
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
const float target_float[XYZE] = { a, b, c, e };
|
||||
#endif
|
||||
|
||||
// DRYRUN prevents E moves from taking place
|
||||
if (DEBUGGING(DRYRUN)) {
|
||||
position[E_AXIS] = target[E_AXIS];
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
position_float[E_AXIS] = e;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* <-- add a slash to enable
|
||||
SERIAL_ECHOPAIR(" buffer_segment FR:", fr_mm_s);
|
||||
#if IS_KINEMATIC
|
||||
@ -1484,85 +1545,48 @@ void Planner::buffer_segment(const float &a, const float &b, const float &c, con
|
||||
SERIAL_ECHOLNPGM(")");
|
||||
//*/
|
||||
|
||||
// DRYRUN prevents E moves from taking place
|
||||
if (DEBUGGING(DRYRUN)) {
|
||||
position[E_AXIS] = target[E_AXIS];
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
position_float[E_AXIS] = e;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
lin_dist_e = e - position_float[E_AXIS];
|
||||
#endif
|
||||
|
||||
// If LIN_ADVANCE is enabled then do E move prevention with floats
|
||||
// Otherwise it's done in _buffer_steps.
|
||||
#if ENABLED(LIN_ADVANCE) && (ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE))
|
||||
if (lin_dist_e) {
|
||||
#if ENABLED(PREVENT_COLD_EXTRUSION)
|
||||
if (thermalManager.tooColdToExtrude(extruder)) {
|
||||
position_float[E_AXIS] = e; // Behave as if the move really took place, but ignore E part
|
||||
position[E_AXIS] = target[E_AXIS];
|
||||
lin_dist_e = 0;
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
|
||||
}
|
||||
#endif // PREVENT_COLD_EXTRUSION
|
||||
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
|
||||
if (lin_dist_e * e_factor[extruder] > (EXTRUDE_MAXLENGTH)) {
|
||||
position_float[E_AXIS] = e; // Behave as if the move really took place, but ignore E part
|
||||
position[E_AXIS] = target[E_AXIS];
|
||||
lin_dist_e = 0;
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
|
||||
}
|
||||
#endif // PREVENT_LENGTHY_EXTRUDE
|
||||
}
|
||||
#endif // LIN_ADVANCE && (PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE)
|
||||
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
if (lin_dist_e > 0)
|
||||
lin_dist_xy = HYPOT(a - position_float[X_AXIS], b - position_float[Y_AXIS]);
|
||||
#endif
|
||||
|
||||
// Always split the first move into two (if not homing or probing)
|
||||
if (!blocks_queued()) {
|
||||
|
||||
#define _BETWEEN(A) (position[A##_AXIS] + target[A##_AXIS]) >> 1
|
||||
const int32_t between[ABCE] = { _BETWEEN(A), _BETWEEN(B), _BETWEEN(C), _BETWEEN(E) };
|
||||
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
#define _BETWEEN_F(A) (position_float[A##_AXIS] + target_float[A##_AXIS]) * 0.5
|
||||
const float between_float[ABCE] = { _BETWEEN_F(A), _BETWEEN_F(B), _BETWEEN_F(C), _BETWEEN_F(E) };
|
||||
#endif
|
||||
|
||||
DISABLE_STEPPER_DRIVER_INTERRUPT();
|
||||
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
lin_dist_xy *= 0.5;
|
||||
lin_dist_e *= 0.5;
|
||||
#endif
|
||||
|
||||
_buffer_steps(between, fr_mm_s, extruder, millimeters * 0.5);
|
||||
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
position_float[X_AXIS] = (position_float[X_AXIS] + a) * 0.5;
|
||||
position_float[Y_AXIS] = (position_float[Y_AXIS] + b) * 0.5;
|
||||
//position_float[Z_AXIS] = (position_float[Z_AXIS] + c) * 0.5;
|
||||
position_float[E_AXIS] = (position_float[E_AXIS] + e) * 0.5;
|
||||
#endif
|
||||
_buffer_steps(between
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
, between_float
|
||||
#endif
|
||||
, fr_mm_s, extruder, millimeters * 0.5
|
||||
);
|
||||
|
||||
const uint8_t next = block_buffer_head;
|
||||
_buffer_steps(target, fr_mm_s, extruder, millimeters * 0.5);
|
||||
|
||||
_buffer_steps(target
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
, target_float
|
||||
#endif
|
||||
, fr_mm_s, extruder, millimeters * 0.5
|
||||
);
|
||||
|
||||
SBI(block_buffer[next].flag, BLOCK_BIT_CONTINUED);
|
||||
ENABLE_STEPPER_DRIVER_INTERRUPT();
|
||||
}
|
||||
else
|
||||
_buffer_steps(target, fr_mm_s, extruder, millimeters);
|
||||
_buffer_steps(target
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
, target_float
|
||||
#endif
|
||||
, fr_mm_s, extruder, millimeters
|
||||
);
|
||||
|
||||
stepper.wake_up();
|
||||
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
position_float[X_AXIS] = a;
|
||||
position_float[Y_AXIS] = b;
|
||||
//position_float[Z_AXIS] = c;
|
||||
position_float[E_AXIS] = e;
|
||||
#endif
|
||||
} // buffer_segment()
|
||||
|
||||
/**
|
||||
@ -1586,7 +1610,7 @@ void Planner::_set_position_mm(const float &a, const float &b, const float &c, c
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
position_float[X_AXIS] = a;
|
||||
position_float[Y_AXIS] = b;
|
||||
//position_float[Z_AXIS] = c;
|
||||
position_float[Z_AXIS] = c;
|
||||
position_float[E_AXIS] = e;
|
||||
#endif
|
||||
stepper.set_position(na, nb, nc, ne);
|
||||
|
Reference in New Issue
Block a user