From 3e2b3353b083d4fe9927912c5f98f9aa0c3fceb3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 23 Jul 2016 19:02:14 -0700 Subject: [PATCH 1/6] Fix axis indices for COREYZ --- Marlin/planner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 35e5d3bd95..3d62789188 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -795,8 +795,8 @@ void Planner::check_axes_activity() { delta_mm[A_AXIS] = (dx + dz) / axis_steps_per_mm[A_AXIS]; delta_mm[C_AXIS] = (dx - dz) / axis_steps_per_mm[C_AXIS]; #elif ENABLED(COREYZ) - delta_mm[X_AXIS] = dx / axis_steps_per_mm[A_AXIS]; - delta_mm[Y_HEAD] = dy / axis_steps_per_mm[Y_AXIS]; + delta_mm[X_AXIS] = dx / axis_steps_per_mm[X_AXIS]; + delta_mm[Y_HEAD] = dy / axis_steps_per_mm[B_AXIS]; delta_mm[Z_HEAD] = dz / axis_steps_per_mm[C_AXIS]; delta_mm[B_AXIS] = (dy + dz) / axis_steps_per_mm[B_AXIS]; delta_mm[C_AXIS] = (dy - dz) / axis_steps_per_mm[C_AXIS]; From db5df9500b902f44759418a2906ef45c3a122133 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 24 Jul 2016 13:27:09 -0700 Subject: [PATCH 2/6] Move sync_plan_position closer to the top --- Marlin/Marlin_main.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index b92a222425..1ad4b80114 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -610,6 +610,20 @@ static void report_current_position(); print_xyz(PSTR(STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n"), VAR); } while(0) #endif +/** + * sync_plan_position + * Set planner / stepper positions to the cartesian current_position. + * The stepper code translates these coordinates into step units. + * Allows translation between steps and millimeters for cartesian & core robots + */ +inline void sync_plan_position() { + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position", current_position); + #endif + planner.set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); +} +inline void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); } + #if ENABLED(DELTA) || ENABLED(SCARA) inline void sync_plan_position_delta() { #if ENABLED(DEBUG_LEVELING_FEATURE) @@ -1627,19 +1641,6 @@ inline void line_to_destination(float fr_mm_m) { } inline void line_to_destination() { line_to_destination(feedrate_mm_m); } -/** - * sync_plan_position - * Set planner / stepper positions to the cartesian current_position. - * The stepper code translates these coordinates into step units. - * Allows translation between steps and millimeters for cartesian & core robots - */ -inline void sync_plan_position() { - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position", current_position); - #endif - planner.set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); -} -inline void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); } inline void set_current_to_destination() { memcpy(current_position, destination, sizeof(current_position)); } inline void set_destination_to_current() { memcpy(destination, current_position, sizeof(destination)); } From b921f6b69d5ac5aa62650863b1af2947b01868c3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 23 Jul 2016 19:03:38 -0700 Subject: [PATCH 3/6] Optimize calculation of block->millimeters for DELTA --- Marlin/planner.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 3d62789188..26ffd5e808 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -803,9 +803,15 @@ void Planner::check_axes_activity() { #endif #else float delta_mm[4]; - delta_mm[X_AXIS] = dx / axis_steps_per_mm[X_AXIS]; - delta_mm[Y_AXIS] = dy / axis_steps_per_mm[Y_AXIS]; - delta_mm[Z_AXIS] = dz / axis_steps_per_mm[Z_AXIS]; + #if ENABLED(DELTA) + // On delta all axes (should!) have the same steps-per-mm + // so calculate distance in steps first, then do one division + // at the end to get millimeters + #else + delta_mm[X_AXIS] = dx / axis_steps_per_mm[X_AXIS]; + delta_mm[Y_AXIS] = dy / axis_steps_per_mm[Y_AXIS]; + delta_mm[Z_AXIS] = dz / axis_steps_per_mm[Z_AXIS]; + #endif #endif delta_mm[E_AXIS] = (de / axis_steps_per_mm[E_AXIS]) * volumetric_multiplier[extruder] * extruder_multiplier[extruder] / 100.0; @@ -820,10 +826,16 @@ void Planner::check_axes_activity() { sq(delta_mm[X_HEAD]) + sq(delta_mm[Y_AXIS]) + sq(delta_mm[Z_HEAD]) #elif ENABLED(COREYZ) sq(delta_mm[X_AXIS]) + sq(delta_mm[Y_HEAD]) + sq(delta_mm[Z_HEAD]) + #elif ENABLED(DELTA) + sq(dx) + sq(dy) + sq(dz) #else sq(delta_mm[X_AXIS]) + sq(delta_mm[Y_AXIS]) + sq(delta_mm[Z_AXIS]) #endif - ); + ) + #if ENABLED(DELTA) + / axis_steps_per_mm[X_AXIS] + #endif + ; } float inverse_millimeters = 1.0 / block->millimeters; // Inverse millimeters to remove multiple divides From f8b5749235eea19134a58656095e2a0f499a2fc7 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 23 Jul 2016 19:36:26 -0700 Subject: [PATCH 4/6] Replace division in planner with multiplication --- Marlin/Marlin_main.cpp | 10 +++---- Marlin/configuration_store.cpp | 6 +++++ Marlin/planner.cpp | 49 ++++++++++++++++++++-------------- Marlin/planner.h | 4 ++- Marlin/stepper.cpp | 2 +- Marlin/stepper.h | 2 +- Marlin/temperature.cpp | 2 +- Marlin/ultralcd.cpp | 13 ++++----- 8 files changed, 53 insertions(+), 35 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 1ad4b80114..70b23a4d3e 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -911,16 +911,15 @@ void setup() { // Send "ok" after commands by default 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(); // Initialize current position based on home_offset memcpy(current_position, home_offset, sizeof(home_offset)); - #if ENABLED(DELTA) || ENABLED(SCARA) - // Vital to init kinematic equivalent for X0 Y0 Z0 - SYNC_PLAN_POSITION_KINEMATIC(); - #endif + // Vital to init stepper/planner equivalent for current_position + SYNC_PLAN_POSITION_KINEMATIC(); thermalManager.init(); // Initialize temperature loop @@ -5148,6 +5147,7 @@ inline void gcode_M92() { } } } + planner.refresh_positioning(); } /** diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index 6a581ee1ff..233a28cd53 100644 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -171,10 +171,16 @@ void Config_Postprocess() { // steps per s2 needs to be updated to agree with units per s2 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) recalc_delta_settings(delta_radius, delta_diagonal_rod); #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) thermalManager.updatePID(); #endif diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 26ffd5e808..decea15763 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -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::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_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) float delta_mm[6]; #if ENABLED(COREXY) - delta_mm[X_HEAD] = dx / axis_steps_per_mm[A_AXIS]; - delta_mm[Y_HEAD] = dy / axis_steps_per_mm[B_AXIS]; - delta_mm[Z_AXIS] = dz / axis_steps_per_mm[Z_AXIS]; - delta_mm[A_AXIS] = (dx + dy) / axis_steps_per_mm[A_AXIS]; - delta_mm[B_AXIS] = (dx - dy) / axis_steps_per_mm[B_AXIS]; + delta_mm[X_HEAD] = dx * steps_to_mm[A_AXIS]; + delta_mm[Y_HEAD] = dy * steps_to_mm[B_AXIS]; + delta_mm[Z_AXIS] = dz * steps_to_mm[Z_AXIS]; + delta_mm[A_AXIS] = (dx + dy) * steps_to_mm[A_AXIS]; + delta_mm[B_AXIS] = (dx - dy) * steps_to_mm[B_AXIS]; #elif ENABLED(COREXZ) - delta_mm[X_HEAD] = dx / axis_steps_per_mm[A_AXIS]; - delta_mm[Y_AXIS] = dy / axis_steps_per_mm[Y_AXIS]; - delta_mm[Z_HEAD] = dz / axis_steps_per_mm[C_AXIS]; - delta_mm[A_AXIS] = (dx + dz) / axis_steps_per_mm[A_AXIS]; - delta_mm[C_AXIS] = (dx - dz) / axis_steps_per_mm[C_AXIS]; + delta_mm[X_HEAD] = dx * steps_to_mm[A_AXIS]; + delta_mm[Y_AXIS] = dy * steps_to_mm[Y_AXIS]; + delta_mm[Z_HEAD] = dz * steps_to_mm[C_AXIS]; + delta_mm[A_AXIS] = (dx + dz) * steps_to_mm[A_AXIS]; + delta_mm[C_AXIS] = (dx - dz) * steps_to_mm[C_AXIS]; #elif ENABLED(COREYZ) - delta_mm[X_AXIS] = dx / axis_steps_per_mm[X_AXIS]; - delta_mm[Y_HEAD] = dy / axis_steps_per_mm[B_AXIS]; - delta_mm[Z_HEAD] = dz / axis_steps_per_mm[C_AXIS]; - delta_mm[B_AXIS] = (dy + dz) / axis_steps_per_mm[B_AXIS]; - delta_mm[C_AXIS] = (dy - dz) / axis_steps_per_mm[C_AXIS]; + delta_mm[X_AXIS] = dx * steps_to_mm[X_AXIS]; + delta_mm[Y_HEAD] = dy * steps_to_mm[B_AXIS]; + delta_mm[Z_HEAD] = dz * steps_to_mm[C_AXIS]; + delta_mm[B_AXIS] = (dy + dz) * steps_to_mm[B_AXIS]; + delta_mm[C_AXIS] = (dy - dz) * steps_to_mm[C_AXIS]; #endif #else float delta_mm[4]; @@ -808,12 +809,12 @@ void Planner::check_axes_activity() { // so calculate distance in steps first, then do one division // at the end to get millimeters #else - delta_mm[X_AXIS] = dx / axis_steps_per_mm[X_AXIS]; - delta_mm[Y_AXIS] = dy / axis_steps_per_mm[Y_AXIS]; - delta_mm[Z_AXIS] = dz / axis_steps_per_mm[Z_AXIS]; + delta_mm[X_AXIS] = dx * steps_to_mm[X_AXIS]; + delta_mm[Y_AXIS] = dy * steps_to_mm[Y_AXIS]; + delta_mm[Z_AXIS] = dz * steps_to_mm[Z_AXIS]; #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) { block->millimeters = fabs(delta_mm[E_AXIS]); @@ -833,7 +834,7 @@ void Planner::check_axes_activity() { #endif ) #if ENABLED(DELTA) - / axis_steps_per_mm[X_AXIS] + * steps_to_mm[X_AXIS] #endif ; } @@ -1176,6 +1177,7 @@ void Planner::check_axes_activity() { void Planner::set_e_position_mm(const float& e) { position[E_AXIS] = lround(e * axis_steps_per_mm[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 @@ -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]; } +// 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) void Planner::autotemp_M109() { diff --git a/Marlin/planner.h b/Marlin/planner.h index 74abd1cb2d..eac1ae5c64 100644 --- a/Marlin/planner.h +++ b/Marlin/planner.h @@ -121,6 +121,7 @@ class Planner { static float max_feedrate_mm_s[NUM_AXIS]; // Max speeds in mm per second 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_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 - * 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]; @@ -187,6 +188,7 @@ class Planner { */ static void reset_acceleration_rates(); + static void refresh_positioning(); // Manage fans, paste pressure, etc. static void check_axes_activity(); diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 90a1ddf65d..63a5d0b312 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -951,7 +951,7 @@ float Stepper::get_axis_position_mm(AxisEnum axis) { #else axis_steps = position(axis); #endif - return axis_steps / planner.axis_steps_per_mm[axis]; + return axis_steps * planner.steps_to_mm[axis]; } void Stepper::finish_and_disable() { diff --git a/Marlin/stepper.h b/Marlin/stepper.h index 45c8753aa7..3ecf93a71e 100644 --- a/Marlin/stepper.h +++ b/Marlin/stepper.h @@ -262,7 +262,7 @@ class Stepper { // Triggered position of an axis in mm (not core-savvy) // 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) diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index db2805285a..82d6477b85 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -572,7 +572,7 @@ float Temperature::get_pid_output(int e) { lpq[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]; } #endif //PID_ADD_EXTRUSION_RATE diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 2a9e6e90e0..65c3ba9cc4 100755 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -678,7 +678,7 @@ void kill_screen(const char* lcd_msg) { } if (lcdDrawUpdate) 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 _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(float5, MSG_A_RETRACT, &planner.retract_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(float52, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_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_CALLBACK(float52, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999, _planner_refresh_positioning); #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 - 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 - 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) MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit); #endif From ddde785b37dafeb1463822dc16cec20eae7d90b1 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 23 Jul 2016 19:49:13 -0700 Subject: [PATCH 5/6] Code formatting in planner.cpp --- Marlin/planner.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index decea15763..8bb9a6ac0b 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -80,30 +80,31 @@ block_t Planner::block_buffer[BLOCK_BUFFER_SIZE]; volatile uint8_t Planner::block_buffer_head = 0; // Index of the next block to be pushed volatile uint8_t Planner::block_buffer_tail = 0; -float Planner::max_feedrate_mm_s[NUM_AXIS]; // Max speeds in mm per second -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_mm_per_s2[NUM_AXIS]; // Use M201 to override by software +float Planner::max_feedrate_mm_s[NUM_AXIS], // Max speeds in mm per second + Planner::axis_steps_per_mm[NUM_AXIS], + Planner::steps_to_mm[NUM_AXIS]; + +unsigned long Planner::max_acceleration_steps_per_s2[NUM_AXIS], + Planner::max_acceleration_mm_per_s2[NUM_AXIS]; // Use M201 to override by software millis_t Planner::min_segment_time; -float Planner::min_feedrate_mm_s; -float Planner::acceleration; // Normal acceleration mm/s^2 DEFAULT ACCELERATION for all printing moves. M204 SXXXX -float Planner::retract_acceleration; // Retract acceleration mm/s^2 filament pull-back and push-forward while standing still in the other axes M204 TXXXX -float Planner::travel_acceleration; // Travel acceleration mm/s^2 DEFAULT ACCELERATION for all NON printing moves. M204 MXXXX -float Planner::max_xy_jerk; // The largest speed change requiring no acceleration -float Planner::max_z_jerk; -float Planner::max_e_jerk; -float Planner::min_travel_feedrate_mm_s; +float Planner::min_feedrate_mm_s, + Planner::acceleration, // Normal acceleration mm/s^2 DEFAULT ACCELERATION for all printing moves. M204 SXXXX + Planner::retract_acceleration, // Retract acceleration mm/s^2 filament pull-back and push-forward while standing still in the other axes M204 TXXXX + Planner::travel_acceleration, // Travel acceleration mm/s^2 DEFAULT ACCELERATION for all NON printing moves. M204 MXXXX + Planner::max_xy_jerk, // The largest speed change requiring no acceleration + Planner::max_z_jerk, + Planner::max_e_jerk, + Planner::min_travel_feedrate_mm_s; #if ENABLED(AUTO_BED_LEVELING_FEATURE) matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level #endif #if ENABLED(AUTOTEMP) - float Planner::autotemp_max = 250; - float Planner::autotemp_min = 210; - float Planner::autotemp_factor = 0.1; + float Planner::autotemp_max = 250, + Planner::autotemp_min = 210, + Planner::autotemp_factor = 0.1; bool Planner::autotemp_enabled = false; #endif @@ -111,9 +112,8 @@ float Planner::min_travel_feedrate_mm_s; long Planner::position[NUM_AXIS] = { 0 }; -float Planner::previous_speed[NUM_AXIS]; - -float Planner::previous_nominal_speed; +float Planner::previous_speed[NUM_AXIS], + Planner::previous_nominal_speed; #if ENABLED(DISABLE_INACTIVE_EXTRUDER) uint8_t Planner::g_uc_extruder_last_move[EXTRUDERS] = { 0 }; From d8f2876753b05c6c73ba1412631789fcb7db7ad8 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 24 Jul 2016 11:50:54 -0700 Subject: [PATCH 6/6] Replace some float division with multiplication --- Marlin/Marlin_main.cpp | 6 +++--- Marlin/planner.cpp | 16 +++++++++------- Marlin/stepper.cpp | 6 +++--- Marlin/temperature.cpp | 8 ++++---- Marlin/ultralcd_impl_DOGM.h | 2 +- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 70b23a4d3e..ec0fc51d26 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1332,7 +1332,7 @@ inline bool code_value_bool() { return code_value_byte() > 0; } case TEMPUNIT_C: return code_value_float(); case TEMPUNIT_F: - return (code_value_float() - 32) / 1.8; + return (code_value_float() - 32) * 0.5555555556; case TEMPUNIT_K: return code_value_float() - 272.15; default: @@ -1346,7 +1346,7 @@ inline bool code_value_bool() { return code_value_byte() > 0; } case TEMPUNIT_K: return code_value_float(); case TEMPUNIT_F: - return code_value_float() / 1.8; + return code_value_float() * 0.5555555556; default: return code_value_float(); } @@ -6141,7 +6141,7 @@ inline void gcode_M428() { bool err = false; LOOP_XYZ(i) { if (axis_homed[i]) { - float base = (current_position[i] > (sw_endstop_min[i] + sw_endstop_max[i]) / 2) ? base_home_pos(i) : 0, + float base = (current_position[i] > (sw_endstop_min[i] + sw_endstop_max[i]) * 0.5) ? base_home_pos(i) : 0, diff = current_position[i] - LOGICAL_POSITION(base, i); if (diff > -20 && diff < 20) { set_home_offset((AxisEnum)i, home_offset[i] - diff); diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 8bb9a6ac0b..d59f6c8e9f 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -814,7 +814,7 @@ void Planner::check_axes_activity() { delta_mm[Z_AXIS] = dz * steps_to_mm[Z_AXIS]; #endif #endif - delta_mm[E_AXIS] = (de * steps_to_mm[E_AXIS]) * volumetric_multiplier[extruder] * extruder_multiplier[extruder] / 100.0; + delta_mm[E_AXIS] = 0.01 * (de * steps_to_mm[E_AXIS]) * volumetric_multiplier[extruder] * extruder_multiplier[extruder]; if (block->steps[X_AXIS] <= dropsegments && block->steps[Y_AXIS] <= dropsegments && block->steps[Z_AXIS] <= dropsegments) { block->millimeters = fabs(delta_mm[E_AXIS]); @@ -888,7 +888,7 @@ void Planner::check_axes_activity() { while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM; // Convert into an index into the measurement array - filwidth_delay_index1 = (int)(filwidth_delay_dist / 10.0 + 0.0001); + filwidth_delay_index1 = (int)(filwidth_delay_dist * 0.1 + 0.0001); // If the index has changed (must have gone forward)... if (filwidth_delay_index1 != filwidth_delay_index2) { @@ -975,7 +975,7 @@ void Planner::check_axes_activity() { block->acceleration_steps_per_s2 = (max_acceleration_steps_per_s2[E_AXIS] * block->step_event_count) / block->steps[E_AXIS]; } block->acceleration = block->acceleration_steps_per_s2 / steps_per_mm; - block->acceleration_rate = (long)(block->acceleration_steps_per_s2 * 16777216.0 / ((F_CPU) / 8.0)); + block->acceleration_rate = (long)(block->acceleration_steps_per_s2 * 16777216.0 / ((F_CPU) * 0.125)); #if 0 // Use old jerk for now @@ -1021,10 +1021,12 @@ void Planner::check_axes_activity() { #endif // Start with a safe speed - float vmax_junction = max_xy_jerk / 2; - float vmax_junction_factor = 1.0; - float mz2 = max_z_jerk / 2, me2 = max_e_jerk / 2; - float csz = current_speed[Z_AXIS], cse = current_speed[E_AXIS]; + float vmax_junction = max_xy_jerk * 0.5, + vmax_junction_factor = 1.0, + mz2 = max_z_jerk * 0.5, + me2 = max_e_jerk * 0.5, + csz = current_speed[Z_AXIS], + cse = current_speed[E_AXIS]; if (fabs(csz) > mz2) vmax_junction = min(vmax_junction, mz2); if (fabs(cse) > me2) vmax_junction = min(vmax_junction, me2); vmax_junction = min(vmax_junction, block->nominal_speed); diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 63a5d0b312..88e8cd5600 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -944,7 +944,7 @@ float Stepper::get_axis_position_mm(AxisEnum axis) { CRITICAL_SECTION_END; // ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1 // ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2 - axis_steps = (pos1 + ((axis == CORE_AXIS_1) ? pos2 : -pos2)) / 2.0f; + axis_steps = (pos1 + ((axis == CORE_AXIS_1) ? pos2 : -pos2)) * 0.5f; } else axis_steps = position(axis); @@ -973,9 +973,9 @@ void Stepper::endstop_triggered(AxisEnum axis) { float axis_pos = count_position[axis]; if (axis == CORE_AXIS_1) - axis_pos = (axis_pos + count_position[CORE_AXIS_2]) / 2; + axis_pos = (axis_pos + count_position[CORE_AXIS_2]) * 0.5; else if (axis == CORE_AXIS_2) - axis_pos = (count_position[CORE_AXIS_1] - axis_pos) / 2; + axis_pos = (count_position[CORE_AXIS_1] - axis_pos) * 0.5; endstops_trigsteps[axis] = axis_pos; #else // !COREXY && !COREXZ && !COREYZ diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 82d6477b85..666edd90f9 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -319,13 +319,13 @@ unsigned char Temperature::soft_pwm[HOTENDS]; SERIAL_PROTOCOLPAIR(MSG_T_MIN, min); SERIAL_PROTOCOLPAIR(MSG_T_MAX, max); if (cycles > 2) { - Ku = (4.0 * d) / (3.14159265 * (max - min) / 2.0); - Tu = ((float)(t_low + t_high) / 1000.0); + Ku = (4.0 * d) / (3.14159265 * (max - min) * 0.5); + Tu = ((float)(t_low + t_high) * 0.001); SERIAL_PROTOCOLPAIR(MSG_KU, Ku); SERIAL_PROTOCOLPAIR(MSG_TU, Tu); workKp = 0.6 * Ku; workKi = 2 * workKp / Tu; - workKd = workKp * Tu / 8; + workKd = workKp * Tu * 0.125; SERIAL_PROTOCOLLNPGM(MSG_CLASSIC_PID); SERIAL_PROTOCOLPAIR(MSG_KP, workKp); SERIAL_PROTOCOLPAIR(MSG_KI, workKi); @@ -753,7 +753,7 @@ void Temperature::manage_heater() { // Get the delayed info and add 100 to reconstitute to a percent of // the nominal filament diameter then square it to get an area meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY); - float vm = pow((measurement_delay[meas_shift_index] + 100.0) / 100.0, 2); + float vm = pow((measurement_delay[meas_shift_index] + 100.0) * 0.01, 2); NOLESS(vm, 0.01); volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vm; } diff --git a/Marlin/ultralcd_impl_DOGM.h b/Marlin/ultralcd_impl_DOGM.h index 22a86a5dab..742e253f27 100644 --- a/Marlin/ultralcd_impl_DOGM.h +++ b/Marlin/ultralcd_impl_DOGM.h @@ -385,7 +385,7 @@ static void lcd_implementation_status_screen() { // SD Card Progress bar and clock if (IS_SD_PRINTING) { // Progress bar solid part - u8g.drawBox(55, 50, (unsigned int)(71.f * card.percentDone() / 100.f), 2 - (TALL_FONT_CORRECTION)); + u8g.drawBox(55, 50, (unsigned int)(71 * card.percentDone() * 0.01), 2 - (TALL_FONT_CORRECTION)); } u8g.setPrintPos(80,48);