safe_z_home: Simplify logic and fix edge case

Signed-off-by: Florian Heilmann <Florian.Heilmann@gmx.net>
This commit is contained in:
Florian Heilmann 2021-05-18 17:31:07 +01:00 committed by KevinOConnor
parent 391ebd32c1
commit cf61ca301b
1 changed files with 13 additions and 19 deletions

View File

@ -34,22 +34,23 @@ class SafeZHoming:
# Perform Z Hop if necessary # Perform Z Hop if necessary
if self.z_hop != 0.0: if self.z_hop != 0.0:
# Check if Z axis is homed or has a known position # Check if Z axis is homed and its last known position
curtime = self.printer.get_reactor().monotonic() curtime = self.printer.get_reactor().monotonic()
kin_status = toolhead.get_kinematics().get_status(curtime) kin_status = toolhead.get_kinematics().get_status(curtime)
if 'z' in kin_status['homed_axes']:
# Check if the zhop would exceed the printer limits
pos = toolhead.get_position() pos = toolhead.get_position()
if pos[2] + self.z_hop > self.max_z:
gcmd.respond_info( if 'z' not in kin_status['homed_axes']:
"No zhop performed, target Z out of bounds: " + # Always perform the z_hop if the Z axis is not homed
str(pos[2] + self.z_hop)) pos[2] = 0
elif pos[2] < self.z_hop: toolhead.set_position(pos, homing_axes=[2])
self._perform_z_hop() toolhead.manual_move([None, None, self.z_hop],
else: self.z_hop_speed)
self._perform_z_hop()
if hasattr(toolhead.get_kinematics(), "note_z_not_homed"): if hasattr(toolhead.get_kinematics(), "note_z_not_homed"):
toolhead.get_kinematics().note_z_not_homed() toolhead.get_kinematics().note_z_not_homed()
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],
self.z_hop_speed)
# Determine which axes we need to home # Determine which axes we need to home
need_x, need_y, need_z = [gcmd.get(axis, None) is not None need_x, need_y, need_z = [gcmd.get(axis, None) is not None
@ -88,12 +89,5 @@ class SafeZHoming:
if self.move_to_previous: if self.move_to_previous:
toolhead.manual_move(prevpos[:2], self.speed) toolhead.manual_move(prevpos[:2], self.speed)
def _perform_z_hop(self):
toolhead = self.printer.lookup_object('toolhead')
# Perform the Z-Hop
pos = toolhead.get_position()
toolhead.set_position(pos, homing_axes=[2])
toolhead.manual_move([None, None, pos[2]+self.z_hop], self.z_hop_speed)
def load_config(config): def load_config(config):
return SafeZHoming(config) return SafeZHoming(config)