From 10987003b09a5b88fa0d7cbfff76ffa2f857b445 Mon Sep 17 00:00:00 2001 From: Florian Heilmann Date: Wed, 5 Aug 2020 17:52:23 +0200 Subject: [PATCH] safe_z_home: Make sure X and Y are homed before homing Z (#3153) In it's current behavior, safe_z_home will attempt to home Z if it thinks the toolhead is above the z endstop even if the motors have since been disabled and the toolhead was moved to another position Signed-off-by: Florian Heilmann --- klippy/extras/safe_z_home.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/klippy/extras/safe_z_home.py b/klippy/extras/safe_z_home.py index eaaee965..9f6dd7bd 100644 --- a/klippy/extras/safe_z_home.py +++ b/klippy/extras/safe_z_home.py @@ -30,12 +30,12 @@ class SafeZHoming: def cmd_G28(self, gcmd): toolhead = self.printer.lookup_object('toolhead') + curtime = self.printer.get_reactor().monotonic() + kin_status = toolhead.get_kinematics().get_status(curtime) # Perform Z Hop if necessary if self.z_hop != 0.0: pos = toolhead.get_position() - curtime = self.printer.get_reactor().monotonic() - kin_status = toolhead.get_kinematics().get_status(curtime) # Check if Z axis is homed or has a known position if 'z' in kin_status['homed_axes']: # Check if the zhop would exceed the printer limits @@ -65,14 +65,23 @@ class SafeZHoming: if new_params: g28_gcmd = self.gcode.create_gcode_command("G28", "G28", new_params) self.prev_G28(g28_gcmd) + + # Update the currently homed axes + curtime = self.printer.get_reactor().monotonic() + kin_status = toolhead.get_kinematics().get_status(curtime) + # Home Z axis if necessary if need_z: - # Move to safe XY homing position pos = toolhead.get_position() prev_x = pos[0] prev_y = pos[1] pos[0] = self.home_x_pos pos[1] = self.home_y_pos + # Throw an error if X or Y are not homed + if ('x' not in kin_status['homed_axes'] or + 'y' not in kin_status['homed_axes']): + raise gcmd.error("Must home X and Y axes first") + # Move to safe XY homing position toolhead.move(pos, self.speed) self.gcode.reset_last_position() # Home Z