probe: Allow probe parameters to be specified as g-code parameters

Add PROBE_SPEED, SAMPLES, SAMPLE_RETRACT_DIST, SAMPLES_TOLERANCE,
SAMPLES_TOLERANCE_RETRIES, and SAMPLES_RESULT parameters to the PROBE
command (and to commands that indirectly invoke a probe).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-06-21 14:44:28 -04:00
parent c92aca74b5
commit 83e6c01ada
2 changed files with 75 additions and 46 deletions

View File

@ -220,17 +220,26 @@ section is enabled:
The following commands are available when a "probe" config section is The following commands are available when a "probe" config section is
enabled: enabled:
- `PROBE`: Move the nozzle downwards until the probe triggers. - `PROBE [PROBE_SPEED=<mm/s>] [SAMPLES=<count>]
[SAMPLE_RETRACT_DIST=<mm>] [SAMPLES_TOLERANCE=<mm>]
[SAMPLES_TOLERANCE_RETRIES=<count>]
[SAMPLES_RESULT=median|average]`: Move the nozzle downwards until
the probe triggers. If any of the optional parameters are provided
they override their equivalent setting in the probe config section
(see
[example-extras.cfg](https://github.com/KevinOConnor/klipper/tree/master/config/example-extras.cfg)
for details).
- `QUERY_PROBE`: Report the current status of the probe ("triggered" - `QUERY_PROBE`: Report the current status of the probe ("triggered"
or "open"). or "open").
- `PROBE_ACCURACY [REPEAT=<times>] [SPEED=<speed mm/s>] [X=<x pos>] - `PROBE_ACCURACY [REPEAT=<times>] [SPEED=<speed mm/s>] [X=<x pos>]
[Y=<y pos>] [Z=<z height>]`: Calculate the maximum, minimum, average, [Y=<y pos>] [Z=<z height>]`: Calculate the maximum, minimum, average,
median and standard deviation. The default values are: REPEAT=10, median and standard deviation. The default values are: REPEAT=10,
SPEED=probe config speed, X=current X, Y=current Y and Z=10. SPEED=probe config speed, X=current X, Y=current Y and Z=10.
- `PROBE_CALIBRATE [SPEED=<speed>]`: Run a helper script useful for - `PROBE_CALIBRATE [SPEED=<speed>] [<probe_parameter>=<value>]`: Run a
calibrating the probe's z_offset. See the MANUAL_PROBE command for helper script useful for calibrating the probe's z_offset. See the
details on the parameters and the additional commands available PROBE command for details on the optional probe parameters. See the
while the tool is active. MANUAL_PROBE command for details on the SPEED parameter and the
additional commands available while the tool is active.
## BLTouch ## BLTouch
@ -246,12 +255,13 @@ See [Working with the BL-Touch](BLTouch.md) for more details.
The following commands are available when the "delta_calibrate" config The following commands are available when the "delta_calibrate" config
section is enabled: section is enabled:
- `DELTA_CALIBRATE [METHOD=manual]`: This command will probe seven - `DELTA_CALIBRATE [METHOD=manual] [<probe_parameter>=<value>]`: This
points on the bed and recommend updated endstop positions, tower command will probe seven points on the bed and recommend updated
angles, and radius. If METHOD=manual is specified then the manual endstop positions, tower angles, and radius. See the PROBE command
probing tool is activated - see the MANUAL_PROBE command above for for details on the optional probe parameters. If METHOD=manual is
details on the additional commands available while this tool is specified then the manual probing tool is activated - see the
active. MANUAL_PROBE command above for details on the additional commands
available while this tool is active.
- `DELTA_ANALYZE`: This command is used during enhanced delta - `DELTA_ANALYZE`: This command is used during enhanced delta
calibration. See [Delta Calibrate](Delta_Calibrate.md) for details. calibration. See [Delta Calibrate](Delta_Calibrate.md) for details.
@ -259,24 +269,26 @@ section is enabled:
The following commands are available when the "bed_tilt" config The following commands are available when the "bed_tilt" config
section is enabled: section is enabled:
- `BED_TILT_CALIBRATE [METHOD=manual]`: This command will probe the - `BED_TILT_CALIBRATE [METHOD=manual] [<probe_parameter>=<value>]`:
points specified in the config and then recommend updated x and y This command will probe the points specified in the config and then
tilt adjustments. If METHOD=manual is specified then the manual recommend updated x and y tilt adjustments. See the PROBE command
probing tool is activated - see the MANUAL_PROBE command above for for details on the optional probe parameters. If METHOD=manual is
details on the additional commands available while this tool is specified then the manual probing tool is activated - see the
active. MANUAL_PROBE command above for details on the additional commands
available while this tool is active.
## Mesh Bed Leveling ## Mesh Bed Leveling
The following commands are available when the "bed_mesh" config The following commands are available when the "bed_mesh" config
section is enabled: section is enabled:
- `BED_MESH_CALIBRATE [METHOD=manual]`: This command probes the bed - `BED_MESH_CALIBRATE [METHOD=manual] [<probe_parameter>=<value>]`:
using generated points specified by the parameters in the This command probes the bed using generated points specified by the
config. After probing, a mesh is generated and z-movement is parameters in the config. After probing, a mesh is generated and
adjusted according to the mesh. If METHOD=manual is specified then z-movement is adjusted according to the mesh. See the PROBE command
the manual probing tool is activated - see the MANUAL_PROBE command for details on the optional probe parameters. If METHOD=manual is
above for details on the additional commands available while this specified then the manual probing tool is activated - see the
tool is active. MANUAL_PROBE command above for details on the additional commands
available while this tool is active.
- `BED_MESH_OUTPUT`: This command outputs the current probed z values - `BED_MESH_OUTPUT`: This command outputs the current probed z values
and current mesh values to the terminal. and current mesh values to the terminal.
- `BED_MESH_MAP`: This command probes the bed in a similar fashion - `BED_MESH_MAP`: This command probes the bed in a similar fashion
@ -311,19 +323,22 @@ section is enabled:
The following commands are available when the "screws_tilt_adjust" The following commands are available when the "screws_tilt_adjust"
config section is enabled: config section is enabled:
- `SCREWS_TILT_CALCULATE`: This command will invoke the bed screws - `SCREWS_TILT_CALCULATE [<probe_parameter>=<value>]`: This command
adjustment tool. It will command the nozzle to different locations will invoke the bed screws adjustment tool. It will command the
(as defined in the config file) probing the z height and calculate nozzle to different locations (as defined in the config file)
the number of knob turns to adjust the bed level. probing the z height and calculate the number of knob turns to
adjust the bed level. See the PROBE command for details on the
optional probe parameters.
IMPORTANT: You MUST always do a G28 before using this command. IMPORTANT: You MUST always do a G28 before using this command.
## Z Tilt ## Z Tilt
The following commands are available when the "z_tilt" config section The following commands are available when the "z_tilt" config section
is enabled: is enabled:
- `Z_TILT_ADJUST`: This command will probe the points specified in the - `Z_TILT_ADJUST [<probe_parameter>=<value>]`: This command will probe
config and then make independent adjustments to each Z stepper to the points specified in the config and then make independent
compensate for tilt. adjustments to each Z stepper to compensate for tilt. See the PROBE
command for details on the optional probe parameters.
## Dual Carriages ## Dual Carriages

View File

@ -30,14 +30,16 @@ class PrinterProbe:
pconfig = config.getsection('printer') pconfig = config.getsection('printer')
self.z_position = pconfig.getfloat('minimum_z_position', 0.) self.z_position = pconfig.getfloat('minimum_z_position', 0.)
# Multi-sample support (for improved accuracy) # Multi-sample support (for improved accuracy)
self.samples = config.getint('samples', 1, minval=1) self.sample_count = config.getint('samples', 1, minval=1)
self.sample_retract_dist = config.getfloat('sample_retract_dist', 2., self.sample_retract_dist = config.getfloat('sample_retract_dist', 2.,
above=0.) above=0.)
atypes = {'median': 'median', 'average': 'average'} atypes = {'median': 'median', 'average': 'average'}
self.samples_result = config.getchoice('samples_result', atypes, self.samples_result = config.getchoice('samples_result', atypes,
'average') 'average')
self.samples_tolerance = config.getfloat('samples_tolerance', 0.100) self.samples_tolerance = config.getfloat('samples_tolerance', 0.100,
self.samples_retries = config.getint('samples_tolerance_retries', 0) minval=0.)
self.samples_retries = config.getint('samples_tolerance_retries', 0,
minval=0)
# Register z_virtual_endstop pin # Register z_virtual_endstop pin
self.printer.lookup_object('pins').register_chip('probe', self) self.printer.lookup_object('pins').register_chip('probe', self)
# Register PROBE/QUERY_PROBE commands # Register PROBE/QUERY_PROBE commands
@ -98,17 +100,29 @@ class PrinterProbe:
return z_sorted[middle] return z_sorted[middle]
# even number of samples # even number of samples
return self._calc_mean(z_sorted[middle-1:middle+1]) return self._calc_mean(z_sorted[middle-1:middle+1])
def run_probe(self): def run_probe(self, params={}):
speed = self.gcode.get_float(
"PROBE_SPEED", params, self.speed, above=0.)
sample_count = self.gcode.get_int(
"SAMPLES", params, self.sample_count, minval=1)
sample_retract_dist = self.gcode.get_float(
"SAMPLE_RETRACT_DIST", params, self.sample_retract_dist, above=0.)
samples_tolerance = self.gcode.get_float(
"SAMPLES_TOLERANCE", params, self.samples_tolerance, minval=0.)
samples_retries = self.gcode.get_int(
"SAMPLES_TOLERANCE_RETRIES", params, self.samples_retries, minval=0)
samples_result = self.gcode.get_str(
"SAMPLES_RESULT", params, self.samples_result)
retries = 0 retries = 0
positions = [] positions = []
while len(positions) < self.samples: while len(positions) < sample_count:
# Probe position # Probe position
pos = self._probe(self.speed) pos = self._probe(speed)
positions.append(pos) positions.append(pos)
# Check samples tolerance # Check samples tolerance
z_positions = [p[2] for p in positions] z_positions = [p[2] for p in positions]
if max(z_positions) - min(z_positions) > self.samples_tolerance: if max(z_positions) - min(z_positions) > samples_tolerance:
if retries >= self.samples_retries: if retries >= samples_retries:
raise homing.CommandError( raise homing.CommandError(
"Probe samples exceed samples_tolerance") "Probe samples exceed samples_tolerance")
self.gcode.respond_info( self.gcode.respond_info(
@ -116,16 +130,16 @@ class PrinterProbe:
retries += 1 retries += 1
positions = [] positions = []
# Retract # Retract
if len(positions) < self.samples: if len(positions) < sample_count:
liftpos = [None, None, pos[2] + self.sample_retract_dist] liftpos = [None, None, pos[2] + sample_retract_dist]
self._move(liftpos, self.speed) self._move(liftpos, speed)
# Calculate and return result # Calculate and return result
if self.samples_result == 'median': if samples_result == 'median':
return self._calc_median(positions) return self._calc_median(positions)
return self._calc_mean(positions) return self._calc_mean(positions)
cmd_PROBE_help = "Probe Z-height at current XY position" cmd_PROBE_help = "Probe Z-height at current XY position"
def cmd_PROBE(self, params): def cmd_PROBE(self, params):
pos = self.run_probe() pos = self.run_probe(params)
self.gcode.respond_info("Result is z=%.6f" % (pos[2],)) self.gcode.respond_info("Result is z=%.6f" % (pos[2],))
cmd_QUERY_PROBE_help = "Return the status of the z-probe" cmd_QUERY_PROBE_help = "Return the status of the z-probe"
def cmd_QUERY_PROBE(self, params): def cmd_QUERY_PROBE(self, params):
@ -192,7 +206,7 @@ class PrinterProbe:
def cmd_PROBE_CALIBRATE(self, params): def cmd_PROBE_CALIBRATE(self, params):
manual_probe.verify_no_manual_probe(self.printer) manual_probe.verify_no_manual_probe(self.printer)
# Perform initial probe # Perform initial probe
curpos = self.run_probe() curpos = self.run_probe(params)
# Move away from the bed # Move away from the bed
self.probe_calibrate_z = curpos[2] self.probe_calibrate_z = curpos[2]
curpos[2] += 5. curpos[2] += 5.
@ -331,7 +345,7 @@ class ProbePointsHelper:
done = self._move_next() done = self._move_next()
if done: if done:
break break
pos = probe.run_probe() pos = probe.run_probe(params)
self.results.append(pos) self.results.append(pos)
def _manual_probe_start(self): def _manual_probe_start(self):
done = self._move_next() done = self._move_next()