From 364c22fe8472cac712b6ada06a0a967df98e636a Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 10 Jul 2019 15:11:11 -0400 Subject: [PATCH] probe: Rework the PROBE_ACCURACY command parameters Don't default to a Z location of 10, as that could cause damage if the probe's z_offset is greater than 10. Instead, use the "retract distance" method that is used for normal multi-sample probing. Update the PROBE_ACCURACY command parameter names to use the same parameter names as the PROBE command. Signed-off-by: Kevin O'Connor --- docs/Config_Changes.md | 4 ++++ docs/G-Codes.md | 10 ++++++---- klippy/extras/probe.py | 42 ++++++++++++++++++------------------------ 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/docs/Config_Changes.md b/docs/Config_Changes.md index 40060205..6ba35289 100644 --- a/docs/Config_Changes.md +++ b/docs/Config_Changes.md @@ -6,6 +6,10 @@ All dates in this document are approximate. # Changes +20190710: The optional parameters of the PROBE_ACCURACY command have +changed. It may be necessary to update any macros or scripts that use +that command. + 20190628: All configuration options have been removed from the [skew_correction] section. Configuration for skew_correction is now done via the SET_SKEW gcode. See skew_correction.md diff --git a/docs/G-Codes.md b/docs/G-Codes.md index f38c1a28..b995fa1c 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -231,10 +231,12 @@ enabled: 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_ACCURACY [PROBE_SPEED=] [SAMPLES=] + [SAMPLE_RETRACT_DIST=]`: Calculate the maximum, minimum, + average, median, and standard deviation of multiple probe + samples. By default, 10 SAMPLES are taken. Otherwise the optional + parameters default to their equivalent setting in the probe config + section. - `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 diff --git a/klippy/extras/probe.py b/klippy/extras/probe.py index a6c71428..a13d4098 100644 --- a/klippy/extras/probe.py +++ b/klippy/extras/probe.py @@ -150,32 +150,26 @@ class PrinterProbe: "probe: %s" % (["open", "TRIGGERED"][not not res],)) cmd_PROBE_ACCURACY_help = "Probe Z-height accuracy at current XY position" def cmd_PROBE_ACCURACY(self, params): + speed = self.gcode.get_float( + "PROBE_SPEED", params, self.speed, above=0.) + sample_count = self.gcode.get_int("SAMPLES", params, 10, minval=1) + sample_retract_dist = self.gcode.get_float( + "SAMPLE_RETRACT_DIST", params, self.sample_retract_dist, above=0.) toolhead = self.printer.lookup_object('toolhead') pos = toolhead.get_position() - number_of_reads = self.gcode.get_int('REPEAT', params, default=10, - minval=4, maxval=50) - speed = self.gcode.get_int('SPEED', params, default=self.speed, - minval=1, maxval=30) - z_start_position = self.gcode.get_float( - 'Z', params, default=10., minval=self.z_offset, maxval=70.) - x_start_position = self.gcode.get_float('X', params, default=pos[0]) - y_start_position = self.gcode.get_float('Y', params, default=pos[1]) - start_pos = [x_start_position, y_start_position, z_start_position] - self.gcode.respond_info("probe accuracy: at X:%.3f Y:%.3f Z:%.3f\n" - " " - "and read %d times with speed of %d mm/s" % ( - x_start_position, y_start_position, - z_start_position, number_of_reads, speed)) - # Probe bed "number_of_reads" times + self.gcode.respond_info("PROBE_ACCURACY at X:%.3f Y:%.3f Z:%.3f" + " (samples=%d retract=%.3f speed=%.1f\n" + % (pos[0], pos[1], pos[2], + sample_count, sample_retract_dist, speed)) + # Probe bed sample_count times positions = [] - for i in range(number_of_reads): - # Move Z to start reading position - self._move(start_pos, speed) - # Probe + while len(positions) < sample_count: + # Probe position pos = self._probe(speed) positions.append(pos) - # Move Z to start reading position - self._move(start_pos, speed) + # Retract + liftpos = [None, None, pos[2] + sample_retract_dist] + self._move(liftpos, speed) # Calculate maximum, minimum and average values max_value = max([p[2] for p in positions]) min_value = min([p[2] for p in positions]) @@ -183,9 +177,9 @@ class PrinterProbe: median = self._calc_median(positions)[2] # calculate the standard deviation deviation_sum = 0 - for i in range(number_of_reads): - deviation_sum += pow(positions[i][2] - avg_value, 2) - sigma = (deviation_sum / number_of_reads) ** 0.5 + for i in range(len(positions)): + deviation_sum += pow(positions[i][2] - avg_value, 2.) + sigma = (deviation_sum / len(positions)) ** 0.5 # Show information self.gcode.respond_info( "probe accuracy results: maximum %.6f, minimum %.6f, "