Skip to content

Commit

Permalink
Merge branch 'master' into upstream_pr
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerlz committed Apr 23, 2024
2 parents c3cd269 + 7884129 commit 3f3d378
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 25 deletions.
16 changes: 16 additions & 0 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2218,12 +2218,28 @@ detach_position: 0,0,0
# If Z is specified the toolhead will move to the Z location before the X, Y
# coordinates.
# This parameter is required.
#extract_position: 0,0,0
# Similar to the approach_position, the extract_position is the coordinates
# where the toolhead is moved to extract the probe from the dock.
# If Z is specified the toolhead will move to the Z location before the X, Y
# coordinates.
# The default value is approach_probe value.
#insert_position: 0,0,0
# Similar to the extract_position, the insert_position is the coordinates
# where the toolhead is moved before inserting the probe into the dock.
# If Z is specified the toolhead will move to the Z location before the X, Y
# coordinates.
# The default value is extract_probe value.
#z_hop: 15.0
# Distance (in mm) to lift the Z axis prior to attaching/detaching 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`.
# The default is to not implement Z hop.
#restore_toolhead: True
# While True, the position of the toolhead is restored to the position prior
# to the attach/detach movements.
# The default value is True.
#dock_retries:
# The number of times to attempt to attach/dock the probe before raising
# an error and aborting probing.
Expand Down
36 changes: 19 additions & 17 deletions docs/Dockable_Probe.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ detach_position:
away from the probe dock such that the magnets on the probe body are not
attracted to the magnets on the toolhead.

- `extract_position: 295, 250, 0`\
_Default Value: approach\_position_\
Euclid probe requires the toolhead to move to a different direction to extract
or dock mag_probe.

- `insert_position: 295, 250, 0`\
_Default Value: extract\_position_\
Usually the same as extract position for Euclid probe when the dock is on the
gantry.

- `z_hop: 15.0`\
_Default Value: None_\
Distance (in mm) to lift the Z axis prior to attaching/detaching the probe.
Expand All @@ -81,6 +91,11 @@ detach_position:
the Z axis is not already homed the head is lifted by `z_hop`.
The default is to not implement Z hop.

- `restore_toolhead: False|True`\
_Default Value: True_\
While True, the position of the toolhead is restored to the position prior to
the attach/detach movements.

## Position Examples

Probe mounted on frame at back of print bed at a fixed Z position. To attach
Expand Down Expand Up @@ -145,9 +160,7 @@ 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.
detach positions are the same, as are the extract and insert positions.

```
Attach:
Expand All @@ -167,20 +180,11 @@ Detach:
```
approach_position: 50, 150
dock_position: 10, 150
extract_position: 10, 130
detach_position: 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
Expand Down Expand Up @@ -294,13 +298,11 @@ 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`.
This command will move the toolhead to the `extract_position`.

`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`.
This command will move the toolhead to the `insert_position`.

`MOVE_TO_DETACH_PROBE`

Expand Down
49 changes: 41 additions & 8 deletions klippy/extras/dockable_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
Please see {0}.md and config_Reference.md.
"""


# Helper class to handle polling pins for probe attachment states
class PinPollingHelper:
def __init__(self, config, endstop):
Expand Down Expand Up @@ -167,6 +168,7 @@ def __init__(self, config):
self.lift_speed = config.getfloat("lift_speed", self.speed, above=0.0)
self.dock_retries = config.getint("dock_retries", 0)
self.auto_attach_detach = config.getboolean("auto_attach_detach", True)
self.restore_toolhead = config.getboolean("restore_toolhead", True)
self.travel_speed = config.getfloat(
"travel_speed", self.speed, above=0.0
)
Expand All @@ -183,6 +185,12 @@ def __init__(self, config):
# Positions (approach, detach, etc)
self.approach_position = self._parse_coord(config, "approach_position")
self.detach_position = self._parse_coord(config, "detach_position")
self.extract_position = self._parse_coord(
config, "extract_position", self.approach_position
)
self.insert_position = self._parse_coord(
config, "insert_position", self.extract_position
)
self.dock_position = self._parse_coord(config, "dock_position")
self.z_hop = config.getfloat("z_hop", 0.0, above=0.0)

Expand All @@ -195,7 +203,7 @@ def __init__(self, config):
self.dock_position, self.approach_position
)
self.detach_angle, self.detach_distance = self._get_vector(
self.dock_position, self.detach_position
self.dock_position, self.insert_position
)

# Pins
Expand Down Expand Up @@ -290,11 +298,14 @@ def __init__(self, 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)
def _parse_coord(self, config, name, default=None, expected_dims=3):
if default:
val = config.get(name, None)
else:
val = config.get(name)
error_msg = "Unable to parse {0} in {1}: {2}"
if not val:
return None
return default
try:
vals = [float(x.strip()) for x in val.split(",")]
except Exception as e:
Expand Down Expand Up @@ -338,6 +349,7 @@ def get_status(self, curtime):
# Use last_'status' here to be consistent with QUERY_PROBE_'STATUS'.
return {
"last_status": self.last_probe_state,
"auto_attach_detach": self.auto_attach_detach,
}

cmd_MOVE_TO_APPROACH_PROBE_help = (
Expand Down Expand Up @@ -382,14 +394,35 @@ def cmd_MOVE_TO_DOCK_PROBE(self, gcmd):
)

def cmd_MOVE_TO_EXTRACT_PROBE(self, gcmd):
self.cmd_MOVE_TO_APPROACH_PROBE(gcmd)
if len(self.extract_position) > 2:
self.toolhead.manual_move(
[None, None, self.extract_position[2]], self.attach_speed
)

self.toolhead.manual_move(
[self.extract_position[0], self.extract_position[1], None],
self.attach_speed,
)

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)
if self._check_distance(dist=self.detach_distance):
self._align_to_vector(self.detach_angle)
else:
self._move_to_vector(self.detach_angle)

if len(self.insert_position) > 2:
self.toolhead.manual_move(
[None, None, self.insert_position[2]], self.travel_speed
)

self.toolhead.manual_move(
[self.insert_position[0], self.insert_position[1], None],
self.travel_speed,
)

cmd_MOVE_TO_DETACH_PROBE_help = (
"Move away from the dock to detach" "the probe"
Expand Down Expand Up @@ -461,7 +494,7 @@ def attach_probe(self, return_pos=None):
if self.get_probe_state() != PROBE_ATTACHED:
raise self.printer.command_error("Probe attach failed!")

if return_pos:
if return_pos and self.restore_toolhead:
if not self._check_distance(return_pos, self.approach_distance):
self.toolhead.manual_move(
[return_pos[0], return_pos[1], None], self.travel_speed
Expand Down Expand Up @@ -492,7 +525,7 @@ def detach_probe(self, return_pos=None):
if self.get_probe_state() != PROBE_DOCKED:
raise self.printer.command_error("Probe detach failed!")

if return_pos:
if return_pos and self.restore_toolhead:
if not self._check_distance(return_pos, self.detach_distance):
self.toolhead.manual_move(
[return_pos[0], return_pos[1], None], self.travel_speed
Expand Down
3 changes: 3 additions & 0 deletions test/klippy/dockable_probe.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ max_z_accel: 100
dock_position: 100, 100
approach_position: 150, 150
detach_position: 120, 120
extract_position: 140, 140
insert_position: 130, 130
pin: PH6
z_offset: 1.15
check_open_attach: false
restore_toolhead: true

0 comments on commit 3f3d378

Please sign in to comment.