Restore position_float to fix LIN_ADVANCE

This commit is contained in:
Scott Lahteine 2017-12-21 16:39:18 -06:00
parent 2ec4113cb2
commit 5bc2acc072
3 changed files with 100 additions and 10 deletions

View File

@ -491,6 +491,10 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
#endif
#endif
#if ENABLED(LIN_ADVANCE) && !IS_CARTESIAN
#error "Sorry! LIN_ADVANCE is only compatible with Cartesian."
#endif
/**
* Parking Extruder requirements
*/

View File

@ -182,7 +182,10 @@ float Planner::previous_speed[NUM_AXIS],
#if ENABLED(LIN_ADVANCE)
float Planner::extruder_advance_k, // Initialized by settings.load()
Planner::advance_ed_ratio; // 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;
#endif
#if ENABLED(ULTRA_LCD)
@ -198,6 +201,9 @@ Planner::Planner() { init(); }
void Planner::init() {
block_buffer_head = block_buffer_tail = 0;
ZERO(position);
#if ENABLED(LIN_ADVANCE)
ZERO(position_float);
#endif
ZERO(previous_speed);
previous_nominal_speed = 0.0;
#if ABL_PLANAR
@ -742,7 +748,9 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
SERIAL_ECHOLNPGM(" steps)");
//*/
#if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
// 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 (de) {
#if ENABLED(PREVENT_COLD_EXTRUSION)
if (thermalManager.tooColdToExtrude(extruder)) {
@ -761,7 +769,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
}
#endif // PREVENT_LENGTHY_EXTRUDE
}
#endif // PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE
#endif // !LIN_ADVANCE && (PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE)
// Compute direction bit-mask for this block
uint8_t dm = 0;
@ -1355,16 +1363,16 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
* 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!
* de > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
* 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
&& de > 0;
&& lin_dist_e > 0;
if (block->use_advance_lead)
block->abs_adv_steps_multiplier8 = LROUND(
extruder_advance_k
* (UNEAR_ZERO(advance_ed_ratio) ? de * steps_to_mm[E_AXIS_N] / HYPOT(da * steps_to_mm[X_AXIS], db * steps_to_mm[Y_AXIS]) : advance_ed_ratio) // Use the fixed ratio, if set
* (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
);
@ -1442,16 +1450,69 @@ void Planner::buffer_segment(const float &a, const float &b, const float &c, con
SERIAL_ECHOLNPGM(")");
//*/
// DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
if (DEBUGGING(DRYRUN))
// 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[XYZE] = { _BETWEEN(X), _BETWEEN(Y), _BETWEEN(Z), _BETWEEN(E) };
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);
#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
const uint8_t next = block_buffer_head;
_buffer_steps(target, fr_mm_s, extruder);
SBI(block_buffer[next].flag, BLOCK_BIT_CONTINUED);
@ -1462,6 +1523,12 @@ void Planner::buffer_segment(const float &a, const float &b, const float &c, con
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()
/**
@ -1482,6 +1549,12 @@ void Planner::_set_position_mm(const float &a, const float &b, const float &c, c
nb = position[Y_AXIS] = LROUND(b * axis_steps_per_mm[Y_AXIS]),
nc = position[Z_AXIS] = LROUND(c * axis_steps_per_mm[Z_AXIS]),
ne = position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]);
#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
stepper.set_position(na, nb, nc, ne);
previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
ZERO(previous_speed);
@ -1506,8 +1579,16 @@ void Planner::set_position_mm_kinematic(const float (&cart)[XYZE]) {
* Sync from the stepper positions. (e.g., after an interrupted move)
*/
void Planner::sync_from_steppers() {
LOOP_XYZE(i)
LOOP_XYZE(i) {
position[i] = stepper.position((AxisEnum)i);
#if ENABLED(LIN_ADVANCE)
position_float[i] = position[i] * steps_to_mm[i
#if ENABLED(DISTINCT_E_FACTORS)
+ (i == E_AXIS ? active_extruder : 0)
#endif
];
#endif
}
}
/**
@ -1521,6 +1602,9 @@ void Planner::set_position_mm(const AxisEnum axis, const float &v) {
const uint8_t axis_index = axis;
#endif
position[axis] = LROUND(v * axis_steps_per_mm[axis_index]);
#if ENABLED(LIN_ADVANCE)
position_float[axis] = v;
#endif
stepper.set_position(axis, v);
previous_speed[axis] = 0.0;
}

View File

@ -195,7 +195,9 @@ class Planner {
#endif
#if ENABLED(LIN_ADVANCE)
static float extruder_advance_k, advance_ed_ratio;
static float extruder_advance_k, advance_ed_ratio,
position_float[XYZE],
lin_dist_xy, lin_dist_e;
#endif
#if ENABLED(SKEW_CORRECTION)