quad_gantry_level: Use new ZAdjustHelper

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-05-27 09:56:34 -04:00 committed by KevinOConnor
parent 20851ab3e9
commit 494a5b732d
1 changed files with 4 additions and 41 deletions

View File

@ -4,19 +4,18 @@
# #
# This file may be distributed under the terms of the GNU GPLv3 license. # This file may be distributed under the terms of the GNU GPLv3 license.
import logging import logging
import probe import probe, z_tilt
class QuadGantryLevel: class QuadGantryLevel:
def __init__(self, config): def __init__(self, config):
self.printer = config.get_printer() self.printer = config.get_printer()
self.max_adjust = config.getfloat("max_adjust", 4, above=0) self.max_adjust = config.getfloat("max_adjust", 4, above=0)
self.horizontal_move_z = config.getfloat("horizontal_move_z", 5.0) self.horizontal_move_z = config.getfloat("horizontal_move_z", 5.0)
self.printer.register_event_handler("klippy:connect",
self.handle_connect)
self.probe_helper = probe.ProbePointsHelper(config, self.probe_finalize) self.probe_helper = probe.ProbePointsHelper(config, self.probe_finalize)
if len(self.probe_helper.probe_points) != 4: if len(self.probe_helper.probe_points) != 4:
raise config.error( raise config.error(
"Need exactly 4 probe points for quad_gantry_level") "Need exactly 4 probe points for quad_gantry_level")
self.z_helper = z_tilt.ZAdjustHelper(config, 4)
gantry_corners = config.get('gantry_corners').split('\n') gantry_corners = config.get('gantry_corners').split('\n')
try: try:
gantry_corners = [line.split(',', 1) gantry_corners = [line.split(',', 1)
@ -29,19 +28,11 @@ class QuadGantryLevel:
if len(self.gantry_corners) < 2: if len(self.gantry_corners) < 2:
raise config.error( raise config.error(
"quad_gantry_level requires at least two gantry_corners") "quad_gantry_level requires at least two gantry_corners")
self.z_steppers = []
# Register QUAD_GANTRY_LEVEL command # Register QUAD_GANTRY_LEVEL command
self.gcode = self.printer.lookup_object('gcode') self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command( self.gcode.register_command(
'QUAD_GANTRY_LEVEL', self.cmd_QUAD_GANTRY_LEVEL, 'QUAD_GANTRY_LEVEL', self.cmd_QUAD_GANTRY_LEVEL,
desc=self.cmd_QUAD_GANTRY_LEVEL_help) desc=self.cmd_QUAD_GANTRY_LEVEL_help)
def handle_connect(self):
kin = self.printer.lookup_object('toolhead').get_kinematics()
z_steppers = kin.get_steppers('Z')
if len(z_steppers) != 4:
raise self.printer.config_error(
"quad_gantry_level needs exactly 4 z steppers")
self.z_steppers = z_steppers
cmd_QUAD_GANTRY_LEVEL_help = ( cmd_QUAD_GANTRY_LEVEL_help = (
"Conform a moving, twistable gantry to the shape of a stationary bed") "Conform a moving, twistable gantry to the shape of a stationary bed")
def cmd_QUAD_GANTRY_LEVEL(self, params): def cmd_QUAD_GANTRY_LEVEL(self, params):
@ -96,13 +87,8 @@ class QuadGantryLevel:
"is greater than max_adjust %0.6f" % (self.max_adjust)) "is greater than max_adjust %0.6f" % (self.max_adjust))
return return
try: speed = self.probe_helper.get_lift_speed()
self.adjust_steppers(z_adjust) self.z_helper.adjust_steppers(z_adjust, speed)
except:
logging.exception("quad_gantry_level adjust_steppers")
for s in self.z_steppers:
s.set_ignore_move(False)
raise
def linefit(self,p1,p2): def linefit(self,p1,p2):
if p1[1] == p2[1]: if p1[1] == p2[1]:
# Straight line # Straight line
@ -112,29 +98,6 @@ class QuadGantryLevel:
return m,b return m,b
def plot(self,f,x): def plot(self,f,x):
return f[0]*x + f[1] return f[0]*x + f[1]
def adjust_steppers(self, z_adjust):
msg = "Making the following gantry adjustments:\n%s\n" % (
"\n".join(["%s = %.6f" % (
self.z_steppers[z_id].get_name(), z_adjust[z_id]
) for z_id in range(4)]))
self.gcode.respond_info(msg)
toolhead = self.printer.lookup_object('toolhead')
cur_pos = toolhead.get_position()
speed = self.probe_helper.get_lift_speed()
# Disable moves on all Z steppers
for s in self.z_steppers:
s.set_ignore_move(True)
for z_id in range(len(z_adjust)):
stepper = self.z_steppers[z_id]
stepper.set_ignore_move(False)
cur_pos[2] = cur_pos[2] + z_adjust[z_id]
toolhead.move(cur_pos, speed)
toolhead.set_position(cur_pos)
stepper.set_ignore_move(True)
# Re-enable moves on all Z steppers
for s in self.z_steppers:
s.set_ignore_move(False)
self.gcode.reset_last_position()
def load_config(config): def load_config(config):
return QuadGantryLevel(config) return QuadGantryLevel(config)