Skip to content

Commit

Permalink
add adaptive option for horizontal z move
Browse files Browse the repository at this point in the history
  • Loading branch information
bwnance committed Jul 12, 2024
1 parent 24265bd commit 2e8abf3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
20 changes: 19 additions & 1 deletion klippy/extras/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
import pins
import math
from . import manual_probe

HINT_TIMEOUT = """
Expand Down Expand Up @@ -493,6 +494,12 @@ def __init__(
)
def_move_z = config.getfloat("horizontal_move_z", 5.0)
self.default_horizontal_move_z = def_move_z
self.adaptive_horizontal_move_z = config.getboolean(
"adaptive_horizontal_move_z", False
)
self.adaptive_horizontal_move_z_clearance = config.getfloat(
"adaptive_horizontal_move_z_clearance", 1.0
)
self.speed = config.getfloat("speed", 50.0, above=0.0)
self.use_offsets = False
# Internal probing state
Expand Down Expand Up @@ -531,7 +538,16 @@ def _move_next(self):
if len(self.results) >= len(self.probe_points):
toolhead.get_last_move_time()
res = self.finalize_callback(self.probe_offsets, self.results)
if res != "retry":
if isinstance(res, [int, float]):
if res == 0:
return True
if self.adaptive_horizontal_move_z:
# then res is error
error = math.ceil(res)
self.horizontal_move_z = (
error + self.adaptive_horizontal_move_z_clearance
)
elif res != "retry":
return True
self.results = []
# Move to next XY probe point
Expand All @@ -548,8 +564,10 @@ def start_probe(self, gcmd):
probe = self.printer.lookup_object("probe", None)
method = gcmd.get("METHOD", "automatic").lower()
self.results = []

def_move_z = self.default_horizontal_move_z
self.horizontal_move_z = gcmd.get_float("HORIZONTAL_MOVE_Z", def_move_z)

if probe is None or method != "automatic":
# Manual probe
self.lift_speed = self.speed
Expand Down
6 changes: 3 additions & 3 deletions klippy/extras/z_tilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self, printer):
)

def check_retry_result(self, retry_result):
if retry_result == "done":
if int(retry_result) == 0 or retry_result == "done":
self.applied = True
return retry_result

Expand Down Expand Up @@ -155,11 +155,11 @@ def check_retry(self, z_positions):
% (self.value_label, self.error_msg_extra)
)
if error <= self.retry_tolerance:
return "done"
return 0.0
self.current_retry += 1
if self.current_retry > self.max_retries:
raise self.gcode.error("Too many retries")
return "retry"
return error


class ZTilt:
Expand Down

0 comments on commit 2e8abf3

Please sign in to comment.