From f2fbe984547c5291ee4cd9df40d4ee0f36ed1fbb Mon Sep 17 00:00:00 2001 From: Matt Baker Date: Thu, 21 Mar 2019 07:39:22 -0700 Subject: [PATCH] bed_mesh: enable relative offset bed meshes (#1323) Adds parameter for bed meshes to be adjusted relative to a probed point during calibration. This allows the probe z offset to be ignored for probes that are not stable over time (for example, the thermal drift of inductive probes). An endstop other than the probe is then necessary to determine the bed-nozzle offset. Signed-off-by: Matt Baker --- config/example-extras.cfg | 4 ++++ klippy/extras/bed_mesh.py | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/config/example-extras.cfg b/config/example-extras.cfg index 14a02d08..d002c922 100644 --- a/config/example-extras.cfg +++ b/config/example-extras.cfg @@ -226,6 +226,10 @@ # may be applied to change the amount of slope interpolated. # Larger numbers will increase the amount of slope, which # results in more curvature in the mesh. Default is .2. +#relative_reference_index: +# A point index in the mesh to reference all z values to. Enabling +# this parameter produces a mesh relative to the probed z position +# at the provided index. # Tool to help adjust bed leveling screws. One may define a diff --git a/klippy/extras/bed_mesh.py b/klippy/extras/bed_mesh.py index 506d5aa1..ec2b88ad 100644 --- a/klippy/extras/bed_mesh.py +++ b/klippy/extras/bed_mesh.py @@ -186,6 +186,7 @@ class BedMeshCalibrate: self.printer = config.get_printer() self.name = config.get_name() self.radius = None + self.relative_reference_index = None self.bedmesh = bedmesh self.probed_z_table = None self.build_map = False @@ -267,8 +268,17 @@ class BedMeshCalibrate: points.append((pos_x, pos_y)) pos_y += y_dist logging.info('bed_mesh: generated points') - for p in points: - logging.info("(%.1f, %.1f)" % (p[0], p[1])) + for i, p in enumerate(points): + logging.info("%d: (%.1f, %.1f)" % (i, p[0], p[1])) + rref_index = config.get('relative_reference_index', None) + if rref_index is not None: + rref_index = int(rref_index) + if rref_index < 0 or rref_index >= len(points): + raise config.error("bed_mesh: relative reference index %d " + "is out of bounds" % (rref_index)) + logging.info("bed_mesh: relative_reference_index %d is (%.2f, %.2f)" + % (rref_index, points[rref_index][0], points[rref_index][1])) + self.relative_reference_index = rref_index return points def _init_probe_params(self, config, points): self.probe_params['min_x'] = min(points, key=lambda p: p[0])[0] @@ -411,6 +421,11 @@ class BedMeshCalibrate: x_cnt = self.probe_params['x_count'] y_cnt = self.probe_params['y_count'] + if self.relative_reference_index is not None: + # zero out probe z offset and + # set offset relative to reference index + z_offset = positions[self.relative_reference_index][2] + self.probed_z_table = [] row = [] prev_pos = positions[0]