screws_tilt_adjust: Add MAX_DEVIATION parameter for bed level invariant.

This is useful when a saved bed mesh is used to ensure that the bed level
has not drifted too far from where it was when the mesh was created.

Signed-off-by: Johannes Stuettgen <johannes.stuettgen@gmail.com>
This commit is contained in:
Johannes Stuettgen 2021-02-08 17:52:46 +01:00 committed by KevinOConnor
parent d36dbfebd1
commit ed6ab6b9cc
3 changed files with 16 additions and 0 deletions

View File

@ -191,3 +191,10 @@ it has an X or Y offset) then note that adjusting the bed tilt will
invalidate any previous probe calibration that was performed with a
tilted bed. Be sure to run [probe calibration](Probe_Calibrate.md)
after the bed screws have been adjusted.
The `MAX_DEVIATION` parameter is useful when a saved bed mesh is used,
to ensure that the bed level has not drifted too far from where it was when
the mesh was created. For example, `SCREWS_TILT_CALCULATE MAX_DEVIATION=0.01`
can be added to the custom start gcode of the slicer before the mesh is loaded.
It will abort the print if the configured limit is exceeded (0.01mm in this
example), giving the user a chance to adjust the screws and restart the print.

View File

@ -19,6 +19,7 @@ class ScrewsTiltAdjust:
self.config = config
self.printer = config.get_printer()
self.screws = []
self.max_diff = None
# Read config
for i in range(99):
prefix = "screw%d" % (i + 1,)
@ -51,11 +52,13 @@ class ScrewsTiltAdjust:
"of turns to level it."
def cmd_SCREWS_TILT_CALCULATE(self, gcmd):
self.max_diff = gcmd.get_float("MAX_DEVIATION", None)
self.probe_helper.start_probe(gcmd)
def probe_finalize(self, offsets, positions):
# Factors used for CW-M3, CCW-M3, CW-M4, CCW-M4, CW-M5 and CCW-M5
threads_factor = {0: 0.5, 1: 0.5, 2: 0.7, 3: 0.7, 4: 0.8, 5: 0.8}
screw_diff = []
# Process the read Z values and
for i, screw in enumerate(self.screws):
if i == 0:
@ -71,6 +74,7 @@ class ScrewsTiltAdjust:
z = positions[i][2]
coord, name = screw
diff = z_base - z
screw_diff.append(abs(diff))
if abs(diff) < 0.001:
adjust = 0
else:
@ -87,6 +91,10 @@ class ScrewsTiltAdjust:
"Adjust -> %s %02d:%02d" %
(name, coord[0], coord[1], z, sign,
abs(full_turns), abs(minutes)))
if self.max_diff and any((d > self.max_diff) for d in screw_diff):
raise self.gcode.error(
"bed level exceeds configured limits ({}mm)! " \
"Adjust screws and restart print.".format(self.max_diff))
def load_config(config):
return ScrewsTiltAdjust(config)

View File

@ -5,3 +5,4 @@ DICTIONARY atmega2560.dict
# Simple script to test
G28
SCREWS_TILT_CALCULATE
SCREWS_TILT_CALCULATE MAX_DEVIATION=0.01