Skip to content

Commit

Permalink
dockable_probe: fbocs feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerlz committed Jan 13, 2025
1 parent 902bd67 commit eeea778
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions klippy/extras/dockable_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit eeea778

Please sign in to comment.