Skip to content

Commit be5e548

Browse files
committed
probe: Deprecate last_z_result and add new last_probe_position
Deprecate the PROBE command's exported value `{printer.probe.last_z_result}`. This value effectively returns the toolhead Z position when the probe triggers and user's then need to adjust the result using the probe's configured z_offset. Introduce a new `{printer.probe.last_probe_position}` as a replacement. This replacement has an easier to understand behavior - it states that the probe hardware estimates that if the toolhead is commanded to last_probe_position.x, last_probe_position.y and descends then the tip of the toolhead should first make contact at a Z height of last_probe_position.z . That is, the new exported value already takes into account the probe's configured xyz offsets. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
1 parent 1fb2b27 commit be5e548

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

docs/Config_Changes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ All dates in this document are approximate.
88

99
## Changes
1010

11+
20260109: The status value `{printer.probe.last_z_result}` is
12+
deprecated; it will be removed in the near future. Use
13+
`{printer.probe.last_probe_position}` instead, and note that this new
14+
value already has the probe's configured xyz offsets applied.
15+
1116
20260109: The g-code console text output from the `PROBE`,
1217
`PROBE_ACCURACY`, and similar commands has changed. Now Z heights are
1318
reported relative to the nominal bed Z position instead of relative to

docs/Load_Cell.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,12 @@ macro. This requires setting up
252252
Here is a simple macro that can accomplish this. Note that the
253253
`_HOME_Z_FROM_LAST_PROBE` macro has to be separate because of the way macros
254254
work. The sub-call is needed so that the `_HOME_Z_FROM_LAST_PROBE` macro can
255-
see the result of the probe in `printer.probe.last_z_result`.
255+
see the result of the probe in `printer.probe.last_probe_position`.
256256

257257
```gcode
258258
[gcode_macro _HOME_Z_FROM_LAST_PROBE]
259259
gcode:
260-
{% set z_probed = printer.probe.last_z_result %}
260+
{% set z_probed = printer.probe.last_probe_position.z %}
261261
{% set z_position = printer.toolhead.position[2] %}
262262
{% set z_actual = z_position - z_probed %}
263263
SET_KINEMATIC_POSITION Z={z_actual}

docs/Status_Reference.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,18 @@ is defined):
419419
during the last QUERY_PROBE command. Note, if this is used in a
420420
macro, due to the order of template expansion, the QUERY_PROBE
421421
command must be run prior to the macro containing this reference.
422-
- `last_z_result`: Returns the Z result value of the last PROBE
423-
command. Note, if this is used in a macro, due to the order of
424-
template expansion, the PROBE (or similar) command must be run prior
425-
to the macro containing this reference.
422+
- `last_probe_position`: The results of the last `PROBE` command. This
423+
value is encoded as a [coordinate](#accessing-coordinates). The
424+
probe hardware estimates that if one were to command the toolhead to
425+
XY position `last_probe_position.x`,`last_probe_position.y` and
426+
descend then the tip of the toolhead would first contact the bed at
427+
a Z height of `last_probe_position.z`. These coordinates are
428+
relative to the frame (that is, they use the coordinate system
429+
specified in the config file). Note, if this is used in a macro,
430+
due to the order of template expansion, the `PROBE` command must be
431+
run prior to the macro containing this reference.
432+
- `last_z_result`: This value is deprecated; it will be removed in the
433+
near future.
426434

427435
## pwm_cycle_time
428436

klippy/extras/probe.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def __init__(self, config, probe, query_endstop=None,
4949
gcode.register_command('QUERY_PROBE', self.cmd_QUERY_PROBE,
5050
desc=self.cmd_QUERY_PROBE_help)
5151
# PROBE command
52+
self.last_probe_position = gcode.Coord((0., 0., 0.))
5253
self.last_z_result = 0.
5354
gcode.register_command('PROBE', self.cmd_PROBE,
5455
desc=self.cmd_PROBE_help)
@@ -69,6 +70,7 @@ def _move(self, coord, speed):
6970
def get_status(self, eventtime):
7071
return {'name': self.name,
7172
'last_query': self.last_state,
73+
'last_probe_position': self.last_probe_position,
7274
'last_z_result': self.last_z_result}
7375
cmd_QUERY_PROBE_help = "Return the status of the z-probe"
7476
def cmd_QUERY_PROBE(self, gcmd):
@@ -84,8 +86,11 @@ def cmd_PROBE(self, gcmd):
8486
pos = run_single_probe(self.probe, gcmd)
8587
gcmd.respond_info("Result: at %.3f,%.3f estimate contact at z=%.6f"
8688
% (pos.bed_x, pos.bed_y, pos.bed_z))
89+
gcode = self.printer.lookup_object('gcode')
90+
self.last_probe_position = gcode.Coord((pos.bed_x, pos.bed_y,
91+
pos.bed_z))
8792
x_offset, y_offset, z_offset = self.probe.get_offsets()
88-
self.last_z_result = pos.bed_z + z_offset # XXX
93+
self.last_z_result = pos.bed_z + z_offset # Deprecated
8994
def probe_calibrate_finalize(self, mpresult):
9095
if mpresult is None:
9196
return

0 commit comments

Comments
 (0)