z_tilt: Take into account probe xy offset when calculating z_adjust
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
19d18c2bc1
commit
c3550158bb
|
@ -41,9 +41,11 @@ class ZTilt:
|
||||||
def cmd_Z_TILT_ADJUST(self, params):
|
def cmd_Z_TILT_ADJUST(self, params):
|
||||||
self.probe_helper.start_probe(params)
|
self.probe_helper.start_probe(params)
|
||||||
def probe_finalize(self, offsets, positions):
|
def probe_finalize(self, offsets, positions):
|
||||||
|
# Setup for coordinate descent analysis
|
||||||
z_offset = offsets[2]
|
z_offset = offsets[2]
|
||||||
logging.info("Calculating bed tilt with: %s", positions)
|
logging.info("Calculating bed tilt with: %s", positions)
|
||||||
params = { 'x_adjust': 0., 'y_adjust': 0., 'z_adjust': z_offset }
|
params = { 'x_adjust': 0., 'y_adjust': 0., 'z_adjust': z_offset }
|
||||||
|
# Perform coordinate descent
|
||||||
def adjusted_height(pos, params):
|
def adjusted_height(pos, params):
|
||||||
x, y, z = pos
|
x, y, z = pos
|
||||||
return (z - x*params['x_adjust'] - y*params['y_adjust']
|
return (z - x*params['x_adjust'] - y*params['y_adjust']
|
||||||
|
@ -55,16 +57,20 @@ class ZTilt:
|
||||||
return total_error
|
return total_error
|
||||||
new_params = mathutil.coordinate_descent(
|
new_params = mathutil.coordinate_descent(
|
||||||
params.keys(), params, errorfunc)
|
params.keys(), params, errorfunc)
|
||||||
|
# Apply results
|
||||||
logging.info("Calculated bed tilt parameters: %s", new_params)
|
logging.info("Calculated bed tilt parameters: %s", new_params)
|
||||||
|
x_adjust = new_params['x_adjust']
|
||||||
|
y_adjust = new_params['y_adjust']
|
||||||
|
z_adjust = (new_params['z_adjust'] - z_offset
|
||||||
|
- x_adjust * offsets[0] - y_adjust * offsets[1])
|
||||||
try:
|
try:
|
||||||
self.adjust_steppers(new_params['x_adjust'], new_params['y_adjust'],
|
self.adjust_steppers(x_adjust, y_adjust, z_adjust)
|
||||||
new_params['z_adjust'], z_offset)
|
|
||||||
except:
|
except:
|
||||||
logging.exception("z_tilt adjust_steppers")
|
logging.exception("z_tilt adjust_steppers")
|
||||||
for s in self.z_steppers:
|
for s in self.z_steppers:
|
||||||
z.set_ignore_move(False)
|
z.set_ignore_move(False)
|
||||||
raise
|
raise
|
||||||
def adjust_steppers(self, x_adjust, y_adjust, z_adjust, z_offset):
|
def adjust_steppers(self, x_adjust, y_adjust, z_adjust):
|
||||||
toolhead = self.printer.lookup_object('toolhead')
|
toolhead = self.printer.lookup_object('toolhead')
|
||||||
curpos = toolhead.get_position()
|
curpos = toolhead.get_position()
|
||||||
speed = self.probe_helper.get_lift_speed()
|
speed = self.probe_helper.get_lift_speed()
|
||||||
|
@ -75,9 +81,9 @@ class ZTilt:
|
||||||
stepper_offset = -(x*x_adjust + y*y_adjust)
|
stepper_offset = -(x*x_adjust + y*y_adjust)
|
||||||
positions.append((stepper_offset, s))
|
positions.append((stepper_offset, s))
|
||||||
# Report on movements
|
# Report on movements
|
||||||
msg = "Making the following Z tilt adjustments:\n%s\nz_offset = %.6f" % (
|
stepstrs = ["%s = %.6f" % (s.get_name(), so) for so, s in positions]
|
||||||
"\n".join(["%s = %.6f" % (s.get_name(), so) for so, s in positions]),
|
msg = "Making the following Z adjustments:\n%s\nz_adjust = %.6f" % (
|
||||||
z_adjust - z_offset)
|
"\n".join(stepstrs), z_adjust)
|
||||||
logging.info(msg)
|
logging.info(msg)
|
||||||
self.gcode.respond_info(msg)
|
self.gcode.respond_info(msg)
|
||||||
# Move each z stepper (sorted from lowest to highest) until they match
|
# Move each z stepper (sorted from lowest to highest) until they match
|
||||||
|
@ -94,7 +100,7 @@ class ZTilt:
|
||||||
# Z should now be level - do final cleanup
|
# Z should now be level - do final cleanup
|
||||||
last_stepper_offset, last_stepper = positions[-1]
|
last_stepper_offset, last_stepper = positions[-1]
|
||||||
last_stepper.set_ignore_move(False)
|
last_stepper.set_ignore_move(False)
|
||||||
curpos[2] -= z_adjust - z_offset
|
curpos[2] -= z_adjust
|
||||||
toolhead.set_position(curpos)
|
toolhead.set_position(curpos)
|
||||||
self.gcode.reset_last_position()
|
self.gcode.reset_last_position()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue