Replace division in planner with multiplication
This commit is contained in:
parent
b921f6b69d
commit
f8b5749235
|
@ -911,16 +911,15 @@ void setup() {
|
||||||
// Send "ok" after commands by default
|
// Send "ok" after commands by default
|
||||||
for (int8_t i = 0; i < BUFSIZE; i++) send_ok[i] = true;
|
for (int8_t i = 0; i < BUFSIZE; i++) send_ok[i] = true;
|
||||||
|
|
||||||
// loads data from EEPROM if available else uses defaults (and resets step acceleration rate)
|
// Load data from EEPROM if available (or use defaults)
|
||||||
|
// This also updates variables in the planner, elsewhere
|
||||||
Config_RetrieveSettings();
|
Config_RetrieveSettings();
|
||||||
|
|
||||||
// Initialize current position based on home_offset
|
// Initialize current position based on home_offset
|
||||||
memcpy(current_position, home_offset, sizeof(home_offset));
|
memcpy(current_position, home_offset, sizeof(home_offset));
|
||||||
|
|
||||||
#if ENABLED(DELTA) || ENABLED(SCARA)
|
// Vital to init stepper/planner equivalent for current_position
|
||||||
// Vital to init kinematic equivalent for X0 Y0 Z0
|
|
||||||
SYNC_PLAN_POSITION_KINEMATIC();
|
SYNC_PLAN_POSITION_KINEMATIC();
|
||||||
#endif
|
|
||||||
|
|
||||||
thermalManager.init(); // Initialize temperature loop
|
thermalManager.init(); // Initialize temperature loop
|
||||||
|
|
||||||
|
@ -5148,6 +5147,7 @@ inline void gcode_M92() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
planner.refresh_positioning();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -171,10 +171,16 @@ void Config_Postprocess() {
|
||||||
// steps per s2 needs to be updated to agree with units per s2
|
// steps per s2 needs to be updated to agree with units per s2
|
||||||
planner.reset_acceleration_rates();
|
planner.reset_acceleration_rates();
|
||||||
|
|
||||||
|
// Make sure delta kinematics are updated before refreshing the
|
||||||
|
// planner position so the stepper counts will be set correctly.
|
||||||
#if ENABLED(DELTA)
|
#if ENABLED(DELTA)
|
||||||
recalc_delta_settings(delta_radius, delta_diagonal_rod);
|
recalc_delta_settings(delta_radius, delta_diagonal_rod);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
|
||||||
|
// and init stepper.count[], planner.position[] with current_position
|
||||||
|
planner.refresh_positioning();
|
||||||
|
|
||||||
#if ENABLED(PIDTEMP)
|
#if ENABLED(PIDTEMP)
|
||||||
thermalManager.updatePID();
|
thermalManager.updatePID();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -82,6 +82,7 @@ volatile uint8_t Planner::block_buffer_tail = 0;
|
||||||
|
|
||||||
float Planner::max_feedrate_mm_s[NUM_AXIS]; // Max speeds in mm per second
|
float Planner::max_feedrate_mm_s[NUM_AXIS]; // Max speeds in mm per second
|
||||||
float Planner::axis_steps_per_mm[NUM_AXIS];
|
float Planner::axis_steps_per_mm[NUM_AXIS];
|
||||||
|
float Planner::steps_to_mm[NUM_AXIS];
|
||||||
unsigned long Planner::max_acceleration_steps_per_s2[NUM_AXIS];
|
unsigned long Planner::max_acceleration_steps_per_s2[NUM_AXIS];
|
||||||
unsigned long Planner::max_acceleration_mm_per_s2[NUM_AXIS]; // Use M201 to override by software
|
unsigned long Planner::max_acceleration_mm_per_s2[NUM_AXIS]; // Use M201 to override by software
|
||||||
|
|
||||||
|
@ -783,23 +784,23 @@ void Planner::check_axes_activity() {
|
||||||
#if ENABLED(COREXY) || ENABLED(COREXZ) || ENABLED(COREYZ)
|
#if ENABLED(COREXY) || ENABLED(COREXZ) || ENABLED(COREYZ)
|
||||||
float delta_mm[6];
|
float delta_mm[6];
|
||||||
#if ENABLED(COREXY)
|
#if ENABLED(COREXY)
|
||||||
delta_mm[X_HEAD] = dx / axis_steps_per_mm[A_AXIS];
|
delta_mm[X_HEAD] = dx * steps_to_mm[A_AXIS];
|
||||||
delta_mm[Y_HEAD] = dy / axis_steps_per_mm[B_AXIS];
|
delta_mm[Y_HEAD] = dy * steps_to_mm[B_AXIS];
|
||||||
delta_mm[Z_AXIS] = dz / axis_steps_per_mm[Z_AXIS];
|
delta_mm[Z_AXIS] = dz * steps_to_mm[Z_AXIS];
|
||||||
delta_mm[A_AXIS] = (dx + dy) / axis_steps_per_mm[A_AXIS];
|
delta_mm[A_AXIS] = (dx + dy) * steps_to_mm[A_AXIS];
|
||||||
delta_mm[B_AXIS] = (dx - dy) / axis_steps_per_mm[B_AXIS];
|
delta_mm[B_AXIS] = (dx - dy) * steps_to_mm[B_AXIS];
|
||||||
#elif ENABLED(COREXZ)
|
#elif ENABLED(COREXZ)
|
||||||
delta_mm[X_HEAD] = dx / axis_steps_per_mm[A_AXIS];
|
delta_mm[X_HEAD] = dx * steps_to_mm[A_AXIS];
|
||||||
delta_mm[Y_AXIS] = dy / axis_steps_per_mm[Y_AXIS];
|
delta_mm[Y_AXIS] = dy * steps_to_mm[Y_AXIS];
|
||||||
delta_mm[Z_HEAD] = dz / axis_steps_per_mm[C_AXIS];
|
delta_mm[Z_HEAD] = dz * steps_to_mm[C_AXIS];
|
||||||
delta_mm[A_AXIS] = (dx + dz) / axis_steps_per_mm[A_AXIS];
|
delta_mm[A_AXIS] = (dx + dz) * steps_to_mm[A_AXIS];
|
||||||
delta_mm[C_AXIS] = (dx - dz) / axis_steps_per_mm[C_AXIS];
|
delta_mm[C_AXIS] = (dx - dz) * steps_to_mm[C_AXIS];
|
||||||
#elif ENABLED(COREYZ)
|
#elif ENABLED(COREYZ)
|
||||||
delta_mm[X_AXIS] = dx / axis_steps_per_mm[X_AXIS];
|
delta_mm[X_AXIS] = dx * steps_to_mm[X_AXIS];
|
||||||
delta_mm[Y_HEAD] = dy / axis_steps_per_mm[B_AXIS];
|
delta_mm[Y_HEAD] = dy * steps_to_mm[B_AXIS];
|
||||||
delta_mm[Z_HEAD] = dz / axis_steps_per_mm[C_AXIS];
|
delta_mm[Z_HEAD] = dz * steps_to_mm[C_AXIS];
|
||||||
delta_mm[B_AXIS] = (dy + dz) / axis_steps_per_mm[B_AXIS];
|
delta_mm[B_AXIS] = (dy + dz) * steps_to_mm[B_AXIS];
|
||||||
delta_mm[C_AXIS] = (dy - dz) / axis_steps_per_mm[C_AXIS];
|
delta_mm[C_AXIS] = (dy - dz) * steps_to_mm[C_AXIS];
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
float delta_mm[4];
|
float delta_mm[4];
|
||||||
|
@ -808,12 +809,12 @@ void Planner::check_axes_activity() {
|
||||||
// so calculate distance in steps first, then do one division
|
// so calculate distance in steps first, then do one division
|
||||||
// at the end to get millimeters
|
// at the end to get millimeters
|
||||||
#else
|
#else
|
||||||
delta_mm[X_AXIS] = dx / axis_steps_per_mm[X_AXIS];
|
delta_mm[X_AXIS] = dx * steps_to_mm[X_AXIS];
|
||||||
delta_mm[Y_AXIS] = dy / axis_steps_per_mm[Y_AXIS];
|
delta_mm[Y_AXIS] = dy * steps_to_mm[Y_AXIS];
|
||||||
delta_mm[Z_AXIS] = dz / axis_steps_per_mm[Z_AXIS];
|
delta_mm[Z_AXIS] = dz * steps_to_mm[Z_AXIS];
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
delta_mm[E_AXIS] = (de / axis_steps_per_mm[E_AXIS]) * volumetric_multiplier[extruder] * extruder_multiplier[extruder] / 100.0;
|
delta_mm[E_AXIS] = (de * steps_to_mm[E_AXIS]) * volumetric_multiplier[extruder] * extruder_multiplier[extruder] / 100.0;
|
||||||
|
|
||||||
if (block->steps[X_AXIS] <= dropsegments && block->steps[Y_AXIS] <= dropsegments && block->steps[Z_AXIS] <= dropsegments) {
|
if (block->steps[X_AXIS] <= dropsegments && block->steps[Y_AXIS] <= dropsegments && block->steps[Z_AXIS] <= dropsegments) {
|
||||||
block->millimeters = fabs(delta_mm[E_AXIS]);
|
block->millimeters = fabs(delta_mm[E_AXIS]);
|
||||||
|
@ -833,7 +834,7 @@ void Planner::check_axes_activity() {
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
#if ENABLED(DELTA)
|
#if ENABLED(DELTA)
|
||||||
/ axis_steps_per_mm[X_AXIS]
|
* steps_to_mm[X_AXIS]
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -1176,6 +1177,7 @@ void Planner::check_axes_activity() {
|
||||||
void Planner::set_e_position_mm(const float& e) {
|
void Planner::set_e_position_mm(const float& e) {
|
||||||
position[E_AXIS] = lround(e * axis_steps_per_mm[E_AXIS]);
|
position[E_AXIS] = lround(e * axis_steps_per_mm[E_AXIS]);
|
||||||
stepper.set_e_position(position[E_AXIS]);
|
stepper.set_e_position(position[E_AXIS]);
|
||||||
|
previous_speed[E_AXIS] = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recalculate the steps/s^2 acceleration rates, based on the mm/s^2
|
// Recalculate the steps/s^2 acceleration rates, based on the mm/s^2
|
||||||
|
@ -1184,6 +1186,13 @@ void Planner::reset_acceleration_rates() {
|
||||||
max_acceleration_steps_per_s2[i] = max_acceleration_mm_per_s2[i] * axis_steps_per_mm[i];
|
max_acceleration_steps_per_s2[i] = max_acceleration_mm_per_s2[i] * axis_steps_per_mm[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recalculate position, steps_to_mm if axis_steps_per_mm changes!
|
||||||
|
void Planner::refresh_positioning() {
|
||||||
|
LOOP_XYZE(i) planner.steps_to_mm[i] = 1.0 / planner.axis_steps_per_mm[i];
|
||||||
|
set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
||||||
|
reset_acceleration_rates();
|
||||||
|
}
|
||||||
|
|
||||||
#if ENABLED(AUTOTEMP)
|
#if ENABLED(AUTOTEMP)
|
||||||
|
|
||||||
void Planner::autotemp_M109() {
|
void Planner::autotemp_M109() {
|
||||||
|
|
|
@ -121,6 +121,7 @@ class Planner {
|
||||||
|
|
||||||
static float max_feedrate_mm_s[NUM_AXIS]; // Max speeds in mm per second
|
static float max_feedrate_mm_s[NUM_AXIS]; // Max speeds in mm per second
|
||||||
static float axis_steps_per_mm[NUM_AXIS];
|
static float axis_steps_per_mm[NUM_AXIS];
|
||||||
|
static float steps_to_mm[NUM_AXIS];
|
||||||
static unsigned long max_acceleration_steps_per_s2[NUM_AXIS];
|
static unsigned long max_acceleration_steps_per_s2[NUM_AXIS];
|
||||||
static unsigned long max_acceleration_mm_per_s2[NUM_AXIS]; // Use M201 to override by software
|
static unsigned long max_acceleration_mm_per_s2[NUM_AXIS]; // Use M201 to override by software
|
||||||
|
|
||||||
|
@ -142,7 +143,7 @@ class Planner {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current position of the tool in absolute steps
|
* The current position of the tool in absolute steps
|
||||||
* Reclculated 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 long position[NUM_AXIS];
|
||||||
|
|
||||||
|
@ -187,6 +188,7 @@ class Planner {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void reset_acceleration_rates();
|
static void reset_acceleration_rates();
|
||||||
|
static void refresh_positioning();
|
||||||
|
|
||||||
// Manage fans, paste pressure, etc.
|
// Manage fans, paste pressure, etc.
|
||||||
static void check_axes_activity();
|
static void check_axes_activity();
|
||||||
|
|
|
@ -951,7 +951,7 @@ float Stepper::get_axis_position_mm(AxisEnum axis) {
|
||||||
#else
|
#else
|
||||||
axis_steps = position(axis);
|
axis_steps = position(axis);
|
||||||
#endif
|
#endif
|
||||||
return axis_steps / planner.axis_steps_per_mm[axis];
|
return axis_steps * planner.steps_to_mm[axis];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stepper::finish_and_disable() {
|
void Stepper::finish_and_disable() {
|
||||||
|
|
|
@ -262,7 +262,7 @@ class Stepper {
|
||||||
// Triggered position of an axis in mm (not core-savvy)
|
// Triggered position of an axis in mm (not core-savvy)
|
||||||
//
|
//
|
||||||
static FORCE_INLINE float triggered_position_mm(AxisEnum axis) {
|
static FORCE_INLINE float triggered_position_mm(AxisEnum axis) {
|
||||||
return endstops_trigsteps[axis] / planner.axis_steps_per_mm[axis];
|
return endstops_trigsteps[axis] * planner.steps_to_mm[axis];
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLED(LIN_ADVANCE)
|
#if ENABLED(LIN_ADVANCE)
|
||||||
|
|
|
@ -572,7 +572,7 @@ float Temperature::get_pid_output(int e) {
|
||||||
lpq[lpq_ptr] = 0;
|
lpq[lpq_ptr] = 0;
|
||||||
}
|
}
|
||||||
if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
|
if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
|
||||||
cTerm[HOTEND_INDEX] = (lpq[lpq_ptr] / planner.axis_steps_per_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
|
cTerm[HOTEND_INDEX] = (lpq[lpq_ptr] * planner.steps_to_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
|
||||||
pid_output += cTerm[HOTEND_INDEX];
|
pid_output += cTerm[HOTEND_INDEX];
|
||||||
}
|
}
|
||||||
#endif //PID_ADD_EXTRUSION_RATE
|
#endif //PID_ADD_EXTRUSION_RATE
|
||||||
|
|
|
@ -678,7 +678,7 @@ void kill_screen(const char* lcd_msg) {
|
||||||
}
|
}
|
||||||
if (lcdDrawUpdate)
|
if (lcdDrawUpdate)
|
||||||
lcd_implementation_drawedit(msg, ftostr43sign(
|
lcd_implementation_drawedit(msg, ftostr43sign(
|
||||||
((1000 * babysteps_done) / planner.axis_steps_per_mm[axis]) * 0.001f
|
((1000 * babysteps_done) * planner.steps_to_mm[axis]) * 0.001f
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1769,6 +1769,7 @@ void kill_screen(const char* lcd_msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
|
static void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
|
||||||
|
static void _planner_refresh_positioning() { planner.refresh_positioning(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -1805,14 +1806,14 @@ void kill_screen(const char* lcd_msg) {
|
||||||
MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
|
MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
|
||||||
MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
|
MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
|
||||||
MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
|
MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
|
||||||
MENU_ITEM_EDIT(float52, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999);
|
MENU_ITEM_EDIT_CALLBACK(float52, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999, _planner_refresh_positioning);
|
||||||
MENU_ITEM_EDIT(float52, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999);
|
MENU_ITEM_EDIT_CALLBACK(float52, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999, _planner_refresh_positioning);
|
||||||
#if ENABLED(DELTA)
|
#if ENABLED(DELTA)
|
||||||
MENU_ITEM_EDIT(float52, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999);
|
MENU_ITEM_EDIT_CALLBACK(float52, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999, _planner_refresh_positioning);
|
||||||
#else
|
#else
|
||||||
MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999);
|
MENU_ITEM_EDIT_CALLBACK(float51, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999, _planner_refresh_positioning);
|
||||||
#endif
|
#endif
|
||||||
MENU_ITEM_EDIT(float51, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999);
|
MENU_ITEM_EDIT_CALLBACK(float51, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
|
||||||
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
|
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
|
||||||
MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
|
MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue