Skip to content

Commit

Permalink
screws_tilt_adjust: Add get_status() method (#5921)
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Meredith <[email protected]>
  • Loading branch information
theophile authored Dec 17, 2022
1 parent 3c1ed3b commit 2a25733
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/Status_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,28 @@ The following information is available in the `query_endstops` object
the QUERY_ENDSTOP command must be run prior to the macro containing
this reference.

## screws_tilt_adjust

The following information is available in the `screws_tilt_adjust`
object:
- `error`: Returns True if the most recent `SCREWS_TILT_CALCULATE`
command included the `MAX_DEVIATION` parameter and any of the probed
screw points exceeded the specified `MAX_DEVIATION`.
- `results`: A list of the probed screw locations. Each entry in
the list will be a dictionary containing the following keys:
- `name`: The name of the screw as specified in the config file.
- `x`: The X coordinate of the screw as specified in the config file.
- `y`: The Y coordinate of the screw as specified in the config file.
- `z`: The measured Z height of the screw location.
- `sign`: A string specifying the direction to turn to screw for the
necessary adjustment. Either "CW" for clockwise or "CCW" for
counterclockwise. The base screw will not have a `sign` key.
- `adjust`: The number of screw turns to adjust the screw, given in
the format "HH:MM," where "HH" is the number of full screw turns
and "MM" is the number of "minutes of a clock face" representing
a partial screw turn. (E.g. "01:15" would mean to turn the screw
one and a quarter revolutions.)

## servo

The following information is available in
Expand Down
14 changes: 14 additions & 0 deletions klippy/extras/screws_tilt_adjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def __init__(self, config):
self.config = config
self.printer = config.get_printer()
self.screws = []
self.results = []
self.max_diff = None
self.max_diff_error = False
# Read config
for i in range(99):
prefix = "screw%d" % (i + 1,)
Expand Down Expand Up @@ -57,7 +59,13 @@ def cmd_SCREWS_TILT_CALCULATE(self, gcmd):
self.direction = direction
self.probe_helper.start_probe(gcmd)

def get_status(self, eventtime):
return {'error': self.max_diff_error,
'results': self.results}

def probe_finalize(self, offsets, positions):
self.results = []
self.max_diff_error = False
# 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
Expand All @@ -84,6 +92,8 @@ def probe_finalize(self, offsets, positions):
self.gcode.respond_info(
"%s : x=%.1f, y=%.1f, z=%.5f" %
(name + ' (base)', coord[0], coord[1], z))
self.results.append({'name': name + ' (base)', 'x': coord[0],
'y': coord[1], 'z': z, 'sign': 'CW', 'adjust':'00:00'})
else:
# Calculate how knob must be adjusted for other positions
diff = z_base - z
Expand All @@ -104,7 +114,11 @@ def probe_finalize(self, offsets, positions):
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))
self.results.append({'name': name, 'x': coord[0], 'y': coord[1],
'z': z, 'sign': sign,
'adjust':"%02d:%02d" % (full_turns, minutes)})
if self.max_diff and any((d > self.max_diff) for d in screw_diff):
self.max_diff_error = True
raise self.gcode.error(
"bed level exceeds configured limits ({}mm)! " \
"Adjust screws and restart print.".format(self.max_diff))
Expand Down

0 comments on commit 2a25733

Please sign in to comment.