From 4dfe01a2cd619143e2e39ad6b46e66a4dc62e0b8 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Thu, 3 Jun 2021 18:14:44 -0400 Subject: [PATCH] bed_mesh: move the "fade offset" out of the ZMesh This is a temporary offset applied to the mesh used to fade toward a "target". For clarity, apply the fade offset when the final z calculation is made. SIgned-off-by: Eric Callahan --- klippy/extras/bed_mesh.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/klippy/extras/bed_mesh.py b/klippy/extras/bed_mesh.py index 11a8a748..4a2a3b61 100644 --- a/klippy/extras/bed_mesh.py +++ b/klippy/extras/bed_mesh.py @@ -118,8 +118,6 @@ class BedMesh: "bed_mesh: ERROR, fade_target lies outside of mesh z " "range\nmin: %.4f, max: %.4f, fade_target: %.4f" % (min_z, max_z, err_target)) - if self.fade_target: - mesh.offset_mesh(self.fade_target) min_z, max_z = mesh.get_z_range() if self.fade_dist <= max(abs(min_z), abs(max_z)): self.z_mesh = None @@ -132,7 +130,7 @@ class BedMesh: else: self.fade_target = 0. self.z_mesh = mesh - self.splitter.initialize(mesh) + self.splitter.initialize(mesh, self.fade_target) # cache the current position before a transform takes place gcode_move = self.printer.lookup_object('gcode_move') gcode_move.reset_last_position() @@ -152,9 +150,9 @@ class BedMesh: else: # return current position minus the current z-adjustment x, y, z, e = self.toolhead.get_position() - z_adj = self.z_mesh.calc_z(x, y) + max_adj = self.z_mesh.calc_z(x, y) factor = 1. - max_adj = z_adj + self.fade_target + z_adj = max_adj - self.fade_target if min(z, (z - max_adj)) >= self.fade_end: # Fade out is complete, no factor factor = 0. @@ -707,9 +705,11 @@ class MoveSplitter: self.move_check_distance = config.getfloat( 'move_check_distance', 5., minval=3.) self.z_mesh = None + self.fade_offset = 0. self.gcode = gcode - def initialize(self, mesh): + def initialize(self, mesh, fade_offset): self.z_mesh = mesh + self.fade_offset = fade_offset def build_move(self, prev_pos, next_pos, factor): self.prev_pos = tuple(prev_pos) self.next_pos = tuple(next_pos) @@ -723,7 +723,8 @@ class MoveSplitter: self.axis_move = [not isclose(d, 0., abs_tol=1e-10) for d in axes_d] def _calc_z_offset(self, pos): z = self.z_mesh.calc_z(pos[0], pos[1]) - return self.z_factor * z + self.z_mesh.mesh_offset + offset = self.fade_offset + return self.z_factor * (z - offset) + offset def _set_next_move(self, distance_from_prev): t = distance_from_prev / self.total_move_length if t > 1. or t < 0.: @@ -766,7 +767,6 @@ class ZMesh: self.probed_matrix = self.mesh_matrix = None self.mesh_params = params self.avg_z = 0. - self.mesh_offset = 0. logging.debug('bed_mesh: probe/mesh parameters:') for key, value in self.mesh_params.items(): logging.debug("%s : %s" % (key, value)) @@ -802,7 +802,7 @@ class ZMesh: (self.mesh_y_count - 1) def get_mesh_matrix(self): if self.mesh_matrix is not None: - return [[round(z + self.mesh_offset, 6) for z in line] + return [[round(z, 6) for z in line] for line in self.mesh_matrix] return [[]] def get_probed_matrix(self): @@ -851,12 +851,6 @@ class ZMesh: # z step distances self.avg_z = round(self.avg_z, 2) self.print_mesh(logging.debug) - def offset_mesh(self, offset): - if self.mesh_matrix: - self.mesh_offset = offset - for y_line in self.mesh_matrix: - for idx, z in enumerate(y_line): - y_line[idx] = z - self.mesh_offset def get_x_coordinate(self, index): return self.mesh_x_min + self.mesh_x_dist * index def get_y_coordinate(self, index):