bed_tilt: Take into account the XY position used with z_virtual_endstop
If a z_virtual_endstop is in use, then record the last XY position that is used when the Z is homed. Use that XY position to report what change is needed to the z position_endstop. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
1dda4628a0
commit
c95cc3fb66
|
@ -44,6 +44,10 @@ class BedTiltCalibrate:
|
|||
self.speed = config.getfloat('speed', 50., above=0.)
|
||||
self.horizontal_move_z = config.getfloat('horizontal_move_z', 5.)
|
||||
self.probe_z_offset = config.getfloat('probe_z_offset', 0.)
|
||||
self.z_position_endstop = None
|
||||
if config.has_section('stepper_z'):
|
||||
zconfig = config.getsection('stepper_z')
|
||||
self.z_position_endstop = zconfig.getfloat('position_endstop', None)
|
||||
self.manual_probe = config.getboolean('manual_probe', None)
|
||||
if self.manual_probe is None:
|
||||
self.manual_probe = not config.has_section('probe')
|
||||
|
@ -81,15 +85,30 @@ class BedTiltCalibrate:
|
|||
for pos in positions:
|
||||
logging.info("orig: %s new: %s", adjusted_height(pos, params),
|
||||
adjusted_height(pos, new_params))
|
||||
z_warn = ""
|
||||
z_diff = new_params['z_adjust'] - self.probe_z_offset
|
||||
if abs(z_diff) > .010:
|
||||
z_warn = "Note: Z offset was %.6f\n" % (z_diff,)
|
||||
if self.z_position_endstop is not None:
|
||||
# Cartesian style robot
|
||||
z_extra = ""
|
||||
probe = self.printer.lookup_object('probe', None)
|
||||
if probe is not None:
|
||||
last_home_position = probe.last_home_position()
|
||||
if last_home_position is not None:
|
||||
# Using z_virtual_endstop
|
||||
home_x, home_y = last_home_position[:2]
|
||||
z_diff -= home_x * new_params['x_adjust']
|
||||
z_diff -= home_y * new_params['y_adjust']
|
||||
z_extra = " (when Z homing at %.3f,%.3f)" % (home_x, home_y)
|
||||
z_adjust = "stepper_z position_endstop: %.6f%s\n" % (
|
||||
self.z_position_endstop - z_diff, z_extra)
|
||||
else:
|
||||
# Delta (or other) style robot
|
||||
z_adjust = "Add %.6f to endstop position\n" % (-z_diff,)
|
||||
msg = "%sx_adjust: %.6f y_adjust: %.6f" % (
|
||||
z_adjust, new_params['x_adjust'], new_params['y_adjust'])
|
||||
logging.info("bed_tilt_calibrate: %s", msg)
|
||||
self.gcode.respond_info(
|
||||
"%sx_adjust: %.6f y_adjust: %.6f\n"
|
||||
"To use these parameters, update the printer config file with\n"
|
||||
"the above and then issue a RESTART command" % (
|
||||
z_warn, new_params['x_adjust'], new_params['y_adjust']))
|
||||
"%s\nTo use these parameters, update the printer config file with\n"
|
||||
"the above and then issue a RESTART command" % (msg,))
|
||||
|
||||
def load_config(config):
|
||||
return BedTilt(config)
|
||||
|
|
|
@ -34,6 +34,7 @@ class PrinterProbe:
|
|||
self.mcu_probe = ProbeEndstopWrapper(config, self.mcu_probe)
|
||||
# Create z_virtual_endstop pin
|
||||
ppins.register_chip('probe', self)
|
||||
self.z_virtual_endstop = None
|
||||
# Register PROBE/QUERY_PROBE commands
|
||||
self.gcode = self.printer.lookup_object('gcode')
|
||||
self.gcode.register_command(
|
||||
|
@ -53,7 +54,13 @@ class PrinterProbe:
|
|||
raise pins.error("Probe virtual endstop only useful as endstop pin")
|
||||
if pin_params['invert'] or pin_params['pullup']:
|
||||
raise pins.error("Can not pullup/invert probe virtual endstop")
|
||||
return self.mcu_probe
|
||||
self.z_virtual_endstop = ProbeVirtualEndstop(
|
||||
self.printer, self.mcu_probe)
|
||||
return self.z_virtual_endstop
|
||||
def last_home_position(self):
|
||||
if self.z_virtual_endstop is None:
|
||||
return None
|
||||
return self.z_virtual_endstop.position
|
||||
cmd_PROBE_help = "Probe Z-height at current XY position"
|
||||
def cmd_PROBE(self, params):
|
||||
toolhead = self.printer.lookup_object('toolhead')
|
||||
|
@ -101,6 +108,26 @@ class ProbeEndstopWrapper:
|
|||
self.gcode.run_script(self.deactivate_gcode)
|
||||
self.mcu_endstop.home_finalize()
|
||||
|
||||
# Wrapper that records the last XY position of a virtual endstop probe
|
||||
class ProbeVirtualEndstop:
|
||||
def __init__(self, printer, mcu_endstop):
|
||||
self.printer = printer
|
||||
self.mcu_endstop = mcu_endstop
|
||||
self.position = None
|
||||
# Wrappers
|
||||
self.get_mcu = self.mcu_endstop.get_mcu
|
||||
self.add_stepper = self.mcu_endstop.add_stepper
|
||||
self.get_steppers = self.mcu_endstop.get_steppers
|
||||
self.home_start = self.mcu_endstop.home_start
|
||||
self.home_wait = self.mcu_endstop.home_wait
|
||||
self.query_endstop = self.mcu_endstop.query_endstop
|
||||
self.query_endstop_wait = self.mcu_endstop.query_endstop_wait
|
||||
self.home_prepare = self.mcu_endstop.home_prepare
|
||||
self.TimeoutError = self.mcu_endstop.TimeoutError
|
||||
def home_finalize(self):
|
||||
self.position = self.printer.lookup_object('toolhead').get_position()
|
||||
self.mcu_endstop.home_finalize()
|
||||
|
||||
# Helper code that can probe a series of points and report the
|
||||
# position at each point.
|
||||
class ProbePointsHelper:
|
||||
|
|
Loading…
Reference in New Issue