From eeea7787a48f64d5e95f6f40e9e00ac8581ab7f7 Mon Sep 17 00:00:00 2001 From: Rogerio Goncalves Date: Mon, 13 Jan 2025 08:42:00 -0300 Subject: [PATCH] dockable_probe: fbocs feedback --- klippy/extras/dockable_probe.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/klippy/extras/dockable_probe.py b/klippy/extras/dockable_probe.py index 078280acc..ada45b644 100644 --- a/klippy/extras/dockable_probe.py +++ b/klippy/extras/dockable_probe.py @@ -31,6 +31,11 @@ Please see {0}.md and config_Reference.md. """ +VIRTUAL_Z_ENDSTOP_ERROR = """ +DockableProbe cannot be used as Z endstop if a z position +is defined in approach/dock/extract/insert/detach position." +""" + # Helper class to handle polling pins for probe attachment states class PinPollingHelper: @@ -374,6 +379,17 @@ def _handle_config(self): def _handle_connect(self): self.toolhead = self.printer.lookup_object("toolhead") + rails = self.toolhead.get_kinematics().rails + endstops = [es for rail in rails for es, name in rail.get_endstops()] + positions = [ + self.approach_position, + self.dock_position, + self.extract_position, + self.insert_position, + self.detach_position, + ] + if self in endstops and any(pos[2] is not None for pos in positions): + raise self.printer.config_error(VIRTUAL_Z_ENDSTOP_ERROR) ####################################################################### # GCode Commands @@ -507,7 +523,6 @@ def cmd_MOVE_AVOIDING_DOCK(self, gcmd): def attach_probe(self, return_pos=None, always_restore_toolhead=False): self._lower_probe() - self.pre_attach_gcode.run_gcode_from_command() retry = 0 while ( @@ -518,6 +533,7 @@ def attach_probe(self, return_pos=None, always_restore_toolhead=False): raise self.printer.command_error( "Attach Probe: Probe not detected in dock, aborting" ) + self.pre_attach_gcode.run_gcode_from_command() # Call these gcodes as a script because we don't have enough # structs/data to call the cmd_...() funcs and supply 'gcmd'. # This method also has the advantage of calling user-written gcodes @@ -529,6 +545,7 @@ def attach_probe(self, return_pos=None, always_restore_toolhead=False): MOVE_TO_EXTRACT_PROBE """ ) + self.post_attach_gcode.run_gcode_from_command() retry += 1 @@ -542,15 +559,13 @@ def attach_probe(self, return_pos=None, always_restore_toolhead=False): # Do NOT return to the original Z position after attach # as the probe might crash into the bed. - self.post_attach_gcode.run_gcode_from_command() - def detach_probe(self, return_pos=None): - self.pre_detach_gcode.run_gcode_from_command() retry = 0 while ( self.get_probe_state() != PROBE_DOCKED and retry < self.dock_retries + 1 ): + self.pre_detach_gcode.run_gcode_from_command() # Call these gcodes as a script because we don't have enough # structs/data to call the cmd_...() funcs and supply 'gcmd'. # This method also has the advantage of calling user-written gcodes @@ -562,14 +577,13 @@ def detach_probe(self, return_pos=None): MOVE_TO_DETACH_PROBE """ ) + self.post_detach_gcode.run_gcode_from_command() retry += 1 if self.get_probe_state() != PROBE_DOCKED: raise self.printer.command_error("Probe detach failed!") - self.post_detach_gcode.run_gcode_from_command() - if return_pos and self.restore_toolhead: # return to the original XY position, if inside safe_dock area # move to the closest point