diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 5d06a4a1..3fcdd88e 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -220,17 +220,26 @@ section is enabled: The following commands are available when a "probe" config section is enabled: -- `PROBE`: Move the nozzle downwards until the probe triggers. +- `PROBE [PROBE_SPEED=] [SAMPLES=] + [SAMPLE_RETRACT_DIST=] [SAMPLES_TOLERANCE=] + [SAMPLES_TOLERANCE_RETRIES=] + [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" or "open"). - `PROBE_ACCURACY [REPEAT=] [SPEED=] [X=] [Y=] [Z=]`: Calculate the maximum, minimum, average, median and standard deviation. The default values are: REPEAT=10, SPEED=probe config speed, X=current X, Y=current Y and Z=10. -- `PROBE_CALIBRATE [SPEED=]`: Run a helper script useful for - calibrating the probe's z_offset. See the MANUAL_PROBE command for - details on the parameters and the additional commands available - while the tool is active. +- `PROBE_CALIBRATE [SPEED=] [=]`: Run a + helper script useful for calibrating the probe's z_offset. See the + PROBE command for details on the optional probe parameters. See the + MANUAL_PROBE command for details on the SPEED parameter and the + additional commands available while the tool is active. ## 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 section is enabled: -- `DELTA_CALIBRATE [METHOD=manual]`: This command will probe seven - points on the bed and recommend updated endstop positions, tower - angles, and radius. If METHOD=manual is specified then the manual - probing tool is activated - see the MANUAL_PROBE command above for - details on the additional commands available while this tool is - active. +- `DELTA_CALIBRATE [METHOD=manual] [=]`: This + command will probe seven points on the bed and recommend updated + endstop positions, tower angles, and radius. See the PROBE command + for details on the optional probe parameters. If METHOD=manual is + specified then the manual probing tool is activated - see the + 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 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 section is enabled: -- `BED_TILT_CALIBRATE [METHOD=manual]`: This command will probe the - points specified in the config and then recommend updated x and y - tilt adjustments. If METHOD=manual is specified then the manual - probing tool is activated - see the MANUAL_PROBE command above for - details on the additional commands available while this tool is - active. +- `BED_TILT_CALIBRATE [METHOD=manual] [=]`: + This command will probe the points specified in the config and then + recommend updated x and y tilt adjustments. See the PROBE command + for details on the optional probe parameters. If METHOD=manual is + specified then the manual probing tool is activated - see the + MANUAL_PROBE command above for details on the additional commands + available while this tool is active. ## Mesh Bed Leveling The following commands are available when the "bed_mesh" config section is enabled: -- `BED_MESH_CALIBRATE [METHOD=manual]`: This command probes the bed - using generated points specified by the parameters in the - config. After probing, a mesh is generated and z-movement is - adjusted according to the mesh. If METHOD=manual is specified then - the manual probing tool is activated - see the MANUAL_PROBE command - above for details on the additional commands available while this - tool is active. +- `BED_MESH_CALIBRATE [METHOD=manual] [=]`: + This command probes the bed using generated points specified by the + parameters in the config. After probing, a mesh is generated and + z-movement is adjusted according to the mesh. See the PROBE command + for details on the optional probe parameters. If METHOD=manual is + specified then the manual probing tool is activated - see the + 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 and current mesh values to the terminal. - `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" config section is enabled: -- `SCREWS_TILT_CALCULATE`: This command will invoke the bed screws - adjustment tool. It will command the nozzle to different locations - (as defined in the config file) probing the z height and calculate - the number of knob turns to adjust the bed level. +- `SCREWS_TILT_CALCULATE [=]`: This command + will invoke the bed screws adjustment tool. It will command the + nozzle to different locations (as defined in the config file) + 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. ## Z Tilt The following commands are available when the "z_tilt" config section is enabled: -- `Z_TILT_ADJUST`: This command will probe the points specified in the - config and then make independent adjustments to each Z stepper to - compensate for tilt. +- `Z_TILT_ADJUST [=]`: This command will probe + the points specified in the config and then make independent + adjustments to each Z stepper to compensate for tilt. See the PROBE + command for details on the optional probe parameters. ## Dual Carriages diff --git a/klippy/extras/probe.py b/klippy/extras/probe.py index ccf32a74..92f0528c 100644 --- a/klippy/extras/probe.py +++ b/klippy/extras/probe.py @@ -30,14 +30,16 @@ class PrinterProbe: pconfig = config.getsection('printer') self.z_position = pconfig.getfloat('minimum_z_position', 0.) # 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., above=0.) atypes = {'median': 'median', 'average': 'average'} self.samples_result = config.getchoice('samples_result', atypes, 'average') - self.samples_tolerance = config.getfloat('samples_tolerance', 0.100) - self.samples_retries = config.getint('samples_tolerance_retries', 0) + self.samples_tolerance = config.getfloat('samples_tolerance', 0.100, + minval=0.) + self.samples_retries = config.getint('samples_tolerance_retries', 0, + minval=0) # Register z_virtual_endstop pin self.printer.lookup_object('pins').register_chip('probe', self) # Register PROBE/QUERY_PROBE commands @@ -98,17 +100,29 @@ class PrinterProbe: return z_sorted[middle] # even number of samples 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 positions = [] - while len(positions) < self.samples: + while len(positions) < sample_count: # Probe position - pos = self._probe(self.speed) + pos = self._probe(speed) positions.append(pos) # Check samples tolerance z_positions = [p[2] for p in positions] - if max(z_positions) - min(z_positions) > self.samples_tolerance: - if retries >= self.samples_retries: + if max(z_positions) - min(z_positions) > samples_tolerance: + if retries >= samples_retries: raise homing.CommandError( "Probe samples exceed samples_tolerance") self.gcode.respond_info( @@ -116,16 +130,16 @@ class PrinterProbe: retries += 1 positions = [] # Retract - if len(positions) < self.samples: - liftpos = [None, None, pos[2] + self.sample_retract_dist] - self._move(liftpos, self.speed) + if len(positions) < sample_count: + liftpos = [None, None, pos[2] + sample_retract_dist] + self._move(liftpos, speed) # Calculate and return result - if self.samples_result == 'median': + if samples_result == 'median': return self._calc_median(positions) return self._calc_mean(positions) cmd_PROBE_help = "Probe Z-height at current XY position" def cmd_PROBE(self, params): - pos = self.run_probe() + pos = self.run_probe(params) self.gcode.respond_info("Result is z=%.6f" % (pos[2],)) cmd_QUERY_PROBE_help = "Return the status of the z-probe" def cmd_QUERY_PROBE(self, params): @@ -192,7 +206,7 @@ class PrinterProbe: def cmd_PROBE_CALIBRATE(self, params): manual_probe.verify_no_manual_probe(self.printer) # Perform initial probe - curpos = self.run_probe() + curpos = self.run_probe(params) # Move away from the bed self.probe_calibrate_z = curpos[2] curpos[2] += 5. @@ -331,7 +345,7 @@ class ProbePointsHelper: done = self._move_next() if done: break - pos = probe.run_probe() + pos = probe.run_probe(params) self.results.append(pos) def _manual_probe_start(self): done = self._move_next()