Drop Planner::position_float, use int types
This commit is contained in:
parent
ec6ca37ed3
commit
dd3ce40826
2 changed files with 31 additions and 89 deletions
|
@ -144,7 +144,7 @@ float Planner::min_feedrate_mm_s,
|
||||||
|
|
||||||
// private:
|
// private:
|
||||||
|
|
||||||
long Planner::position[NUM_AXIS] = { 0 };
|
int32_t Planner::position[NUM_AXIS] = { 0 };
|
||||||
|
|
||||||
uint32_t Planner::cutoff_long;
|
uint32_t Planner::cutoff_long;
|
||||||
|
|
||||||
|
@ -164,8 +164,7 @@ float Planner::previous_speed[NUM_AXIS],
|
||||||
|
|
||||||
#if ENABLED(LIN_ADVANCE)
|
#if ENABLED(LIN_ADVANCE)
|
||||||
float Planner::extruder_advance_k, // Initialized by settings.load()
|
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[NUM_AXIS] = { 0 };
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(ULTRA_LCD)
|
#if ENABLED(ULTRA_LCD)
|
||||||
|
@ -181,9 +180,6 @@ Planner::Planner() { init(); }
|
||||||
void Planner::init() {
|
void Planner::init() {
|
||||||
block_buffer_head = block_buffer_tail = 0;
|
block_buffer_head = block_buffer_tail = 0;
|
||||||
ZERO(position);
|
ZERO(position);
|
||||||
#if ENABLED(LIN_ADVANCE)
|
|
||||||
ZERO(position_float);
|
|
||||||
#endif
|
|
||||||
ZERO(previous_speed);
|
ZERO(previous_speed);
|
||||||
previous_nominal_speed = 0.0;
|
previous_nominal_speed = 0.0;
|
||||||
#if ABL_PLANAR
|
#if ABL_PLANAR
|
||||||
|
@ -690,13 +686,9 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(LIN_ADVANCE)
|
const int32_t da = target[X_AXIS] - position[X_AXIS],
|
||||||
const float mm_D_float = SQRT(sq(a - position_float[X_AXIS]) + sq(b - position_float[Y_AXIS]));
|
db = target[Y_AXIS] - position[Y_AXIS],
|
||||||
#endif
|
dc = target[Z_AXIS] - position[Z_AXIS];
|
||||||
|
|
||||||
const long da = target[X_AXIS] - position[X_AXIS],
|
|
||||||
db = target[Y_AXIS] - position[Y_AXIS],
|
|
||||||
dc = target[Z_AXIS] - position[Z_AXIS];
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
SERIAL_ECHOPAIR(" Planner FR:", fr_mm_s);
|
SERIAL_ECHOPAIR(" Planner FR:", fr_mm_s);
|
||||||
|
@ -721,19 +713,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
|
||||||
SERIAL_EOL();
|
SERIAL_EOL();
|
||||||
//*/
|
//*/
|
||||||
|
|
||||||
// DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
|
int32_t de = target[E_AXIS] - position[E_AXIS];
|
||||||
if (DEBUGGING(DRYRUN)) {
|
|
||||||
position[E_AXIS] = target[E_AXIS];
|
|
||||||
#if ENABLED(LIN_ADVANCE)
|
|
||||||
position_float[E_AXIS] = e;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
long de = target[E_AXIS] - position[E_AXIS];
|
|
||||||
|
|
||||||
#if ENABLED(LIN_ADVANCE)
|
|
||||||
float de_float = e - position_float[E_AXIS]; // Should this include e_factor?
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
|
#if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
|
||||||
if (de) {
|
if (de) {
|
||||||
|
@ -741,10 +721,6 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
|
||||||
if (thermalManager.tooColdToExtrude(extruder)) {
|
if (thermalManager.tooColdToExtrude(extruder)) {
|
||||||
position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
|
position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
|
||||||
de = 0; // no difference
|
de = 0; // no difference
|
||||||
#if ENABLED(LIN_ADVANCE)
|
|
||||||
position_float[E_AXIS] = e;
|
|
||||||
de_float = 0;
|
|
||||||
#endif
|
|
||||||
SERIAL_ECHO_START();
|
SERIAL_ECHO_START();
|
||||||
SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
|
SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
|
||||||
}
|
}
|
||||||
|
@ -753,10 +729,6 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
|
||||||
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
|
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
|
position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
|
||||||
de = 0; // no difference
|
de = 0; // no difference
|
||||||
#if ENABLED(LIN_ADVANCE)
|
|
||||||
position_float[E_AXIS] = e;
|
|
||||||
de_float = 0;
|
|
||||||
#endif
|
|
||||||
SERIAL_ECHO_START();
|
SERIAL_ECHO_START();
|
||||||
SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
|
SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
|
||||||
}
|
}
|
||||||
|
@ -1036,7 +1008,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const float inverse_millimeters = 1.0 / block->millimeters; // Inverse millimeters to remove multiple divides
|
float inverse_millimeters = 1.0 / block->millimeters; // Inverse millimeters to remove multiple divides
|
||||||
|
|
||||||
// Calculate moves/second for this move. No divide by zero due to previous checks.
|
// Calculate moves/second for this move. No divide by zero due to previous checks.
|
||||||
float inverse_mm_s = fr_mm_s * inverse_millimeters;
|
float inverse_mm_s = fr_mm_s * inverse_millimeters;
|
||||||
|
@ -1360,31 +1332,28 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
|
||||||
previous_safe_speed = safe_speed;
|
previous_safe_speed = safe_speed;
|
||||||
|
|
||||||
#if ENABLED(LIN_ADVANCE)
|
#if ENABLED(LIN_ADVANCE)
|
||||||
|
/**
|
||||||
//
|
*
|
||||||
// Use LIN_ADVANCE for blocks if all these are true:
|
* Use LIN_ADVANCE for blocks if all these are true:
|
||||||
//
|
*
|
||||||
// esteps : We have E steps todo (a printing move)
|
* esteps && (block->steps[X_AXIS] || block->steps[Y_AXIS]) : This is a print move
|
||||||
//
|
*
|
||||||
// block->steps[X_AXIS] || block->steps[Y_AXIS] : We have a movement in XY direction (i.e., not retract / prime).
|
* extruder_advance_k : There is an advance factor set.
|
||||||
//
|
*
|
||||||
// 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.
|
||||||
// block->steps[E_AXIS] != block->step_event_count : A problem occurs if the move before a retract is too small.
|
* This leads to too many advance steps due to a huge e_acceleration.
|
||||||
// In that case, the retract and move will be executed together.
|
* The math is good, but we must avoid retract moves with advance!
|
||||||
// This leads to too many advance steps due to a huge e_acceleration.
|
* de > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
|
||||||
// The math is good, but we must avoid retract moves with advance!
|
*/
|
||||||
// de_float > 0.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])
|
||||||
//
|
|
||||||
block->use_advance_lead = esteps
|
|
||||||
&& (block->steps[X_AXIS] || block->steps[Y_AXIS])
|
|
||||||
&& extruder_advance_k
|
&& extruder_advance_k
|
||||||
&& (uint32_t)esteps != block->step_event_count
|
&& (uint32_t)esteps != block->step_event_count
|
||||||
&& de_float > 0.0;
|
&& de > 0;
|
||||||
if (block->use_advance_lead)
|
if (block->use_advance_lead)
|
||||||
block->abs_adv_steps_multiplier8 = LROUND(
|
block->abs_adv_steps_multiplier8 = LROUND(
|
||||||
extruder_advance_k
|
extruder_advance_k
|
||||||
* (UNEAR_ZERO(advance_ed_ratio) ? de_float / mm_D_float : advance_ed_ratio) // Use the fixed ratio, if set
|
* (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
|
||||||
* (block->nominal_speed / (float)block->nominal_rate)
|
* (block->nominal_speed / (float)block->nominal_rate)
|
||||||
* axis_steps_per_mm[E_AXIS_N] * 256.0
|
* axis_steps_per_mm[E_AXIS_N] * 256.0
|
||||||
);
|
);
|
||||||
|
@ -1398,12 +1367,6 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
|
||||||
|
|
||||||
// Update the position (only when a move was queued)
|
// Update the position (only when a move was queued)
|
||||||
COPY(position, target);
|
COPY(position, target);
|
||||||
#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
|
|
||||||
|
|
||||||
recalculate();
|
recalculate();
|
||||||
|
|
||||||
|
@ -1425,16 +1388,10 @@ void Planner::_set_position_mm(const float &a, const float &b, const float &c, c
|
||||||
#else
|
#else
|
||||||
#define _EINDEX E_AXIS
|
#define _EINDEX E_AXIS
|
||||||
#endif
|
#endif
|
||||||
const long na = position[X_AXIS] = LROUND(a * axis_steps_per_mm[X_AXIS]),
|
const int32_t na = position[X_AXIS] = LROUND(a * axis_steps_per_mm[X_AXIS]),
|
||||||
nb = position[Y_AXIS] = LROUND(b * axis_steps_per_mm[Y_AXIS]),
|
nb = position[Y_AXIS] = LROUND(b * axis_steps_per_mm[Y_AXIS]),
|
||||||
nc = position[Z_AXIS] = LROUND(c * axis_steps_per_mm[Z_AXIS]),
|
nc = position[Z_AXIS] = LROUND(c * axis_steps_per_mm[Z_AXIS]),
|
||||||
ne = position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]);
|
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);
|
stepper.set_position(na, nb, nc, ne);
|
||||||
previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
|
previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
|
||||||
ZERO(previous_speed);
|
ZERO(previous_speed);
|
||||||
|
@ -1459,16 +1416,8 @@ void Planner::set_position_mm_kinematic(const float position[NUM_AXIS]) {
|
||||||
* Sync from the stepper positions. (e.g., after an interrupted move)
|
* Sync from the stepper positions. (e.g., after an interrupted move)
|
||||||
*/
|
*/
|
||||||
void Planner::sync_from_steppers() {
|
void Planner::sync_from_steppers() {
|
||||||
LOOP_XYZE(i) {
|
LOOP_XYZE(i)
|
||||||
position[i] = stepper.position((AxisEnum)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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1482,9 +1431,6 @@ void Planner::set_position_mm(const AxisEnum axis, const float &v) {
|
||||||
const uint8_t axis_index = axis;
|
const uint8_t axis_index = axis;
|
||||||
#endif
|
#endif
|
||||||
position[axis] = LROUND(v * axis_steps_per_mm[axis_index]);
|
position[axis] = LROUND(v * axis_steps_per_mm[axis_index]);
|
||||||
#if ENABLED(LIN_ADVANCE)
|
|
||||||
position_float[axis] = v;
|
|
||||||
#endif
|
|
||||||
stepper.set_position(axis, v);
|
stepper.set_position(axis, v);
|
||||||
previous_speed[axis] = 0.0;
|
previous_speed[axis] = 0.0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,7 @@ class Planner {
|
||||||
* The current position of the tool in absolute steps
|
* The current position of the tool in absolute steps
|
||||||
* Recalculated if any axis_steps_per_mm are changed by gcode
|
* Recalculated if any axis_steps_per_mm are changed by gcode
|
||||||
*/
|
*/
|
||||||
static long position[NUM_AXIS];
|
static int32_t position[NUM_AXIS];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Speed of previous path line segment
|
* Speed of previous path line segment
|
||||||
|
@ -220,11 +220,7 @@ class Planner {
|
||||||
// Old direction bits. Used for speed calculations
|
// Old direction bits. Used for speed calculations
|
||||||
static unsigned char old_direction_bits;
|
static unsigned char old_direction_bits;
|
||||||
// Segment times (in µs). Used for speed calculations
|
// Segment times (in µs). Used for speed calculations
|
||||||
static long axis_segment_time_us[2][3];
|
static uint32_t axis_segment_time_us[2][3];
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ENABLED(LIN_ADVANCE)
|
|
||||||
static float position_float[NUM_AXIS];
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(ULTRA_LCD)
|
#if ENABLED(ULTRA_LCD)
|
||||||
|
|
Reference in a new issue