From e93f077944fb2546a95d73fa4204f3f06b3fc633 Mon Sep 17 00:00:00 2001 From: yochiwarez Date: Thu, 17 Oct 2024 09:02:31 +0100 Subject: [PATCH] axis_twist_compensation: Apply suggestions from review Signed-off-by: Jorge Apaza Merma --- docs/Config_Changes.md | 4 --- docs/G-Codes.md | 4 +-- klippy/extras/axis_twist_compensation.py | 42 +++++++++++------------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/docs/Config_Changes.md b/docs/Config_Changes.md index 8ea9746b63ff..b5212ce19930 100644 --- a/docs/Config_Changes.md +++ b/docs/Config_Changes.md @@ -8,10 +8,6 @@ All dates in this document are approximate. ## Changes -20240709: The `z_compensations` parameter in the `[axis_twist_compensation]` -config section has been renamed to `zx_compensations`. If you don't want -to recalibrate your x_axis_twist_compensation, simply rename the parameter. - 20240415: The `on_error_gcode` parameter in the `[virtual_sdcard]` config section now has a default. If this parameter is not specified it now defaults to `TURN_OFF_HEATERS`. If the previous behavior is diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 29404a370d03..09fbe4c96e78 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -148,9 +148,9 @@ section](Config_Reference.md#axis_twist_compensation) is enabled. #### AXIS_TWIST_COMPENSATION_CALIBRATE `AXIS_TWIST_COMPENSATION_CALIBRATE [SAMPLE_COUNT=] [AXIS=]`: Initiates the X or Y twist calibration wizard. `SAMPLE_COUNT` specifies the number of points along -the X axis to calibrate at and defaults to 3. -`axis` can either be X or Y +the X or Y axis to calibrate at and defaults to 3. +#### AXIS_TWIST_COMPENSATION_AUTOCALIBRATE `AXIS_TWIST_COMPENSATION_AUTOCALIBRATE` performs automatic calibration to calculate the twist of the X and Y axes without manual measurement. ### [bed_mesh] diff --git a/klippy/extras/axis_twist_compensation.py b/klippy/extras/axis_twist_compensation.py index 18012e0a1730..040034b0fc67 100644 --- a/klippy/extras/axis_twist_compensation.py +++ b/klippy/extras/axis_twist_compensation.py @@ -26,7 +26,7 @@ def __init__(self, config): self.calibrate_start_x = config.getfloat('calibrate_start_x') self.calibrate_end_x = config.getfloat('calibrate_end_x') self.calibrate_y = config.getfloat('calibrate_y') - self.zx_compensations = config.getlists('zx_compensations', + self.z_compensations = config.getlists('z_compensations', default=[], parser=float) self.compensation_start_x = config.getfloat('compensation_start_x', default=None) @@ -54,9 +54,9 @@ def __init__(self, config): self._update_z_compensation_value) def _update_z_compensation_value(self, pos): - if self.zx_compensations: + if self.z_compensations: pos[2] += self._get_interpolated_z_compensation( - pos[0], self.zx_compensations, + pos[0], self.z_compensations, self.compensation_start_x, self.compensation_end_x ) @@ -87,7 +87,7 @@ def _get_interpolated_z_compensation( return interpolated_z_compensation def clear_compensations(self): - self.zx_compensations = [] + self.z_compensations = [] self.zy_compensations = [] self.m = None self.b = None @@ -111,8 +111,8 @@ def __init__(self, compensation, config): compensation.calibrate_y) self.x_end_point = (compensation.calibrate_end_x, compensation.calibrate_y) - self.y_start_point = (compensation.calibrate_start_y, - compensation.calibrate_x) + self.y_start_point = (compensation.calibrate_x, + compensation.calibrate_start_y) self.y_end_point = (compensation.calibrate_end_y, compensation.calibrate_x) self.results = None @@ -157,7 +157,7 @@ def cmd_AXIS_TWIST_COMPENSATION_CALIBRATE(self, gcmd): axis = gcmd.get('AXIS', 'X') # check for valid sample_count - if sample_count is None or sample_count < 2: + if sample_count < 2: raise self.gcmd.error( "SAMPLE_COUNT to probe must be at least 2") @@ -182,13 +182,12 @@ def cmd_AXIS_TWIST_COMPENSATION_CALIBRATE(self, gcmd): """ ) - start_point = self.y_start_point + start_point = (self.y_start_point[1], self.y_start_point[0]) end_point = self.y_end_point else: raise self.gcmd.error( "AXIS_TWIST_COMPENSATION_CALIBRATE: " "Invalid axis.") - return axis_range = end_point[0] - start_point[0] @@ -284,6 +283,9 @@ def cmd_AXIS_TWIST_COMPENSATION_AUTOCALIBRATE(self, gcmd): raise self.gcmd.error( "SAMPLE_COUNT to probe must be at least 2") + # verify no other manual probe is in progress + manual_probe.verify_no_manual_probe(self.printer) + # clear the current config self.compensation.clear_compensations() @@ -292,12 +294,12 @@ def cmd_AXIS_TWIST_COMPENSATION_AUTOCALIBRATE(self, gcmd): min_x = self.x_start_point[0] max_x = self.x_end_point[0] - min_y = self.y_start_point[0] + min_y = self.y_start_point[1] max_y = self.y_end_point[0] # calculate x positions - spcx = (max_x - min_x) / (sample_count - 1) - xps = [min_x + spcx * i for i in range(sample_count)] + interval_x = (max_x - min_x) / (sample_count - 1) + xps = [min_x + interval_x * i for i in range(sample_count)] # Calculate points array spcy = (max_y - min_y) / (sample_count - 1) @@ -313,9 +315,6 @@ def cmd_AXIS_TWIST_COMPENSATION_AUTOCALIBRATE(self, gcmd): points.append([xps[i], min_y + spcy * idx ]) flip = not flip - # verify no other manual probe is in progress - manual_probe.verify_no_manual_probe(self.printer) - # calculate the points to put the nozzle at, and probe probe_points = [] @@ -336,7 +335,7 @@ def cmd_AXIS_TWIST_COMPENSATION_AUTOCALIBRATE(self, gcmd): # finalize configfile = self.printer.lookup_object('configfile') - configfile.set(self.configname, 'zx_compensations', x_corr_str) + configfile.set(self.configname, 'z_compensations', x_corr_str) configfile.set(self.configname, 'compensation_start_x', self.x_start_point[0]) configfile.set(self.configname, 'compensation_end_x', @@ -345,7 +344,7 @@ def cmd_AXIS_TWIST_COMPENSATION_AUTOCALIBRATE(self, gcmd): configfile.set(self.configname, 'zy_compensations', y_corr_str) configfile.set(self.configname, 'compensation_start_y', - self.y_start_point[0]) + self.y_start_point[1]) configfile.set(self.configname, 'compensation_end_y', self.y_end_point[0]) @@ -365,7 +364,6 @@ def _auto_calibration(self, probe_point): # probe the point pos = probe.run_single_probe(self.probe, self.gcmd) - #self.current_measured_z = pos[2] # horizontal_move_z (to prevent probe trigger or hitting bed) self._move_helper((None, None, self.horizontal_move_z)) @@ -461,13 +459,13 @@ def _finalize_calibration(self): if(self.current_axis == 'X'): - configfile.set(self.configname, 'zx_compensations', values_as_str) + configfile.set(self.configname, 'z_compensations', values_as_str) configfile.set(self.configname, 'compensation_start_x', self.x_start_point[0]) configfile.set(self.configname, 'compensation_end_x', self.x_end_point[0]) - self.compensation.zx_compensations = self.results + self.compensation.z_compensations = self.results self.compensation.compensation_start_x = self.x_start_point[0] self.compensation.compensation_end_x = self.x_end_point[0] @@ -475,12 +473,12 @@ def _finalize_calibration(self): configfile.set(self.configname, 'zy_compensations', values_as_str) configfile.set(self.configname, 'compensation_start_y', - self.y_start_point[0]) + self.y_start_point[1]) configfile.set(self.configname, 'compensation_end_y', self.y_end_point[0]) self.compensation.zy_compensations = self.results - self.compensation.compensation_start_y = self.y_start_point[0] + self.compensation.compensation_start_y = self.y_start_point[1] self.compensation.compensation_end_y = self.y_end_point[0] self.gcode.respond_info(