bed_mesh: implement BED_MESH_OFFSET
The BED_MESH_OFFSET gcode can be used to apply X and/or Y offsets the the mesh lookup. This allows printers with independent extruders to correct the Z adjustment when changing a tool. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
4dfe01a2cd
commit
3fcce4bb4b
|
@ -93,6 +93,9 @@ class BedMesh:
|
||||||
self.gcode.register_command(
|
self.gcode.register_command(
|
||||||
'BED_MESH_CLEAR', self.cmd_BED_MESH_CLEAR,
|
'BED_MESH_CLEAR', self.cmd_BED_MESH_CLEAR,
|
||||||
desc=self.cmd_BED_MESH_CLEAR_help)
|
desc=self.cmd_BED_MESH_CLEAR_help)
|
||||||
|
self.gcode.register_command(
|
||||||
|
'BED_MESH_OFFSET', self.cmd_BED_MESH_OFFSET,
|
||||||
|
desc=self.cmd_BED_MESH_OFFSET_help)
|
||||||
# Register transform
|
# Register transform
|
||||||
gcode_move = self.printer.load_object(config, 'gcode_move')
|
gcode_move = self.printer.load_object(config, 'gcode_move')
|
||||||
gcode_move.set_move_transform(self)
|
gcode_move.set_move_transform(self)
|
||||||
|
@ -230,9 +233,20 @@ class BedMesh:
|
||||||
gcmd.respond_raw("mesh_map_output " + json.dumps(outdict))
|
gcmd.respond_raw("mesh_map_output " + json.dumps(outdict))
|
||||||
else:
|
else:
|
||||||
gcmd.respond_info("Bed has not been probed")
|
gcmd.respond_info("Bed has not been probed")
|
||||||
cmd_BED_MESH_CLEAR_help = "Clear the Mesh so no z-adjusment is made"
|
cmd_BED_MESH_CLEAR_help = "Clear the Mesh so no z-adjustment is made"
|
||||||
def cmd_BED_MESH_CLEAR(self, gcmd):
|
def cmd_BED_MESH_CLEAR(self, gcmd):
|
||||||
self.set_mesh(None)
|
self.set_mesh(None)
|
||||||
|
cmd_BED_MESH_OFFSET_help = "Add X/Y offsets to the mesh lookup"
|
||||||
|
def cmd_BED_MESH_OFFSET(self, gcmd):
|
||||||
|
if self.z_mesh is not None:
|
||||||
|
offsets = [None, None]
|
||||||
|
for i, axis in enumerate(['X', 'Y']):
|
||||||
|
offsets[i] = gcmd.get_float(axis, None)
|
||||||
|
self.z_mesh.set_mesh_offsets(offsets)
|
||||||
|
gcode_move = self.printer.lookup_object('gcode_move')
|
||||||
|
gcode_move.reset_last_position()
|
||||||
|
else:
|
||||||
|
gcmd.respond_info("No mesh loaded to offset")
|
||||||
|
|
||||||
|
|
||||||
class BedMeshCalibrate:
|
class BedMeshCalibrate:
|
||||||
|
@ -767,6 +781,7 @@ class ZMesh:
|
||||||
self.probed_matrix = self.mesh_matrix = None
|
self.probed_matrix = self.mesh_matrix = None
|
||||||
self.mesh_params = params
|
self.mesh_params = params
|
||||||
self.avg_z = 0.
|
self.avg_z = 0.
|
||||||
|
self.mesh_offsets = [0., 0.]
|
||||||
logging.debug('bed_mesh: probe/mesh parameters:')
|
logging.debug('bed_mesh: probe/mesh parameters:')
|
||||||
for key, value in self.mesh_params.items():
|
for key, value in self.mesh_params.items():
|
||||||
logging.debug("%s : %s" % (key, value))
|
logging.debug("%s : %s" % (key, value))
|
||||||
|
@ -828,6 +843,8 @@ class ZMesh:
|
||||||
msg = "Mesh X,Y: %d,%d\n" % (self.mesh_x_count, self.mesh_y_count)
|
msg = "Mesh X,Y: %d,%d\n" % (self.mesh_x_count, self.mesh_y_count)
|
||||||
if move_z is not None:
|
if move_z is not None:
|
||||||
msg += "Search Height: %d\n" % (move_z)
|
msg += "Search Height: %d\n" % (move_z)
|
||||||
|
msg += "Mesh Offsets: X=%.4f, Y=%.4f\n" % (
|
||||||
|
self.mesh_offsets[0], self.mesh_offsets[1])
|
||||||
msg += "Mesh Average: %.2f\n" % (self.avg_z)
|
msg += "Mesh Average: %.2f\n" % (self.avg_z)
|
||||||
rng = self.get_z_range()
|
rng = self.get_z_range()
|
||||||
msg += "Mesh Range: min=%.4f max=%.4f\n" % (rng[0], rng[1])
|
msg += "Mesh Range: min=%.4f max=%.4f\n" % (rng[0], rng[1])
|
||||||
|
@ -851,6 +868,10 @@ class ZMesh:
|
||||||
# z step distances
|
# z step distances
|
||||||
self.avg_z = round(self.avg_z, 2)
|
self.avg_z = round(self.avg_z, 2)
|
||||||
self.print_mesh(logging.debug)
|
self.print_mesh(logging.debug)
|
||||||
|
def set_mesh_offsets(self, offsets):
|
||||||
|
for i, o in enumerate(offsets):
|
||||||
|
if o is not None:
|
||||||
|
self.mesh_offsets[i] = o
|
||||||
def get_x_coordinate(self, index):
|
def get_x_coordinate(self, index):
|
||||||
return self.mesh_x_min + self.mesh_x_dist * index
|
return self.mesh_x_min + self.mesh_x_dist * index
|
||||||
def get_y_coordinate(self, index):
|
def get_y_coordinate(self, index):
|
||||||
|
@ -858,8 +879,8 @@ class ZMesh:
|
||||||
def calc_z(self, x, y):
|
def calc_z(self, x, y):
|
||||||
if self.mesh_matrix is not None:
|
if self.mesh_matrix is not None:
|
||||||
tbl = self.mesh_matrix
|
tbl = self.mesh_matrix
|
||||||
tx, xidx = self._get_linear_index(x, 0)
|
tx, xidx = self._get_linear_index(x + self.mesh_offsets[0], 0)
|
||||||
ty, yidx = self._get_linear_index(y, 1)
|
ty, yidx = self._get_linear_index(y + self.mesh_offsets[1], 1)
|
||||||
z0 = lerp(tx, tbl[yidx][xidx], tbl[yidx][xidx+1])
|
z0 = lerp(tx, tbl[yidx][xidx], tbl[yidx][xidx+1])
|
||||||
z1 = lerp(tx, tbl[yidx+1][xidx], tbl[yidx+1][xidx+1])
|
z1 = lerp(tx, tbl[yidx+1][xidx], tbl[yidx+1][xidx+1])
|
||||||
return lerp(ty, z0, z1)
|
return lerp(ty, z0, z1)
|
||||||
|
|
Loading…
Reference in New Issue