mirror of https://github.com/Desuuuu/klipper.git
quad_gantry_level: Use new ZAdjustHelper
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
20851ab3e9
commit
494a5b732d
|
@ -4,19 +4,18 @@
|
|||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import logging
|
||||
import probe
|
||||
import probe, z_tilt
|
||||
|
||||
class QuadGantryLevel:
|
||||
def __init__(self, config):
|
||||
self.printer = config.get_printer()
|
||||
self.max_adjust = config.getfloat("max_adjust", 4, above=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)
|
||||
if len(self.probe_helper.probe_points) != 4:
|
||||
raise config.error(
|
||||
"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')
|
||||
try:
|
||||
gantry_corners = [line.split(',', 1)
|
||||
|
@ -29,19 +28,11 @@ class QuadGantryLevel:
|
|||
if len(self.gantry_corners) < 2:
|
||||
raise config.error(
|
||||
"quad_gantry_level requires at least two gantry_corners")
|
||||
self.z_steppers = []
|
||||
# Register QUAD_GANTRY_LEVEL command
|
||||
self.gcode = self.printer.lookup_object('gcode')
|
||||
self.gcode.register_command(
|
||||
'QUAD_GANTRY_LEVEL', self.cmd_QUAD_GANTRY_LEVEL,
|
||||
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 = (
|
||||
"Conform a moving, twistable gantry to the shape of a stationary bed")
|
||||
def cmd_QUAD_GANTRY_LEVEL(self, params):
|
||||
|
@ -96,13 +87,8 @@ class QuadGantryLevel:
|
|||
"is greater than max_adjust %0.6f" % (self.max_adjust))
|
||||
return
|
||||
|
||||
try:
|
||||
self.adjust_steppers(z_adjust)
|
||||
except:
|
||||
logging.exception("quad_gantry_level adjust_steppers")
|
||||
for s in self.z_steppers:
|
||||
s.set_ignore_move(False)
|
||||
raise
|
||||
speed = self.probe_helper.get_lift_speed()
|
||||
self.z_helper.adjust_steppers(z_adjust, speed)
|
||||
def linefit(self,p1,p2):
|
||||
if p1[1] == p2[1]:
|
||||
# Straight line
|
||||
|
@ -112,29 +98,6 @@ class QuadGantryLevel:
|
|||
return m,b
|
||||
def plot(self,f,x):
|
||||
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):
|
||||
return QuadGantryLevel(config)
|
||||
|
|
Loading…
Reference in New Issue