safe_z_home: Hop only if necessary and add option to move xy back

Once a hop is performed, it will only be re-issued if the z-axis has been
moved in the meantime. Usually it is only moved by a z-homing so doing so
will cause safe_z_home to do the hop on the next homing action.

When z-axis is homed, x and y positions are known. When setting this
boolean option, these are set back to their last positions.

Whenever a hop is specified it is re-issued after the Z axis has been
homed. This is especially necessary when a pressure-based probe is used.
Also, the module decides if a hop is necessary, based on either a known
Z position or a flag that is set whenever the motors are disabled.

Signed-off-by: Nils Friedchen <Nils.Friedchen@googlemail.com>
This commit is contained in:
Master92 2019-09-18 15:37:33 +02:00 committed by KevinOConnor
parent 80775faa09
commit 3a37d4a208
3 changed files with 47 additions and 16 deletions

View File

@ -313,10 +313,17 @@
#z_hop: 0.0 #z_hop: 0.0
# Lift the Z axis prior to homing. This is applied to any homing command, # Lift the Z axis prior to homing. This is applied to any homing command,
# even if it doesn't home the Z axis. If the Z axis is already homed and # even if it doesn't home the Z axis. If the Z axis is already homed and
# the zhop would exceed the printer limits, the zhop is ignored. # the zhop would exceed the printer limits, the zhop is ignored. If a lift
# has already been performed or the Z axis is known to be equally or higher
# than this distance, the zhop is ignored. After homing Z completed, the
# printhead is lifted to zhop, respecting the probe's z_offset.
# The default is 0.0mm. # The default is 0.0mm.
#z_hop_speed: 20.0 #z_hop_speed: 20.0
# Speed at which the Z axis is lifted prior to homing. The default is 20mm/s. # Speed at which the Z axis is lifted prior to homing. The default is 20mm/s.
#move_to_previous: True
# When set to True, xy are reset to their previous positions after z homing.
# The default is True.
# Homing override. One may use this mechanism to run a series of # Homing override. One may use this mechanism to run a series of
# g-code commands in place of a G28 found in the normal g-code input. # g-code commands in place of a G28 found in the normal g-code input.

View File

@ -6,6 +6,10 @@ All dates in this document are approximate.
# Changes # Changes
20190918: The zhop option in [safe_z_homing] is always re-applied
after Z axis homing completed. This might need users to update custom
scripts based on this module.
20190806: The SET_NEOPIXEL command has been renamed to SET_LED. 20190806: The SET_NEOPIXEL command has been renamed to SET_LED.
20190726: The mcp4728 digital-to-analog code has changed. The default 20190726: The mcp4728 digital-to-analog code has changed. The default

View File

@ -9,7 +9,7 @@ class SafeZHoming:
self.printer = config.get_printer() self.printer = config.get_printer()
try: try:
x_pos, y_pos = config.get("home_xy_position", x_pos, y_pos = config.get("home_xy_position",
default=",").split(',') default=",").split(',')
self.home_x_pos, self.home_y_pos = float(x_pos), float(y_pos) self.home_x_pos, self.home_y_pos = float(x_pos), float(y_pos)
except: except:
raise config.error("Unable to parse home_xy_position in %s" % ( raise config.error("Unable to parse home_xy_position in %s" % (
@ -19,36 +19,35 @@ class SafeZHoming:
self.z_hop_speed = config.getfloat('z_hop_speed', 15., above=0.) self.z_hop_speed = config.getfloat('z_hop_speed', 15., above=0.)
self.max_z = config.getsection('stepper_z').getfloat('position_max') self.max_z = config.getsection('stepper_z').getfloat('position_max')
self.speed = config.getfloat('speed', 50.0, above=0.) self.speed = config.getfloat('speed', 50.0, above=0.)
self.move_to_previous = config.getboolean('move_to_previous', True)
self.gcode = self.printer.lookup_object('gcode') self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command("G28", None) self.gcode.register_command("G28", None)
self.gcode.register_command("G28", self.cmd_G28) self.gcode.register_command("G28", self.cmd_G28)
if config.has_section("homing_override"): if config.has_section("homing_override"):
raise config.error("homing_override and safe_z_homing cannot" raise config.error("homing_override and safe_z_homing cannot"
+" be used simultaneously") +" be used simultaneously")
def cmd_G28(self, params): def cmd_G28(self, params):
toolhead = self.printer.lookup_object('toolhead') toolhead = self.printer.lookup_object('toolhead')
kinematics = toolhead.get_kinematics() kinematics = toolhead.get_kinematics()
# Perform Z Hop if necessary # Perform Z Hop if necessary
if self.z_hop != 0.0: if self.z_hop != 0.0:
# Check if the zhop would exceed the printer limits
pos = toolhead.get_position() pos = toolhead.get_position()
kin_status = kinematics.get_status() kin_status = kinematics.get_status()
if ('Z' in kin_status['homed_axes'] and # Check if Z axis is homed or has a known position
pos[2] + self.z_hop > self.max_z): if 'Z' in kin_status['homed_axes']:
self.gcode.respond_info( # Check if the zhop would exceed the printer limits
"No zhop performed, target Z out of bounds: " + if pos[2] + self.z_hop > self.max_z:
str(pos[2] + self.z_hop) self.gcode.respond_info(
) "No zhop performed, target Z out of bounds: " +
str(pos[2] + self.z_hop)
)
elif pos[2] < self.z_hop:
self._perform_z_hop(pos)
else: else:
# Perform the Z-Hop self._perform_z_hop(pos)
toolhead.set_position(pos, homing_axes=[2])
pos[2] = pos[2] + self.z_hop
toolhead.move(pos, self.z_hop_speed)
self.gcode.reset_last_position()
# Determine which axes we need to home # Determine which axes we need to home
if not any([axis in params.keys() for axis in ['X', 'Y', 'Z']]): if not any([axis in params.keys() for axis in ['X', 'Y', 'Z']]):
@ -69,6 +68,8 @@ class SafeZHoming:
if need_z: if need_z:
# Move to safe XY homing position # Move to safe XY homing position
pos = toolhead.get_position() pos = toolhead.get_position()
prev_x = pos[0]
prev_y = pos[1]
if self.home_x_pos: if self.home_x_pos:
pos[0] = self.home_x_pos pos[0] = self.home_x_pos
if self.home_y_pos: if self.home_y_pos:
@ -77,6 +78,25 @@ class SafeZHoming:
self.gcode.reset_last_position() self.gcode.reset_last_position()
# Home Z # Home Z
self.gcode.cmd_G28({'Z': '0'}) self.gcode.cmd_G28({'Z': '0'})
# Perform Z Hop again for pressure-based probes
pos = toolhead.get_position()
if self.z_hop:
pos[2] = self.z_hop
toolhead.move(pos, self.z_hop_speed)
# Move XY back to previous positions
if self.move_to_previous:
pos[0] = prev_x
pos[1] = prev_y
toolhead.move(pos, self.speed)
self.gcode.reset_last_position()
def _perform_z_hop(self, pos):
toolhead = self.printer.lookup_object('toolhead')
# Perform the Z-Hop
toolhead.set_position(pos, homing_axes=[2])
pos[2] = pos[2] + self.z_hop
toolhead.move(pos, self.z_hop_speed)
self.gcode.reset_last_position()
def load_config(config): def load_config(config):
return SafeZHoming(config) return SafeZHoming(config)