z_tilt: expose an 'applied' status to allow macros to skip QGL/Z_TILT_ADJUST (#4313)
This is useful for macros that'd like to skip QGL if already leveled, e.g.: ``` {% if not printer.quad_gantry_level.applied %} QUAD_GANTRY_LEVEL {% endif %} ``` Signed-off-by: Michael Rose <elementation@gmail.com>
This commit is contained in:
parent
c148f17ea3
commit
27f8cf025e
|
@ -218,6 +218,13 @@ is defined):
|
||||||
template expansion, the PROBE (or similar) command must be run prior
|
template expansion, the PROBE (or similar) command must be run prior
|
||||||
to the macro containing this reference.
|
to the macro containing this reference.
|
||||||
|
|
||||||
|
# quad_gantry_level
|
||||||
|
|
||||||
|
The following information is available in the `quad_gantry_level` object
|
||||||
|
(this object is available if quad_gantry_level is defined):
|
||||||
|
- `applied`: True if the gantry leveling process has been run and completed
|
||||||
|
successfully.
|
||||||
|
|
||||||
# query_endstops
|
# query_endstops
|
||||||
|
|
||||||
The following information is available in the `query_endstops` object
|
The following information is available in the `query_endstops` object
|
||||||
|
@ -316,3 +323,10 @@ object is always available):
|
||||||
state. Possible values are: "ready", "startup", "shutdown", "error".
|
state. Possible values are: "ready", "startup", "shutdown", "error".
|
||||||
- `state_message`: A human readable string giving additional context
|
- `state_message`: A human readable string giving additional context
|
||||||
on the current Klipper state.
|
on the current Klipper state.
|
||||||
|
|
||||||
|
# z_tilt
|
||||||
|
|
||||||
|
The following information is available in the `z_tilt` object (this
|
||||||
|
object is available if z_tilt is defined):
|
||||||
|
- `applied`: True if the z-tilt leveling process has been run and completed
|
||||||
|
successfully.
|
||||||
|
|
|
@ -33,6 +33,7 @@ class QuadGantryLevel:
|
||||||
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_status = z_tilt.ZAdjustStatus(self.printer)
|
||||||
self.z_helper = z_tilt.ZAdjustHelper(config, 4)
|
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:
|
||||||
|
@ -54,6 +55,7 @@ class QuadGantryLevel:
|
||||||
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, gcmd):
|
def cmd_QUAD_GANTRY_LEVEL(self, gcmd):
|
||||||
|
self.z_status.reset()
|
||||||
self.retry_helper.start(gcmd)
|
self.retry_helper.start(gcmd)
|
||||||
self.probe_helper.start_probe(gcmd)
|
self.probe_helper.start_probe(gcmd)
|
||||||
def probe_finalize(self, offsets, positions):
|
def probe_finalize(self, offsets, positions):
|
||||||
|
@ -114,7 +116,9 @@ class QuadGantryLevel:
|
||||||
|
|
||||||
speed = self.probe_helper.get_lift_speed()
|
speed = self.probe_helper.get_lift_speed()
|
||||||
self.z_helper.adjust_steppers(z_adjust, speed)
|
self.z_helper.adjust_steppers(z_adjust, speed)
|
||||||
return self.retry_helper.check_retry(z_positions)
|
return self.z_status.check_retry_result(
|
||||||
|
self.retry_helper.check_retry(z_positions))
|
||||||
|
|
||||||
def linefit(self,p1,p2):
|
def linefit(self,p1,p2):
|
||||||
if p1[1] == p2[1]:
|
if p1[1] == p2[1]:
|
||||||
# Straight line
|
# Straight line
|
||||||
|
@ -124,6 +128,8 @@ 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 get_status(self, eventtime):
|
||||||
|
return self.z_status.get_status(eventtime)
|
||||||
|
|
||||||
def load_config(config):
|
def load_config(config):
|
||||||
return QuadGantryLevel(config)
|
return QuadGantryLevel(config)
|
||||||
|
|
|
@ -66,6 +66,22 @@ class ZAdjustHelper:
|
||||||
curpos[2] += first_stepper_offset
|
curpos[2] += first_stepper_offset
|
||||||
toolhead.set_position(curpos)
|
toolhead.set_position(curpos)
|
||||||
|
|
||||||
|
class ZAdjustStatus:
|
||||||
|
def __init__(self, printer):
|
||||||
|
self.applied = False
|
||||||
|
printer.register_event_handler("stepper_enable:motor_off",
|
||||||
|
self._motor_off)
|
||||||
|
def check_retry_result(self, retry_result):
|
||||||
|
if retry_result == "done":
|
||||||
|
self.applied = True
|
||||||
|
return retry_result
|
||||||
|
def reset(self):
|
||||||
|
self.applied = False
|
||||||
|
def get_status(self, eventtime):
|
||||||
|
return {'applied': self.applied}
|
||||||
|
def _motor_off(self, print_time):
|
||||||
|
self.reset()
|
||||||
|
|
||||||
class RetryHelper:
|
class RetryHelper:
|
||||||
def __init__(self, config, error_msg_extra = ""):
|
def __init__(self, config, error_msg_extra = ""):
|
||||||
self.gcode = config.get_printer().lookup_object('gcode')
|
self.gcode = config.get_printer().lookup_object('gcode')
|
||||||
|
@ -123,6 +139,7 @@ class ZTilt:
|
||||||
self.retry_helper = RetryHelper(config)
|
self.retry_helper = RetryHelper(config)
|
||||||
self.probe_helper = probe.ProbePointsHelper(config, self.probe_finalize)
|
self.probe_helper = probe.ProbePointsHelper(config, self.probe_finalize)
|
||||||
self.probe_helper.minimum_points(2)
|
self.probe_helper.minimum_points(2)
|
||||||
|
self.z_status = ZAdjustStatus(self.printer)
|
||||||
self.z_helper = ZAdjustHelper(config, len(self.z_positions))
|
self.z_helper = ZAdjustHelper(config, len(self.z_positions))
|
||||||
# Register Z_TILT_ADJUST command
|
# Register Z_TILT_ADJUST command
|
||||||
gcode = self.printer.lookup_object('gcode')
|
gcode = self.printer.lookup_object('gcode')
|
||||||
|
@ -130,6 +147,7 @@ class ZTilt:
|
||||||
desc=self.cmd_Z_TILT_ADJUST_help)
|
desc=self.cmd_Z_TILT_ADJUST_help)
|
||||||
cmd_Z_TILT_ADJUST_help = "Adjust the Z tilt"
|
cmd_Z_TILT_ADJUST_help = "Adjust the Z tilt"
|
||||||
def cmd_Z_TILT_ADJUST(self, gcmd):
|
def cmd_Z_TILT_ADJUST(self, gcmd):
|
||||||
|
self.z_status.reset()
|
||||||
self.retry_helper.start(gcmd)
|
self.retry_helper.start(gcmd)
|
||||||
self.probe_helper.start_probe(gcmd)
|
self.probe_helper.start_probe(gcmd)
|
||||||
def probe_finalize(self, offsets, positions):
|
def probe_finalize(self, offsets, positions):
|
||||||
|
@ -159,7 +177,10 @@ class ZTilt:
|
||||||
adjustments = [x*x_adjust + y*y_adjust + z_adjust
|
adjustments = [x*x_adjust + y*y_adjust + z_adjust
|
||||||
for x, y in self.z_positions]
|
for x, y in self.z_positions]
|
||||||
self.z_helper.adjust_steppers(adjustments, speed)
|
self.z_helper.adjust_steppers(adjustments, speed)
|
||||||
return self.retry_helper.check_retry([p[2] for p in positions])
|
return self.z_status.check_retry_result(
|
||||||
|
self.retry_helper.check_retry([p[2] for p in positions]))
|
||||||
|
def get_status(self, eventtime):
|
||||||
|
return self.z_status.get_status(eventtime)
|
||||||
|
|
||||||
def load_config(config):
|
def load_config(config):
|
||||||
return ZTilt(config)
|
return ZTilt(config)
|
||||||
|
|
Loading…
Reference in New Issue