From 3e62be45c07d43759bc85f5c6e0e383534259e32 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 10 Jan 2025 11:58:26 -0500 Subject: [PATCH] force_move: Use strings for axes to clear in clear_homing_state() Pass a string such as "xyz" to kin.clear_homing_state(). This makes the parameter a little less cryptic. Signed-off-by: Kevin O'Connor --- klippy/extras/force_move.py | 5 ++--- klippy/extras/safe_z_home.py | 2 +- klippy/extras/stepper_enable.py | 2 +- klippy/kinematics/cartesian.py | 8 ++++---- klippy/kinematics/corexy.py | 8 ++++---- klippy/kinematics/corexz.py | 8 ++++---- klippy/kinematics/delta.py | 4 ++-- klippy/kinematics/deltesian.py | 8 ++++---- klippy/kinematics/hybrid_corexy.py | 8 ++++---- klippy/kinematics/hybrid_corexz.py | 8 ++++---- klippy/kinematics/none.py | 2 +- klippy/kinematics/polar.py | 6 +++--- klippy/kinematics/rotary_delta.py | 4 ++-- klippy/kinematics/winch.py | 2 +- 14 files changed, 37 insertions(+), 38 deletions(-) diff --git a/klippy/extras/force_move.py b/klippy/extras/force_move.py index 0b2187fd71ba..35a541a58383 100644 --- a/klippy/extras/force_move.py +++ b/klippy/extras/force_move.py @@ -131,9 +131,8 @@ def cmd_SET_KINEMATIC_POSITION(self, gcmd): x = gcmd.get_float('X', curpos[0]) y = gcmd.get_float('Y', curpos[1]) z = gcmd.get_float('Z', curpos[2]) - clear = gcmd.get('CLEAR', '').upper() - axes = ['X', 'Y', 'Z'] - clear_axes = [axes.index(a) for a in axes if a in clear] + clear = gcmd.get('CLEAR', '').lower() + clear_axes = "".join([a for a in "xyz" if a in clear]) logging.info("SET_KINEMATIC_POSITION pos=%.3f,%.3f,%.3f clear=%s", x, y, z, ','.join((axes[i] for i in clear_axes))) toolhead.set_position([x, y, z, curpos[3]], homing_axes="xyz") diff --git a/klippy/extras/safe_z_home.py b/klippy/extras/safe_z_home.py index 3ebaa13e7c2d..32b515b9a3b7 100644 --- a/klippy/extras/safe_z_home.py +++ b/klippy/extras/safe_z_home.py @@ -40,7 +40,7 @@ def cmd_G28(self, gcmd): toolhead.set_position(pos, homing_axes="z") toolhead.manual_move([None, None, self.z_hop], self.z_hop_speed) - toolhead.get_kinematics().clear_homing_state((2,)) + toolhead.get_kinematics().clear_homing_state("z") elif pos[2] < self.z_hop: # If the Z axis is homed, and below z_hop, lift it to z_hop toolhead.manual_move([None, None, self.z_hop], diff --git a/klippy/extras/stepper_enable.py b/klippy/extras/stepper_enable.py index 4e8f3bbb60f6..2bad755527d9 100644 --- a/klippy/extras/stepper_enable.py +++ b/klippy/extras/stepper_enable.py @@ -94,7 +94,7 @@ def motor_off(self): print_time = toolhead.get_last_move_time() for el in self.enable_lines.values(): el.motor_disable(print_time) - toolhead.get_kinematics().clear_homing_state((0, 1, 2)) + toolhead.get_kinematics().clear_homing_state("xyz") self.printer.send_event("stepper_enable:motor_off", print_time) toolhead.dwell(DISABLE_STALL_TIME) def motor_debug_enable(self, stepper, enable): diff --git a/klippy/kinematics/cartesian.py b/klippy/kinematics/cartesian.py index 0c22172b6897..2a50a05de8fa 100644 --- a/klippy/kinematics/cartesian.py +++ b/klippy/kinematics/cartesian.py @@ -72,10 +72,10 @@ def set_position(self, newpos, homing_axes): else: rail = self.rails[axis] self.limits[axis] = rail.get_range() - def clear_homing_state(self, axes): - for i, _ in enumerate(self.limits): - if i in axes: - self.limits[i] = (1.0, -1.0) + def clear_homing_state(self, clear_axes): + for axis, axis_name in enumerate("xyz"): + if axis_name in clear_axes: + self.limits[axis] = (1.0, -1.0) def home_axis(self, homing_state, axis, rail): # Determine movement position_min, position_max = rail.get_range() diff --git a/klippy/kinematics/corexy.py b/klippy/kinematics/corexy.py index 891e58e0d378..d68f8854f390 100644 --- a/klippy/kinematics/corexy.py +++ b/klippy/kinematics/corexy.py @@ -41,10 +41,10 @@ def set_position(self, newpos, homing_axes): rail.set_position(newpos) if "xyz"[i] in homing_axes: self.limits[i] = rail.get_range() - def clear_homing_state(self, axes): - for i, _ in enumerate(self.limits): - if i in axes: - self.limits[i] = (1.0, -1.0) + def clear_homing_state(self, clear_axes): + for axis, axis_name in enumerate("xyz"): + if axis_name in clear_axes: + self.limits[axis] = (1.0, -1.0) def home(self, homing_state): # Each axis is homed independently and in order for axis in homing_state.get_axes(): diff --git a/klippy/kinematics/corexz.py b/klippy/kinematics/corexz.py index 34def72a1bb2..8d3e027c3229 100644 --- a/klippy/kinematics/corexz.py +++ b/klippy/kinematics/corexz.py @@ -41,10 +41,10 @@ def set_position(self, newpos, homing_axes): rail.set_position(newpos) if "xyz"[i] in homing_axes: self.limits[i] = rail.get_range() - def clear_homing_state(self, axes): - for i, _ in enumerate(self.limits): - if i in axes: - self.limits[i] = (1.0, -1.0) + def clear_homing_state(self, clear_axes): + for axis, axis_name in enumerate("xyz"): + if axis_name in clear_axes: + self.limits[axis] = (1.0, -1.0) def home(self, homing_state): # Each axis is homed independently and in order for axis in homing_state.get_axes(): diff --git a/klippy/kinematics/delta.py b/klippy/kinematics/delta.py index beb1826f0e59..aa244a8f383b 100644 --- a/klippy/kinematics/delta.py +++ b/klippy/kinematics/delta.py @@ -103,9 +103,9 @@ def set_position(self, newpos, homing_axes): self.limit_xy2 = -1. if homing_axes == "xyz": self.need_home = False - def clear_homing_state(self, axes): + def clear_homing_state(self, clear_axes): # Clearing homing state for each axis individually is not implemented - if 0 in axes or 1 in axes or 2 in axes: + if clear_axes: self.limit_xy2 = -1 self.need_home = True def home(self, homing_state): diff --git a/klippy/kinematics/deltesian.py b/klippy/kinematics/deltesian.py index e0118b34abae..1f7ddaa0550d 100644 --- a/klippy/kinematics/deltesian.py +++ b/klippy/kinematics/deltesian.py @@ -116,10 +116,10 @@ def set_position(self, newpos, homing_axes): for axis_name in homing_axes: axis = "xyz".index(axis_name) self.homed_axis[axis] = True - def clear_homing_state(self, axes): - for i, _ in enumerate(self.limits): - if i in axes: - self.homed_axis[i] = False + def clear_homing_state(self, clear_axes): + for axis, axis_name in enumerate("xyz"): + if axis_name in clear_axes: + self.homed_axis[axis] = False def home(self, homing_state): homing_axes = homing_state.get_axes() home_xz = 0 in homing_axes or 2 in homing_axes diff --git a/klippy/kinematics/hybrid_corexy.py b/klippy/kinematics/hybrid_corexy.py index 6d72a89c8b1d..fbaf49e4d962 100644 --- a/klippy/kinematics/hybrid_corexy.py +++ b/klippy/kinematics/hybrid_corexy.py @@ -74,10 +74,10 @@ def set_position(self, newpos, homing_axes): else: rail = self.rails[axis] self.limits[axis] = rail.get_range() - def clear_homing_state(self, axes): - for i, _ in enumerate(self.limits): - if i in axes: - self.limits[i] = (1.0, -1.0) + def clear_homing_state(self, clear_axes): + for axis, axis_name in enumerate("xyz"): + if axis_name in clear_axes: + self.limits[axis] = (1.0, -1.0) def home_axis(self, homing_state, axis, rail): position_min, position_max = rail.get_range() hi = rail.get_homing_info() diff --git a/klippy/kinematics/hybrid_corexz.py b/klippy/kinematics/hybrid_corexz.py index 05fe096e5a35..6fa120f77f10 100644 --- a/klippy/kinematics/hybrid_corexz.py +++ b/klippy/kinematics/hybrid_corexz.py @@ -74,10 +74,10 @@ def set_position(self, newpos, homing_axes): else: rail = self.rails[axis] self.limits[axis] = rail.get_range() - def clear_homing_state(self, axes): - for i, _ in enumerate(self.limits): - if i in axes: - self.limits[i] = (1.0, -1.0) + def clear_homing_state(self, clear_axes): + for axis, axis_name in enumerate("xyz"): + if axis_name in clear_axes: + self.limits[axis] = (1.0, -1.0) def home_axis(self, homing_state, axis, rail): position_min, position_max = rail.get_range() hi = rail.get_homing_info() diff --git a/klippy/kinematics/none.py b/klippy/kinematics/none.py index fda1f073a38c..d9f9d21d20be 100644 --- a/klippy/kinematics/none.py +++ b/klippy/kinematics/none.py @@ -13,7 +13,7 @@ def calc_position(self, stepper_positions): return [0, 0, 0] def set_position(self, newpos, homing_axes): pass - def clear_homing_state(self, axes): + def clear_homing_state(self, clear_axes): pass def home(self, homing_state): pass diff --git a/klippy/kinematics/polar.py b/klippy/kinematics/polar.py index 548b4bacd3d0..73967c29c71e 100644 --- a/klippy/kinematics/polar.py +++ b/klippy/kinematics/polar.py @@ -49,11 +49,11 @@ def set_position(self, newpos, homing_axes): self.limit_z = self.rails[1].get_range() if "x" in homing_axes and "y" in homing_axes: self.limit_xy2 = self.rails[0].get_range()[1]**2 - def clear_homing_state(self, axes): - if 0 in axes or 1 in axes: + def clear_homing_state(self, clear_axes): + if "x" in clear_axes or "y" in clear_axes: # X and Y cannot be cleared separately self.limit_xy2 = -1. - if 2 in axes: + if "z" in clear_axes: self.limit_z = (1.0, -1.0) def _home_axis(self, homing_state, axis, rail): # Determine movement diff --git a/klippy/kinematics/rotary_delta.py b/klippy/kinematics/rotary_delta.py index 6b457ccb1843..35f7ca986997 100644 --- a/klippy/kinematics/rotary_delta.py +++ b/klippy/kinematics/rotary_delta.py @@ -86,9 +86,9 @@ def set_position(self, newpos, homing_axes): self.limit_xy2 = -1. if homing_axes == "xyz": self.need_home = False - def clear_homing_state(self, axes): + def clear_homing_state(self, clear_axes): # Clearing homing state for each axis individually is not implemented - if 0 in axes or 1 in axes or 2 in axes: + if clear_axes: self.limit_xy2 = -1 self.need_home = True def home(self, homing_state): diff --git a/klippy/kinematics/winch.py b/klippy/kinematics/winch.py index 0003826b86ab..47bc68558029 100644 --- a/klippy/kinematics/winch.py +++ b/klippy/kinematics/winch.py @@ -36,7 +36,7 @@ def calc_position(self, stepper_positions): def set_position(self, newpos, homing_axes): for s in self.steppers: s.set_position(newpos) - def clear_homing_state(self, axes): + def clear_homing_state(self, clear_axes): # XXX - homing not implemented pass def home(self, homing_state):