diff --git a/Marlin/enum.h b/Marlin/enum.h index 18db5a6f5f..713f3b64c0 100644 --- a/Marlin/enum.h +++ b/Marlin/enum.h @@ -23,6 +23,8 @@ #ifndef __ENUM_H__ #define __ENUM_H__ +#include "MarlinConfig.h" + /** * Axis indices as enumerated constants * diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index c55770e256..5d54f14fad 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -1201,7 +1201,8 @@ void Planner::buffer_line(ARG_X, ARG_Y, ARG_Z, const float &e, float fr_mm_s, co } // buffer_line() /** - * Directly set the planner XYZ position (hence the stepper positions). + * Directly set the planner XYZ position (and stepper positions) + * converting mm (or angles for SCARA) into steps. * * On CORE machines stepper ABC will be translated from the given XYZ. */ @@ -1229,12 +1230,12 @@ void Planner::sync_from_steppers() { } /** - * Directly set the planner E position (hence the stepper E position). + * Setters for planner position (also setting stepper position). */ -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; +void Planner::set_position_mm(const AxisEnum axis, const float& v) { + position[axis] = lround(v * axis_steps_per_mm[axis]); + stepper.set_position(axis, v); + previous_speed[axis] = 0.0; } // Recalculate the steps/s^2 acceleration rates, based on the mm/s^2 diff --git a/Marlin/planner.h b/Marlin/planner.h index 499f9eb529..c198f083aa 100644 --- a/Marlin/planner.h +++ b/Marlin/planner.h @@ -33,6 +33,7 @@ #define PLANNER_H #include "types.h" +#include "enum.h" #include "MarlinConfig.h" #if HAS_ABL @@ -242,17 +243,16 @@ class Planner { * Clears previous speed values. */ static void set_position_mm(ARG_X, ARG_Y, ARG_Z, const float& e); + static void set_position_mm(const AxisEnum axis, const float& v); + + static FORCE_INLINE void set_z_position_mm(const float& z) { set_position_mm(Z_AXIS, z); } + static FORCE_INLINE void set_e_position_mm(const float& e) { set_position_mm(E_AXIS, e); } /** * Sync from the stepper positions. (e.g., after an interrupted move) */ static void sync_from_steppers(); - /** - * Set the E position (mm) of the planner (and the E stepper) - */ - static void set_e_position_mm(const float& e); - /** * Does the buffer have any blocks queued? */ diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 06183a7f5f..7674bd2dbe 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -970,6 +970,12 @@ void Stepper::set_position(const long& x, const long& y, const long& z, const lo CRITICAL_SECTION_END; } +void Stepper::set_position(const AxisEnum &axis, const long& v) { + CRITICAL_SECTION_START; + count_position[axis] = v; + CRITICAL_SECTION_END; +} + void Stepper::set_e_position(const long& e) { CRITICAL_SECTION_START; count_position[E_AXIS] = e; diff --git a/Marlin/stepper.h b/Marlin/stepper.h index a1c62fe941..3e31f82d19 100644 --- a/Marlin/stepper.h +++ b/Marlin/stepper.h @@ -189,6 +189,7 @@ class Stepper { // Set the current position in steps // static void set_position(const long& x, const long& y, const long& z, const long& e); + static void set_position(const AxisEnum& a, const long& v); static void set_e_position(const long& e); //