screws_tilt_adjust: Add DIRECTION parameter to SCREWS_TILT_CALCULATE (#4357)
Signed-off-by: Matthew Lloyd <github@matthewlloyd.net>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# Helper script to adjust bed screws tilt using Z probe
|
||||
#
|
||||
# Copyright (C) 2019 Rui Caridade <rui.mcbc@gmail.com>
|
||||
# Copyright (C) 2021 Matthew Lloyd <github@matthewlloyd.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import math
|
||||
@@ -53,44 +54,64 @@ class ScrewsTiltAdjust:
|
||||
|
||||
def cmd_SCREWS_TILT_CALCULATE(self, gcmd):
|
||||
self.max_diff = gcmd.get_float("MAX_DEVIATION", None)
|
||||
# Option to force all turns to be in the given direction (CW or CCW)
|
||||
direction = gcmd.get("DIRECTION", default=None)
|
||||
if direction is not None:
|
||||
direction = direction.upper()
|
||||
if direction not in ('CW', 'CCW'):
|
||||
raise gcmd.error(
|
||||
"Error on '%s': DIRECTION must be either CW or CCW" % (
|
||||
gcmd.get_commandline(),))
|
||||
self.direction = direction
|
||||
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}
|
||||
is_clockwise_thread = (self.thread & 1) == 0
|
||||
screw_diff = []
|
||||
# Process the read Z values and
|
||||
# Process the read Z values
|
||||
if self.direction is not None:
|
||||
# Lowest or highest screw is the base position used for comparison
|
||||
use_max = ((is_clockwise_thread and self.direction == 'CW')
|
||||
or (not is_clockwise_thread and self.direction == 'CCW'))
|
||||
min_or_max = max if use_max else min
|
||||
i_base, z_base = min_or_max(
|
||||
enumerate([pos[2] for pos in positions]), key=lambda (i, z): z)
|
||||
else:
|
||||
# First screw is the base position used for comparison
|
||||
i_base, z_base = 0, positions[0][2]
|
||||
# Provide the user some information on how to read the results
|
||||
self.gcode.respond_info("01:20 means 1 full turn and 20 minutes, "
|
||||
"CW=clockwise, CCW=counter-clockwise")
|
||||
for i, screw in enumerate(self.screws):
|
||||
if i == 0:
|
||||
# First screw is the base position used for comparison
|
||||
z_base = positions[i][2]
|
||||
coord_base, name_base = screw
|
||||
z = positions[i][2]
|
||||
coord, name = screw
|
||||
if i == i_base:
|
||||
# Show the results
|
||||
self.gcode.respond_info("%s (Base): X %.1f, Y %.1f, Z %.5f" %
|
||||
(name_base, coord_base[0],
|
||||
coord_base[1], z_base))
|
||||
self.gcode.respond_info(
|
||||
"%s : x=%.1f, y=%.1f, z=%.5f" %
|
||||
(name + ' (base)', coord[0], coord[1], z))
|
||||
else:
|
||||
# Calculate how knob must me adjusted for other positions
|
||||
z = positions[i][2]
|
||||
coord, name = screw
|
||||
# Calculate how knob must be adjusted for other positions
|
||||
diff = z_base - z
|
||||
screw_diff.append(abs(diff))
|
||||
if abs(diff) < 0.001:
|
||||
adjust = 0
|
||||
else:
|
||||
adjust = diff / threads_factor.get(self.thread, 0.5)
|
||||
if (self.thread & 1) == 1:
|
||||
sign = "CW" if adjust < 0 else "CCW"
|
||||
if is_clockwise_thread:
|
||||
sign = "CW" if adjust >= 0 else "CCW"
|
||||
else:
|
||||
sign = "CCW" if adjust < 0 else "CW"
|
||||
sign = "CCW" if adjust >= 0 else "CW"
|
||||
adjust = abs(adjust)
|
||||
full_turns = math.trunc(adjust)
|
||||
decimal_part = adjust - full_turns
|
||||
minutes = round(decimal_part * 60, 0)
|
||||
# Show the results
|
||||
self.gcode.respond_info("%s : X %.1f, Y %.1f, Z %.5f : "
|
||||
"Adjust -> %s %02d:%02d" %
|
||||
(name, coord[0], coord[1], z, sign,
|
||||
abs(full_turns), abs(minutes)))
|
||||
self.gcode.respond_info(
|
||||
"%s : x=%.1f, y=%.1f, z=%.5f : adjust %s %02d:%02d" %
|
||||
(name, coord[0], coord[1], z, sign, full_turns, 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)! " \
|
||||
|
Reference in New Issue
Block a user