From f47fff31d2f1240588a8c36368f13f7a62bf8719 Mon Sep 17 00:00:00 2001 From: BillyNate Date: Tue, 12 Sep 2023 13:44:35 +0200 Subject: [PATCH 1/8] Removed `approach_position`, `detach_position` & `dock_position` in favor of `attach_route` & `dock_route` This should increase compatability and simplify the code --- klippy/extras/dockable_probe.py | 250 +++++++------------------------- 1 file changed, 55 insertions(+), 195 deletions(-) diff --git a/klippy/extras/dockable_probe.py b/klippy/extras/dockable_probe.py index d8d568248c1b..57d6806537ab 100644 --- a/klippy/extras/dockable_probe.py +++ b/klippy/extras/dockable_probe.py @@ -34,12 +34,12 @@ HINT_VIRTUAL_ENDSTOP_ERROR = """ {0}: Using a 'probe:z_virtual_endstop' Z endstop is -incompatible with 'approach_position'/'dock_position' +incompatible with 'attach_route'/'dock_route' containing a Z coordinate. If the toolhead doesn't need to move in Z to reach the dock then no Z coordinate should be specified in -'approach_position'/'dock_position'. +'attach_route'/'dock_route'. Please see {0}.md and config_Reference.md. """ @@ -182,20 +182,12 @@ def __init__(self, config): 2., above=0.) # Positions (approach, detach, etc) - self.approach_position = self._parse_coord(config, 'approach_position') - self.detach_position = self._parse_coord(config, 'detach_position') - self.dock_position = self._parse_coord(config, 'dock_position') - self.z_hop = config.getfloat('z_hop', 0., above=0.) + self.z_hop = config.getfloat('z_hop', 0., above=0.) - self.dock_requires_z = (len(self.approach_position) > 2 - or len(self.dock_position) > 2) - - self.dock_angle, self.approach_distance = self._get_vector( - self.dock_position, - self.approach_position) - self.detach_angle, self.detach_distance = self._get_vector( - self.dock_position, - self.detach_position) + self.attach_route = self._config_getcoordlists(config, 'attach_route') + self.dock_route = self._config_getcoordlists(config, 'dock_route') + self.dock_requires_z = max(list(map(lambda coords: len(coords), + self.attach_route + self.dock_route))) > 2 # Pins ppins = self.printer.lookup_object('pins') @@ -233,22 +225,6 @@ def __init__(self, config): self.cmd_QUERY_DOCKABLE_PROBE, desc=self.cmd_QUERY_DOCKABLE_PROBE_help) - self.gcode.register_command('MOVE_TO_APPROACH_PROBE', - self.cmd_MOVE_TO_APPROACH_PROBE, - desc=self.cmd_MOVE_TO_APPROACH_PROBE_help) - self.gcode.register_command('MOVE_TO_DOCK_PROBE', - self.cmd_MOVE_TO_DOCK_PROBE, - desc=self.cmd_MOVE_TO_DOCK_PROBE_help) - self.gcode.register_command('MOVE_TO_EXTRACT_PROBE', - self.cmd_MOVE_TO_EXTRACT_PROBE, - desc=self.cmd_MOVE_TO_EXTRACT_PROBE_help) - self.gcode.register_command('MOVE_TO_INSERT_PROBE', - self.cmd_MOVE_TO_INSERT_PROBE, - desc=self.cmd_MOVE_TO_INSERT_PROBE_help) - self.gcode.register_command('MOVE_TO_DETACH_PROBE', - self.cmd_MOVE_TO_DETACH_PROBE, - desc=self.cmd_MOVE_TO_DETACH_PROBE_help) - self.gcode.register_command('SET_DOCKABLE_PROBE', self.cmd_SET_DOCKABLE_PROBE, desc=self.cmd_SET_DOCKABLE_PROBE_help) @@ -263,27 +239,14 @@ def __init__(self, config): self.printer.register_event_handler('klippy:connect', self._handle_connect) - # Parse a string coordinate representation from the config - # and return a list of numbers. - # - # e.g. "233, 10, 0" -> [233, 10, 0] - def _parse_coord(self, config, name, expected_dims=3): - val = config.get(name) - error_msg = "Unable to parse {0} in {1}: {2}" - if not val: - return None - try: - vals = [float(x.strip()) for x in val.split(',')] - except Exception as e: - raise config.error(error_msg.format(name, self.name, str(e))) - supplied_dims = len(vals) - if not 2 <= supplied_dims <= expected_dims: - raise config.error(error_msg.format(name, self.name, + def _config_getcoordlists(self, config, name, min_dims=2, max_dims=3): + val = config.getlists(name, seps=(',', '\n'), parser=float) + for coord in val: + if not min_dims <= len(coord) <= max_dims: + raise config.error("Unable to parse {0} in {1}: {2}".format(name, self.name, "Invalid number of coordinates")) - p = [None] * supplied_dims - p[:supplied_dims] = vals - return p - + return val + def _build_config(self): kin = self.printer.lookup_object('toolhead').get_kinematics() for stepper in kin.get_steppers(): @@ -293,8 +256,8 @@ def _build_config(self): def _handle_connect(self): self.toolhead = self.printer.lookup_object('toolhead') - # If neither position config options contain a Z coordinate return early - if not self.dock_requires_z: + # If no z hop necessary return early + if self.z_hop <= 0.0: return query_endstops = self.printer.lookup_object('query_endstops') @@ -323,56 +286,6 @@ def get_status(self, curtime): 'last_status': self.last_probe_state, } - cmd_MOVE_TO_APPROACH_PROBE_help = "Move close to the probe dock" \ - "before attaching" - def cmd_MOVE_TO_APPROACH_PROBE(self, gcmd): - self._align_z() - - if self._check_distance(dist=self.approach_distance): - self._align_to_vector(self.dock_angle) - else: - self._move_to_vector(self.dock_angle) - - if len(self.approach_position) > 2: - self.toolhead.manual_move([None, None, self.approach_position[2]], - self.travel_speed) - - self.toolhead.manual_move( - [self.approach_position[0], self.approach_position[1], None], - self.travel_speed) - - cmd_MOVE_TO_DOCK_PROBE_help = "Move to connect the toolhead/dock" \ - "to the probe" - def cmd_MOVE_TO_DOCK_PROBE(self, gcmd): - if len(self.dock_position) > 2: - self.toolhead.manual_move([None, None, self.dock_position[2]], - self.attach_speed) - - self.toolhead.manual_move( - [self.dock_position[0], self.dock_position[1], None], - self.attach_speed) - - cmd_MOVE_TO_EXTRACT_PROBE_help = "Move away from the dock with the" \ - "probe attached" - def cmd_MOVE_TO_EXTRACT_PROBE(self, gcmd): - self.cmd_MOVE_TO_APPROACH_PROBE(gcmd) - - cmd_MOVE_TO_INSERT_PROBE_help = "Move near the dock with the" \ - "probe attached before detaching" - def cmd_MOVE_TO_INSERT_PROBE(self, gcmd): - self.cmd_MOVE_TO_APPROACH_PROBE(gcmd) - - cmd_MOVE_TO_DETACH_PROBE_help = "Move away from the dock to detach" \ - "the probe" - def cmd_MOVE_TO_DETACH_PROBE(self, gcmd): - if len(self.detach_position) > 2: - self.toolhead.manual_move([None, None, self.detach_position[2]], - self.detach_speed) - - self.toolhead.manual_move( - [self.detach_position[0], self.detach_position[1], None], - self.detach_speed) - cmd_SET_DOCKABLE_PROBE_help = "Set probe parameters" def cmd_SET_DOCKABLE_PROBE(self, gcmd): auto = gcmd.get('AUTO_ATTACH_DETACH', None) @@ -403,58 +316,64 @@ def attach_probe(self, return_pos=None): if self.get_probe_state() != PROBE_DOCKED: raise self.printer.command_error( 'Attach Probe: Probe not detected in dock, aborting') - # 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 - # if they've been defined. - self.gcode.run_script_from_command(""" - MOVE_TO_APPROACH_PROBE - MOVE_TO_DOCK_PROBE - MOVE_TO_EXTRACT_PROBE - """) + + self._align_z() + + travel = True + for position in self.attach_route: + speed = self.travel_speed if travel else self.attach_speed + travel = False + z_pos = None if len(position) <= 2 else position[2] + + self.toolhead.manual_move([position[0], position[1], z_pos], + speed) retry += 1 if self.get_probe_state() != PROBE_ATTACHED: raise self.printer.command_error('Probe attach failed!') + + self._align_z() if return_pos: - if not self._check_distance(return_pos, self.approach_distance): - self.toolhead.manual_move( - [return_pos[0], return_pos[1], None], - self.travel_speed) - # Do NOT return to the original Z position after attach - # as the probe might crash into the bed. + self.toolhead.manual_move( + [return_pos[0], return_pos[1], None], + self.travel_speed) + # Do NOT return to the original Z position after attach + # as the probe might crash into the bed. def detach_probe(self, return_pos=None): retry = 0 while (self.get_probe_state() != PROBE_DOCKED and retry < self.dock_retries + 1): - # 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 - # if they've been defined. - self.gcode.run_script_from_command(""" - MOVE_TO_INSERT_PROBE - MOVE_TO_DOCK_PROBE - MOVE_TO_DETACH_PROBE - """) + + self._align_z() + + travel = True + for position in self.dock_route: + speed = self.travel_speed if travel else self.detach_speed + travel = False + z_pos = None if len(position) <= 2 else position[2] + + self.toolhead.manual_move([position[0], position[1], z_pos], + speed) retry += 1 if self.get_probe_state() != PROBE_DOCKED: raise self.printer.command_error('Probe detach failed!') + + self._align_z() if return_pos: - if not self._check_distance(return_pos, self.detach_distance): - self.toolhead.manual_move( - [return_pos[0], return_pos[1], None], - self.travel_speed) - # Return to original Z position after detach as - # there's no chance of the probe crashing into the bed. - self.toolhead.manual_move( - [None, None, return_pos[2]], - self.travel_speed) + self.toolhead.manual_move( + [return_pos[0], return_pos[1], None], + self.travel_speed) + # Return to original Z position after detach as + # there's no chance of the probe crashing into the bed. + self.toolhead.manual_move( + [None, None, return_pos[2]], + self.travel_speed) def auto_detach_probe(self, return_pos=None): if self.get_probe_state() == PROBE_DOCKED: @@ -474,62 +393,6 @@ def auto_attach_probe(self, return_pos=None): # Functions for calculating points and moving the toolhead ####################################################################### - # Move the toolhead to minimum safe distance aligned with angle - def _move_to_vector(self, angle): - x, y = self._get_point_on_vector(self.dock_position[:2], - angle, - self.approach_distance) - self.toolhead.manual_move([x,y,None], self.travel_speed) - - # Move the toolhead to angle within minimium safe distance - def _align_to_vector(self, angle): - approach = self._get_intercept(self.toolhead.get_position(), - angle + (pi/2), - self.dock_position, - angle) - self.toolhead.manual_move([approach[0], approach[1], None], - self.attach_speed) - - # Determine toolhead distance to dock coordinates - def _check_distance(self, pos=None, dist=None): - if not pos: - pos = self.toolhead.get_position() - dock = self.dock_position - - if dist > sqrt((pos[0]-dock[0])**2 + - (pos[1]-dock[1])**2 ): - return True - else: - return False - - # Find a point on a vector line at a specific distance - def _get_point_on_vector(self, point, angle, magnitude=1): - x = point[0] - magnitude * cos(angle) - y = point[1] - magnitude * sin(angle) - return (x, y) - - # Locate the intersection of two vectors - def _get_intercept(self, point1, angle1, point2, angle2): - x1, y1 = point1[:2] - x2, y2 = self._get_point_on_vector(point1, angle1, 10.0) - x3, y3 = point2[:2] - x4, y4 = self._get_point_on_vector(point2, angle2, 10.0) - det1 = ((x1 * y2) - (y1 * x2)) - det2 = ((x3 * y4) - (y3 * x4)) - d = ((x1 - x2) * (y3 - y4)) - ((y1 - y2) * (x3 - x4)) - x = float((det1 * (x3 - x4)) - ((x1 - x2) * det2)) / d - y = float((det1 * (y3 - y4)) - ((y1 - y2) * det2)) / d - return (x, y) - - # Determine the vector of two points - def _get_vector(self, point1, point2): - x1, y1 = point1[:2] - x2, y2 = point2[:2] - magnitude = sqrt((x2-x1)**2 + (y2-y1)**2 ) - angle = atan2(y2-y1, x2-x1) + pi - - return angle, magnitude - # Align z axis to prevent crashes def _align_z(self): curtime = self.printer.get_reactor().monotonic() @@ -553,9 +416,6 @@ def _align_z_required(self): raise self.printer.command_error( "Cannot attach/detach probe, must home Z axis first") - self.toolhead.manual_move([None, None, self.approach_position[2]], - self.lift_speed) - # Hop z and return to un-homed state def _force_z_hop(self): this_z = self.toolhead.get_position()[2] From 515c7ff16dbf6f02d26473c6b2cf7ed94ce1f3ca Mon Sep 17 00:00:00 2001 From: BillyNate Date: Tue, 12 Sep 2023 23:48:59 +0200 Subject: [PATCH 2/8] Replaced `detach` for `dock` in code for improved consistency --- klippy/extras/dockable_probe.py | 48 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/klippy/extras/dockable_probe.py b/klippy/extras/dockable_probe.py index 57d6806537ab..f4f4c23ef963 100644 --- a/klippy/extras/dockable_probe.py +++ b/klippy/extras/dockable_probe.py @@ -170,18 +170,18 @@ def __init__(self, config): self.lift_speed = config.getfloat('lift_speed', self.speed, above=0.) self.dock_retries = config.getint('dock_retries', 0) - self.auto_attach_detach = config.getboolean('auto_attach_detach', + self.auto_attach_dock = config.getboolean('auto_attach_dock', True) self.travel_speed = config.getfloat('travel_speed', self.speed, above=0.) self.attach_speed = config.getfloat('attach_speed', self.travel_speed, above=0.) - self.detach_speed = config.getfloat('detach_speed', + self.dock_speed = config.getfloat('dock_speed', self.travel_speed, above=0.) self.sample_retract_dist = config.getfloat('sample_retract_dist', 2., above=0.) - # Positions (approach, detach, etc) + # Positions (approach, dock, etc) self.z_hop = config.getfloat('z_hop', 0., above=0.) self.attach_route = self._config_getcoordlists(config, 'attach_route') @@ -231,9 +231,9 @@ def __init__(self, config): self.gcode.register_command('ATTACH_PROBE', self.cmd_ATTACH_PROBE, desc=self.cmd_ATTACH_PROBE_help) - self.gcode.register_command('DETACH_PROBE', - self.cmd_DETACH_PROBE, - desc=self.cmd_DETACH_PROBE_help) + self.gcode.register_command('DOCK_PROBE', + self.cmd_DOCK_PROBE, + desc=self.cmd_DOCK_PROBE_help) # Event Handlers self.printer.register_event_handler('klippy:connect', @@ -288,14 +288,14 @@ def get_status(self, curtime): cmd_SET_DOCKABLE_PROBE_help = "Set probe parameters" def cmd_SET_DOCKABLE_PROBE(self, gcmd): - auto = gcmd.get('AUTO_ATTACH_DETACH', None) + auto = gcmd.get('AUTO_ATTACH_DOCK', None) if auto is None: return if int(auto) == 1: - self.auto_attach_detach = True + self.auto_attach_dock = True else: - self.auto_attach_detach = False + self.auto_attach_dock = False cmd_ATTACH_PROBE_help = "Check probe status and attach probe using" \ "the movement gcodes" @@ -303,11 +303,11 @@ def cmd_ATTACH_PROBE(self, gcmd): return_pos = self.toolhead.get_position() self.attach_probe(return_pos) - cmd_DETACH_PROBE_help = "Check probe status and detach probe using" \ + cmd_DOCK_PROBE_help = "Check probe status and dock probe using" \ "the movement gcodes" - def cmd_DETACH_PROBE(self, gcmd): + def cmd_DOCK_PROBE(self, gcmd): return_pos = self.toolhead.get_position() - self.detach_probe(return_pos) + self.dock_probe(return_pos) def attach_probe(self, return_pos=None): retry = 0 @@ -342,7 +342,7 @@ def attach_probe(self, return_pos=None): # Do NOT return to the original Z position after attach # as the probe might crash into the bed. - def detach_probe(self, return_pos=None): + def dock_probe(self, return_pos=None): retry = 0 while (self.get_probe_state() != PROBE_DOCKED and retry < self.dock_retries + 1): @@ -351,7 +351,7 @@ def detach_probe(self, return_pos=None): travel = True for position in self.dock_route: - speed = self.travel_speed if travel else self.detach_speed + speed = self.travel_speed if travel else self.dock_speed travel = False z_pos = None if len(position) <= 2 else position[2] @@ -361,7 +361,7 @@ def detach_probe(self, return_pos=None): retry += 1 if self.get_probe_state() != PROBE_DOCKED: - raise self.printer.command_error('Probe detach failed!') + raise self.printer.command_error('Probe dock failed!') self._align_z() @@ -369,22 +369,22 @@ def detach_probe(self, return_pos=None): self.toolhead.manual_move( [return_pos[0], return_pos[1], None], self.travel_speed) - # Return to original Z position after detach as + # Return to original Z position after dock as # there's no chance of the probe crashing into the bed. self.toolhead.manual_move( [None, None, return_pos[2]], self.travel_speed) - def auto_detach_probe(self, return_pos=None): + def auto_dock_probe(self, return_pos=None): if self.get_probe_state() == PROBE_DOCKED: return - if self.auto_attach_detach: - self.detach_probe(return_pos) + if self.auto_attach_dock: + self.dock_probe(return_pos) def auto_attach_probe(self, return_pos=None): if self.get_probe_state() == PROBE_ATTACHED: return - if not self.auto_attach_detach: + if not self.auto_attach_dock: raise self.printer.command_error("Cannot probe, probe is not " \ "attached and auto-attach is disabled") self.attach_probe(return_pos) @@ -452,10 +452,10 @@ def multi_probe_end(self): return_pos = self.toolhead.get_position() # Move away from the bed to ensure the probe isn't triggered, - # preventing detaching in the event there's no probe/dock sensor. + # preventing docking in the event there's no probe/dock sensor. self.toolhead.manual_move([None, None, return_pos[2]+2], self.travel_speed) - self.auto_detach_probe(return_pos) + self.auto_dock_probe(return_pos) def probe_prepare(self, hmove): if self.multi == MULTI_OFF or self.multi == MULTI_FIRST: @@ -469,10 +469,10 @@ def probe_finish(self, hmove): if self.multi == MULTI_OFF: return_pos = self.toolhead.get_position() # Move away from the bed to ensure the probe isn't triggered, - # preventing detaching in the event there's no probe/dock sensor. + # preventing docking in the event there's no probe/dock sensor. self.toolhead.manual_move([None, None, return_pos[2]+2], self.travel_speed) - self.auto_detach_probe(return_pos) + self.auto_dock_probe(return_pos) def home_start(self, print_time, sample_time, sample_count, rest_time, triggered=True): From 1ff4273bb4d21680e0ffe771f43705cb00e20114 Mon Sep 17 00:00:00 2001 From: BillyNate Date: Tue, 12 Sep 2023 23:37:48 +0200 Subject: [PATCH 3/8] Removed `return_pos` from `auto_attach_probe` calls, because returning is only a waste of time between attaching and moving to first probe point --- klippy/extras/dockable_probe.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/klippy/extras/dockable_probe.py b/klippy/extras/dockable_probe.py index f4f4c23ef963..db727db64879 100644 --- a/klippy/extras/dockable_probe.py +++ b/klippy/extras/dockable_probe.py @@ -445,7 +445,7 @@ def multi_probe_begin(self): # If the toolhead is not returned to the current position it # will complete the probing next to the dock. return_pos = self.toolhead.get_position() - self.auto_attach_probe(return_pos) + self.auto_attach_probe() def multi_probe_end(self): self.multi = MULTI_OFF @@ -460,7 +460,7 @@ def multi_probe_end(self): def probe_prepare(self, hmove): if self.multi == MULTI_OFF or self.multi == MULTI_FIRST: return_pos = self.toolhead.get_position() - self.auto_attach_probe(return_pos) + self.auto_attach_probe() if self.multi == MULTI_FIRST: self.multi = MULTI_ON From ae0c95f54665eb212df88406135ae571a93c3575 Mon Sep 17 00:00:00 2001 From: BillyNate Date: Wed, 13 Sep 2023 00:17:04 +0200 Subject: [PATCH 4/8] Replaced the hardcoded "move away from bed" by `+2` for a z-hop --- klippy/extras/dockable_probe.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/klippy/extras/dockable_probe.py b/klippy/extras/dockable_probe.py index db727db64879..be53f716a717 100644 --- a/klippy/extras/dockable_probe.py +++ b/klippy/extras/dockable_probe.py @@ -451,10 +451,9 @@ def multi_probe_end(self): self.multi = MULTI_OFF return_pos = self.toolhead.get_position() - # Move away from the bed to ensure the probe isn't triggered, + # Move to z hop to ensure the probe isn't triggered, # preventing docking in the event there's no probe/dock sensor. - self.toolhead.manual_move([None, None, return_pos[2]+2], - self.travel_speed) + self._align_z() self.auto_dock_probe(return_pos) def probe_prepare(self, hmove): @@ -468,10 +467,9 @@ def probe_finish(self, hmove): self.wait_trigger_complete.wait() if self.multi == MULTI_OFF: return_pos = self.toolhead.get_position() - # Move away from the bed to ensure the probe isn't triggered, + # Move to z hop to ensure the probe isn't triggered, # preventing docking in the event there's no probe/dock sensor. - self.toolhead.manual_move([None, None, return_pos[2]+2], - self.travel_speed) + self._align_z() self.auto_dock_probe(return_pos) def home_start(self, print_time, sample_time, sample_count, rest_time, From 2288df0d7ce2a72d48b8679d0d5b2826b48b14ed Mon Sep 17 00:00:00 2001 From: BillyNate Date: Wed, 13 Sep 2023 10:32:32 +0200 Subject: [PATCH 5/8] Probe now returns to its original position, even on a complete bed mesh calibration --- klippy/extras/dockable_probe.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/klippy/extras/dockable_probe.py b/klippy/extras/dockable_probe.py index be53f716a717..d339de9b8689 100644 --- a/klippy/extras/dockable_probe.py +++ b/klippy/extras/dockable_probe.py @@ -209,6 +209,7 @@ def __init__(self, config): self.last_z = -9999 self.multi = MULTI_OFF self._last_homed = None + self._return_pos = None pstate = ProbeState(config, self) self.get_probe_state = pstate.get_probe_state @@ -444,21 +445,21 @@ def multi_probe_begin(self): # point but for the latter the toolhead is already in position. # If the toolhead is not returned to the current position it # will complete the probing next to the dock. - return_pos = self.toolhead.get_position() + self._return_pos = self.toolhead.get_position() self.auto_attach_probe() def multi_probe_end(self): self.multi = MULTI_OFF - return_pos = self.toolhead.get_position() # Move to z hop to ensure the probe isn't triggered, # preventing docking in the event there's no probe/dock sensor. self._align_z() - self.auto_dock_probe(return_pos) + self.auto_dock_probe(self._return_pos) def probe_prepare(self, hmove): if self.multi == MULTI_OFF or self.multi == MULTI_FIRST: - return_pos = self.toolhead.get_position() + if self._return_pos is None: + self._return_pos = self.toolhead.get_position() self.auto_attach_probe() if self.multi == MULTI_FIRST: self.multi = MULTI_ON @@ -466,11 +467,10 @@ def probe_prepare(self, hmove): def probe_finish(self, hmove): self.wait_trigger_complete.wait() if self.multi == MULTI_OFF: - return_pos = self.toolhead.get_position() # Move to z hop to ensure the probe isn't triggered, # preventing docking in the event there's no probe/dock sensor. self._align_z() - self.auto_dock_probe(return_pos) + self.auto_dock_probe(self._return_pos) def home_start(self, print_time, sample_time, sample_count, rest_time, triggered=True): From 71bdfb01e2d76ceec1a7e7c10b6aa7c965974c26 Mon Sep 17 00:00:00 2001 From: BillyNate Date: Wed, 13 Sep 2023 10:34:29 +0200 Subject: [PATCH 6/8] Added two `gcode.respond_info` commands for improved feedback to user --- klippy/extras/dockable_probe.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/klippy/extras/dockable_probe.py b/klippy/extras/dockable_probe.py index d339de9b8689..50d5216d59e0 100644 --- a/klippy/extras/dockable_probe.py +++ b/klippy/extras/dockable_probe.py @@ -334,6 +334,8 @@ def attach_probe(self, return_pos=None): if self.get_probe_state() != PROBE_ATTACHED: raise self.printer.command_error('Probe attach failed!') + self.gcode.respond_info("Probe attached!") + self._align_z() if return_pos: @@ -364,6 +366,8 @@ def dock_probe(self, return_pos=None): if self.get_probe_state() != PROBE_DOCKED: raise self.printer.command_error('Probe dock failed!') + self.gcode.respond_info("Probe docked!") + self._align_z() if return_pos: From de36c8101337e52172bd49889688d81ed3558f9c Mon Sep 17 00:00:00 2001 From: BillyNate Date: Thu, 14 Sep 2023 09:59:06 +0200 Subject: [PATCH 7/8] Updated documentation because of the change in settings of dockable_probe --- docs/Config_Reference.md | 38 ++++--- docs/Dockable_Probe.md | 207 +++++++++++++-------------------------- docs/G-Codes.md | 10 +- 3 files changed, 88 insertions(+), 167 deletions(-) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index 66cdca0ef13d..8c7b63aebcbf 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -1907,27 +1907,25 @@ for more detailed information regarding configuration and setup. ``` [dockable_probe] -dock_position: 0,0,0 -# The physical position of the probe dock relative to the origin of +attach_route: + 0.0, 0.0 + 0.0, 0.0, 1.0 + 0.0, 10.0 +# The physical positions of the toolhead relative to the origin of # the bed. The coordinates are specified as a comma separated X, Y, Z -# list of values. Certain dock designs are independent of the Z axis. -# If Z is specified the toolhead will move to the Z location before the X, Y -# coordinates. +# list of values, where Z is optional. Certain dock designs are +# independent of the Z axis. The toolhead will walk through these +# locations in the given order when the probe needs to be attached. # This parameter is required. -approach_position: 0,0,0 -# The X, Y, Z position where the toolhead needs to be prior to moving into the -# dock so that the probe is aligned properly for attaching or detaching. -# If Z is specified the toolhead will move to the Z location before the X, Y -# coordinates. -# This parameter is required. -detach_position: 0,0,0 -# Similar to the approach_position, the detach_position is the coordinates -# where the toolhead is moved after the probe has been docked. -# For magnetically coupled probes, this is typically perpendicular to -# the approach_position in a direction that does not cause the tool to -# collide with the printer. -# If Z is specified the toolhead will move to the Z location before the X, Y -# coordinates. +dock_route: + 0.0, 10.0 + 0.0, 10.0, 1.0 + 0.0, 0.0 +# The physical positions of the toolhead relative to the origin of +# the bed. The coordinates are specified as a comma separated X, Y, Z +# list of values, where Z is optional. Certain dock designs are +# independent of the Z axis. The toolhead will walk through these +# locations in the given order when the probe needs to be docked. # This parameter is required. #z_hop: 15.0 # Distance (in mm) to lift the Z axis prior to attaching/detaching the probe. @@ -1944,7 +1942,7 @@ detach_position: 0,0,0 # actions that require the probe. # The default is True. #attach_speed: -#detach_speed: +#dock_speed: #travel_speed: # Optional speeds used during moves. # The default is to use `speed` of `probe` or 5.0. diff --git a/docs/Dockable_Probe.md b/docs/Dockable_Probe.md index cb2955d185d7..bc9e793ccd2b 100644 --- a/docs/Dockable_Probe.md +++ b/docs/Dockable_Probe.md @@ -19,19 +19,22 @@ for `[probe]` are valid for `[dockable_probe]`. pin: z_offset: sample_retract_dist: -approach_position: -dock_position: -detach_position: +attach_route: +dock_route: (check_open_attach: OR probe_sense_pin:) AND/OR dock_sense_pin: ``` -### Attaching and Detaching Positions +### Attaching and Docking Routes -- `dock_position: 300, 295, 0`\ +- `attach_route:`\ _Required_\ - This is the XYZ coordinates where the toolhead needs to be positioned - in order to attach the probe. This parameter is X, Y and, Z separated - by commas. + This is the route of coordinates the toolhead follows in order to attach + the probe. Each line contains X, Y, and optional Z, separated by commas. + + The most common dock designs use a fork or arms that extend out from the dock. + In order to attach the probe to the toolhead, the toolhead must move into and + away from the dock to a particular position so these arms can capture the + probe body. Many configurations have the dock attached to a moving gantry. This means that Z axis positioning is irrelevant. However, it may be necessary @@ -43,39 +46,20 @@ detach_position: configuration the Z axis parameter _must_ be supplied, and the Z axis _must_ be homed prior to attaching the probe. -- `approach_position: 300, 250, 0`\ +- `dock_route:` _Required_\ - The most common dock designs use a fork or arms that extend out from the dock. - In order to attach the probe to the toolhead, the toolhead must move into and - away from the dock to a particular position so these arms can capture the - probe body. - - As with `dock_position`, a Z position is not required but if specified the - toolhead will be moved to that Z location before the X, Y coordinates. - - For magnetically coupled probes, the `approach_position` should be far enough - away from the probe dock such that the magnets on the probe body are not - attracted to the magnets on the toolhead. + Identical to `attach_route`, but used for putting the probe back into the dock. -- `detach_position: 250, 295, 0`\ - _Required_\ Most probes with magnets require the toolhead to move in a direction that strips the magnets off with a sliding motion. This is to prevent the magnets from becoming unseated from repeated pulling and thus affecting probe accuracy. - The `detach_position` is typically defined as a point that is perpendicular to - the dock so that when the toolhead moves, the probe stays docked but cleanly + When creating the `dock_route` make sure that decoupling happens perpendicular + to the dock so that when the toolhead moves, the probe stays docked but cleanly detaches from the toolhead mount. - As with `dock_position`, a Z position is not required but if specified the - toolhead will be moved to that Z location before the X, Y coordinates. - - For magnetically coupled probes, the `detach_position` should be far enough - away from the probe dock such that the magnets on the probe body are not - attracted to the magnets on the toolhead. - - `z_hop: 15.0`\ _Default Value: None_\ - Distance (in mm) to lift the Z axis prior to attaching/detaching the probe. + Distance (in mm) to lift the Z axis prior to attaching/docking the probe. If the Z axis is already homed and the current Z position is less than `z_hop`, then this will lift the head to a height of `z_hop`. If the Z axis is not already homed the head is lifted by `z_hop`. @@ -96,9 +80,14 @@ will move back, and then to the side. ``` ``` -approach_position: 150, 300, 5 -dock_position: 150, 330, 5 -detach_position: 170, 330 +attach_route: + 150, 300, 5 + 150, 330, 5 + 150, 300 +dock_route: + 150, 300, 5 + 150, 330, 5 + 170, 330 ``` @@ -116,9 +105,14 @@ forward. ``` ``` -approach_position: 50, 150 -dock_position: 10, 150 -detach_position: 10, 130 +attach_route: + 50, 150 + 10, 150 + 50, 150 +dock_route: + 50, 150 + 10, 150 + 10, 130 ``` @@ -135,19 +129,21 @@ as above. ``` ``` -approach_position: 50, 150 -dock_position: 10, 150 -detach_position: 10, 130 +attach_route: + 50, 150 + 10, 150 + 50, 150 +dock_route: + 50, 150 + 10, 150 + 10, 130 z_hop: 15 ``` -Euclid style probe that requires the attach and detach movements to happen in -opposite order. Attach: approach, move to dock, extract. Detach: move to -extract position, move to dock, move to approach position. The approach and -detach positions are the same, as are the extract and insert positions. The -movements can be reordered as necessary by overriding the commands for -extract/insert and using the same coordinates for approach and detach. +Euclid style probe that requires the attach and dock movements to happen in +opposite order. To attach the probe, the toolhead will move to the side and forward. +To detach, the toolhead will move back, and then to the side. ``` Attach: @@ -156,7 +152,7 @@ Attach: | p< | | v | +--------+ -Detach: +Dock: +--------+ | | | p> | @@ -165,22 +161,17 @@ Detach: ``` ``` -approach_position: 50, 150 -dock_position: 10, 150 -detach_position: 50, 150 +attach_route: + 50, 150 + 10, 150 + 10, 130 +dock_route: + 10, 130 + 10, 150 + 50, 150 z_hop: 15 ``` -``` -[gcode_macro MOVE_TO_EXTRACT_PROBE] -gcode: - G1 X10 Y130 - -[gcode_macro MOVE_TO_INSERT_PROBE] -gcode: - G1 X10 Y130 -``` - ### Homing No configuration specific to the dockable probe is required when using @@ -242,16 +233,17 @@ methods can be used to verify probe attachment states. - `attach_speed: 5.0`\ _Default Value: Probe `speed` or 5_\ - Movement speed when attaching the probe during `MOVE_TO_DOCK_PROBE`. + Movement speed when attaching the probe during `ATTACH_PROBE`. -- `detach_speed: 5.0`\ +- `dock_speed: 5.0`\ _Default Value: Probe `speed` or 5_\ - Movement speed when detaching the probe during `MOVE_TO_DETACH_PROBE`. + Movement speed when docking the probe during `DOCK_PROBE`. - `travel_speed: 5.0`\ _Default Value: Probe `speed` or 5_\ - Movement speed when approaching the probe during `MOVE_TO_APPROACH_PROBE` - and returning the toolhead to its previous position after attach/detach. + Movement speed when moving to the first position of `attach_route` and + `dock_route` and returning the toolhead to its previous position after + attach/detach. ## Dockable Probe Gcodes @@ -263,50 +255,12 @@ This command will move the toolhead to the dock, attach the probe, and return it to its previous position. If the probe is already attached, the command does nothing. -This command will call `MOVE_TO_APPROACH_PROBE`, `MOVE_TO_DOCK_PROBE`, -and `MOVE_TO_EXTRACT_PROBE`. +`DOCK_PROBE` -`DETACH_PROBE` - -This command will move the toolhead to the dock, detach the probe, and return -it to its previous position. If the probe is already detached, the command +This command will move the toolhead to the dock, dock the probe, and return +it to its previous position. If the probe is already docked, the command will do nothing. -This command will call `MOVE_TO_APPROACH_PROBE`, `MOVE_TO_DOCK_PROBE`, -and `MOVE_TO_DETACH_PROBE`. - -### Individual Movements - -These commands are useful during setup to prevent the full attach/detach -sequence from crashing into the bed or damaging the probe/dock. - -If your probe has special setup/teardown steps (e.g. moving a servo), -accommodating that could be accomplished by overriding these gcodes. - -`MOVE_TO_APPROACH_PROBE` - -This command will move the toolhead to the `approach_position`. It can be -overridden to move a servo if that's required for attaching your probe. - -`MOVE_TO_DOCK_PROBE` - -This command will move the toolhead to the `dock_position`. - -`MOVE_TO_EXTRACT_PROBE` - -This command will move the toolhead away from the dock after attaching the probe. -By default it's an alias for `MOVE_TO_APPROACH_PROBE`. - -`MOVE_TO_INSERT_PROBE` - -This command will move the toolhead near the dock before detaching the probe. -By default it's an alias for `MOVE_TO_APPROACH_PROBE`. - -`MOVE_TO_DETACH_PROBE` - -This command will move the toolhead to the `detach_position`. It can be -overridden to move a servo if that's required for detaching your probe. - ### Status `QUERY_DOCKABLE_PROBE` @@ -317,7 +271,7 @@ to confirm probe configuration is working as intended. `SET_DOCKABLE_PROBE AUTO_ATTACH_DETACH=0|1` -Enable/Disable the automatic attaching/detaching of the probe during +Enable/Disable the automatic attaching/docking of the probe during actions that require the probe. This command can be helpful in print-start macros where multiple actions will @@ -330,7 +284,7 @@ G28 ATTACH_PROBE # Explicitly attach the probe QUAD_GANTRY_LEVEL # Tram the gantry parallel to the bed BED_MESH_CALIBRATE # Create a bed mesh -DETACH_PROBE # Manually detach the probe +DOCK_PROBE # Manually detach the probe SET_DOCKABLE_PROBE AUTO_ATTACH_DETACH=1 # Make sure the probe is attached in future ``` @@ -347,21 +301,9 @@ SET_DOCKABLE_PROBE AUTO_ATTACH_DETACH=1 # Make sure the probe is attached in fu - The toolhead position is compared to the dock position. - - If the toolhead is outside of the minimum safe radius, the toolhead is - commanded to move to the approach vector, that is, a position that is - the minimum safe distance from the dock in line with the dock angle. - (MOVE_TO_APPROACH_PROBE) - - - If the toolhead is inside of the minimum safe radius, the toolhead is - commanded to move to the nearest point on the line of the approach vector. - (MOVE_TO_APPROACH_PROBE) - - - The tool is moved along the approach vector to the dock coordinates. - (MOVE_TO_DOCK_PROBE) - - - The toolhead is commanded to move out of the dock back to the minimum - safe distance in the reverse direction along the dock angle. - (MOVE_TO_EXTRACT_PROBE) + - The toolhead will go to the first position of `attach_route` at `travel_speed` + and continue following the given coordinates at `attach_speed`. + (ATTACH_PROBE) - If configured, the probe is checked to see if it is attached. @@ -380,20 +322,9 @@ SET_DOCKABLE_PROBE AUTO_ATTACH_DETACH=1 # Make sure the probe is attached in fu - The toolhead position is compared to the dock position. - - If the toolhead is outside of the minimum safe radius, the toolhead is - commanded to move to the approach vector, that is, a position that is - the minimum safe distance from the dock in line with the dock angle. - (MOVE_TO_APPROACH_PROBE) - - - If the toolhead is inside of the minimum safe radius, the toolhead is - commanded to move to the nearest point on the line of the approach vector. - (MOVE_TO_APPROACH_PROBE) - - - The toolhead is moved along the approach vector to the dock coordinates. - (MOVE_TO_DOCK_PROBE) - - - The toolhead is commanded to move along the detach vector if supplied or a - calculated direction based on axis parameters. (MOVE_TO_DETACH_PROBE) + - The toolhead will go to the first position of `dock_route` at `travel_speed` + and continue following the given coordinates at `dock_speed`. + (DOCK_PROBE) - If configured, the probe is checked to see if it detached. diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 0ad39f529085..f8c3e8da40c4 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -312,20 +312,12 @@ commands are available when a - `ATTACH_PROBE`: Move to dock and attach probe to the toolhead, the toolhead will return to its previous position after attaching. -- `DETACH_PROBE`: Move to dock and detach probe from the toolhead, the toolhead +- `DOCK_PROBE`: Move to dock and detach probe from the toolhead, the toolhead will return to its previous position after detaching. - `QUERY_DOCKABLE_PROBE`: Respond with current probe state. This is useful for verifying configuration settings are working as intended. - `SET_DOCKABLE_PROBE AUTO_ATTACH_DETACH=0|1`: Enable/Disable the automatic attaching/detaching of the probe during actions that require the probe. -- `MOVE_TO_APPROACH_PROBE`: Move to approach the probe dock. -- `MOVE_TO_DOCK_PROBE`: Move to the probe dock (this should trigger the probe - to attach). -- `MOVE_TO_EXTRACT_PROBE`: Move to leave the dock with the probe attached. -- `MOVE_TO_INSERT_PROBE`: Move to insert position near the dock - with the probe attached. -- `MOVE_TO_DETACH_PROBE`: Move away from the dock to disconnect the probe - from the toolhead. ### [dual_carriage] From 48010ed6dce3a80ec559550a2d815d0b8ccb0fb8 Mon Sep 17 00:00:00 2001 From: BillyNate Date: Thu, 14 Sep 2023 12:52:57 +0200 Subject: [PATCH 8/8] Removed some unused config lines --- klippy/extras/dockable_probe.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/klippy/extras/dockable_probe.py b/klippy/extras/dockable_probe.py index 50d5216d59e0..0e5635e335c6 100644 --- a/klippy/extras/dockable_probe.py +++ b/klippy/extras/dockable_probe.py @@ -164,8 +164,6 @@ def __init__(self, config): # Configuration Options self.position_endstop = config.getfloat('z_offset') - self.x_offset = config.getfloat('x_offset', 0.) - self.y_offset = config.getfloat('y_offset', 0.) self.speed = config.getfloat('speed', 5.0, above=0.) self.lift_speed = config.getfloat('lift_speed', self.speed, above=0.) @@ -178,8 +176,6 @@ def __init__(self, config): self.travel_speed, above=0.) self.dock_speed = config.getfloat('dock_speed', self.travel_speed, above=0.) - self.sample_retract_dist = config.getfloat('sample_retract_dist', - 2., above=0.) # Positions (approach, dock, etc) self.z_hop = config.getfloat('z_hop', 0., above=0.)