bed_mesh: Support toolhead positions with more than 4 axes

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2025-04-07 19:38:32 -04:00
parent bb281834b0
commit 447908ce0c

View File

@ -186,7 +186,8 @@ class BedMesh:
self.last_position[2] -= self.fade_target self.last_position[2] -= self.fade_target
else: else:
# return current position minus the current z-adjustment # return current position minus the current z-adjustment
x, y, z, e = self.toolhead.get_position() cur_pos = self.toolhead.get_position()
x, y, z = cur_pos[:3]
max_adj = self.z_mesh.calc_z(x, y) max_adj = self.z_mesh.calc_z(x, y)
factor = 1. factor = 1.
z_adj = max_adj - self.fade_target z_adj = max_adj - self.fade_target
@ -202,19 +203,19 @@ class BedMesh:
(self.fade_dist - z_adj)) (self.fade_dist - z_adj))
factor = constrain(factor, 0., 1.) factor = constrain(factor, 0., 1.)
final_z_adj = factor * z_adj + self.fade_target final_z_adj = factor * z_adj + self.fade_target
self.last_position[:] = [x, y, z - final_z_adj, e] self.last_position[:] = [x, y, z - final_z_adj] + cur_pos[3:]
return list(self.last_position) return list(self.last_position)
def move(self, newpos, speed): def move(self, newpos, speed):
factor = self.get_z_factor(newpos[2]) factor = self.get_z_factor(newpos[2])
if self.z_mesh is None or not factor: if self.z_mesh is None or not factor:
# No mesh calibrated, or mesh leveling phased out. # No mesh calibrated, or mesh leveling phased out.
x, y, z, e = newpos x, y, z = newpos[:3]
if self.log_fade_complete: if self.log_fade_complete:
self.log_fade_complete = False self.log_fade_complete = False
logging.info( logging.info(
"bed_mesh fade complete: Current Z: %.4f fade_target: %.4f " "bed_mesh fade complete: Current Z: %.4f fade_target: %.4f "
% (z, self.fade_target)) % (z, self.fade_target))
self.toolhead.move([x, y, z + self.fade_target, e], speed) self.toolhead.move([x, y, z + self.fade_target] + newpos[3:], speed)
else: else:
self.splitter.build_move(self.last_position, newpos, factor) self.splitter.build_move(self.last_position, newpos, factor)
while not self.splitter.traverse_complete: while not self.splitter.traverse_complete:
@ -1273,7 +1274,7 @@ class MoveSplitter:
self.z_offset = self._calc_z_offset(prev_pos) self.z_offset = self._calc_z_offset(prev_pos)
self.traverse_complete = False self.traverse_complete = False
self.distance_checked = 0. self.distance_checked = 0.
axes_d = [self.next_pos[i] - self.prev_pos[i] for i in range(4)] axes_d = [np - pp for np, pp in zip(self.next_pos, self.prev_pos)]
self.total_move_length = math.sqrt(sum([d*d for d in axes_d[:3]])) self.total_move_length = math.sqrt(sum([d*d for d in axes_d[:3]]))
self.axis_move = [not isclose(d, 0., abs_tol=1e-10) for d in axes_d] self.axis_move = [not isclose(d, 0., abs_tol=1e-10) for d in axes_d]
def _calc_z_offset(self, pos): def _calc_z_offset(self, pos):
@ -1286,7 +1287,7 @@ class MoveSplitter:
raise self.gcode.error( raise self.gcode.error(
"bed_mesh: Slice distance is negative " "bed_mesh: Slice distance is negative "
"or greater than entire move length") "or greater than entire move length")
for i in range(4): for i in range(len(self.next_pos)):
if self.axis_move[i]: if self.axis_move[i]:
self.current_pos[i] = lerp( self.current_pos[i] = lerp(
t, self.prev_pos[i], self.next_pos[i]) t, self.prev_pos[i], self.next_pos[i])
@ -1301,9 +1302,9 @@ class MoveSplitter:
next_z = self._calc_z_offset(self.current_pos) next_z = self._calc_z_offset(self.current_pos)
if abs(next_z - self.z_offset) >= self.split_delta_z: if abs(next_z - self.z_offset) >= self.split_delta_z:
self.z_offset = next_z self.z_offset = next_z
return self.current_pos[0], self.current_pos[1], \ newpos = list(self.current_pos)
self.current_pos[2] + self.z_offset, \ newpos[2] += self.z_offset
self.current_pos[3] return newpos
# end of move reached # end of move reached
self.current_pos[:] = self.next_pos self.current_pos[:] = self.next_pos
self.z_offset = self._calc_z_offset(self.current_pos) self.z_offset = self._calc_z_offset(self.current_pos)