Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adaptive horizontal move z #336

Merged
merged 2 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ See the [Danger Features document](https://dangerklipper.io/Danger_Features.html

- [mcu: support for AT32F403](https://github.com/DangerKlippers/danger-klipper/pull/284)

- [z_tilt, quad_gantry_level: adaptive horizontal move z](https://github.com/DangerKlippers/danger-klipper/pull/336)

If you're feeling adventurous, take a peek at the extra features in the bleeding-edge-v2 branch [feature documentation](docs/Bleeding_Edge.md)
and [feature configuration reference](docs/Config_Reference_Bleeding_Edge.md):

Expand Down
23 changes: 23 additions & 0 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,15 @@ extended [G-Code command](G-Codes.md#z_tilt) becomes available.
#horizontal_move_z: 5
# The height (in mm) that the head should be commanded to move to
# just prior to starting a probe operation. The default is 5.
#min_horizontal_move_z: 1.0
# minimum value for horizontal move z
# (only used when adaptive_horizontal_move_z is True)
#adaptive_horizontal_move_z: False
# if we should adjust horizontal move z after the first adjustment round,
# based on error.
# when set to True, initial horizontal_move_z is the config value,
# subsequent iterations will set horizontal_move_z to
# the ceil of error, or min_horizontal_move_z - whichever is greater.
#retries: 0
# Number of times to retry if the probed points aren't within
# tolerance.
Expand All @@ -1391,6 +1400,7 @@ extended [G-Code command](G-Codes.md#z_tilt) becomes available.
#increasing_threshold: 0.0000001
# Sets the threshold that probe points can increase before z_tilt aborts.
# To disable the validation, set this parameter to a high value.

```

#### [z_tilt_ng]
Expand All @@ -1413,6 +1423,10 @@ extended [G-Code command](G-Codes.md#z_tilt) becomes available.
# See [z_tilt]
#horizontal_move_z: 5
# See [z_tilt]
#min_horizontal_move_z: 1.0
# See [z_tilt]
#adaptive_horizontal_move_z: False
# See [z_tilt]
#retries: 0
# See [z_tilt]
#retry_tolerance: 0
Expand Down Expand Up @@ -1487,6 +1501,15 @@ Where x is the 0, 0 point on the bed
#horizontal_move_z: 5
# The height (in mm) that the head should be commanded to move to
# just prior to starting a probe operation. The default is 5.
#min_horizontal_move_z: 1.0
# minimum value for horizontal move z
# (only used when adaptive_horizontal_move_z is True)
#adaptive_horizontal_move_z: False
# if we should adjust horizontal move z after the first adjustment round,
# based on error.
# when set to True, initial horizontal_move_z is the config value,
# subsequent iterations will set horizontal_move_z to
# the ceil of error, or min_horizontal_move_z - whichever is greater.
#max_adjust: 4
# Safety limit if an adjustment greater than this value is requested
# quad_gantry_level will abort.
Expand Down
2 changes: 1 addition & 1 deletion docs/Danger_Features.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
- [`[z_calibration]`](./Config_Reference.md#⚠️-z_calibration) enables automatic probe Z offset calibration using a reference endstop like the Voron 2.4 nozzle endstop.
- [`[z_tilt_ng]`](./Config_Reference.md#z_tilt_ng) adds enforced 3-point z tilt calibration
- [`[z_tilt/quad_gantry_level] increasing_threshold`](./Config_Reference.md#z_tilt) allows you to customize the allowed variation when probing multiple times

- [`[z_tilt/quad_gantry_level] adaptive_horizontal_move_z`](./Config_Reference.md#z_tilt) adaptively decrease horizontal_move_z based on resulting error - z_tilt and QGL faster and safer!
## Heaters, Fans, and PID changes
- [Model Predictive Control](./MPC.md) is an advanced temperature control method that offers an alternative to traditional PID control.
- [Velocity PID](./PID.md) can be more accurate than positional PID, but is more susceptible to noisy sensors and may require larger smoothing times
Expand Down
32 changes: 29 additions & 3 deletions 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.min_horizontal_move_z = config.getfloat(
"min_horizontal_move_z", 1.0
)
self.speed = config.getfloat("speed", 50.0, above=0.0)
self.use_offsets = False
# Internal probing state
Expand All @@ -519,21 +526,38 @@ def use_xy_offsets(self, use_offsets):
def get_lift_speed(self):
return self.lift_speed

def _move_next(self):
def _lift_toolhead(self):
toolhead = self.printer.lookup_object("toolhead")
# Lift toolhead
speed = self.lift_speed
if not self.results:
# Use full speed to first probe position
speed = self.speed
toolhead.manual_move([None, None, self.horizontal_move_z], speed)

def _move_next(self):
toolhead = self.printer.lookup_object("toolhead")
# Check if done probing
done = False
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":
return True
if isinstance(res, (int, float)):
if res == 0:
done = True
if self.adaptive_horizontal_move_z:
# then res is error
error = math.ceil(res)
self.horizontal_move_z = max(
error + self.probe_offsets[2],
self.min_horizontal_move_z,
)
elif res != "retry":
done = True
self.results = []
self._lift_toolhead()
if done:
return True
# Move to next XY probe point
nextpos = list(self.probe_points[len(self.results)])
if self.use_offsets:
Expand All @@ -548,8 +572,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 (retry_result and 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
6 changes: 3 additions & 3 deletions klippy/extras/z_tilt_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(self, printer):
)

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

Expand Down Expand Up @@ -177,11 +177,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
Loading