diff options
author | fess <fess@fess.org> | 2019-06-17 19:39:57 -0700 |
---|---|---|
committer | KevinOConnor <kevin@koconnor.net> | 2019-06-18 12:12:25 -0400 |
commit | 46817752199adf4019dd5d8a74ad3d0f5986a49e (patch) | |
tree | ab49a77a76450df0b57ea03ff24b1ab38b64720b /klippy | |
parent | bdf5898891568dd12ab04cb1a032a1fd31761467 (diff) | |
download | kutter-46817752199adf4019dd5d8a74ad3d0f5986a49e.tar.gz kutter-46817752199adf4019dd5d8a74ad3d0f5986a49e.tar.xz kutter-46817752199adf4019dd5d8a74ad3d0f5986a49e.zip |
z_tilt: Add RetryHelper
add RetryHelper class in prep for implementing retries for both z_tilt
and quad_gantry_level
Signed-off-by: John "Fess" Fessenden <fess@fess.org>
Diffstat (limited to 'klippy')
-rw-r--r-- | klippy/extras/z_tilt.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/klippy/extras/z_tilt.py b/klippy/extras/z_tilt.py index 5d984004..69ac946f 100644 --- a/klippy/extras/z_tilt.py +++ b/klippy/extras/z_tilt.py @@ -61,6 +61,50 @@ class ZAdjustHelper: toolhead.set_position(curpos) gcode.reset_last_position() +class RetryHelper: + def __init__(self, config, error_msg_extra = ""): + self.gcode = config.get_printer().lookup_object('gcode') + self.default_max_retries = config.getint("retries", 0, minval=0) + self.default_retry_tolerance = \ + config.getfloat("retry_tolerance", 0., above=0.) + self.value_label = "Probed points range" + self.error_msg_extra = error_msg_extra + def start(self, params): + self.max_retries = self.gcode.get_int('RETRIES', params, + default=self.default_max_retries, minval=0, maxval=30) + self.retry_tolerance = self.gcode.get_float('RETRY_TOLERANCE', params, + default=self.default_retry_tolerance, minval=0, maxval=1.0) + self.current_retry = 0 + self.previous = None + self.increasing = 0 + def check_increase(self,error): + if self.previous and error > self.previous + 0.0000001: + self.increasing += 1 + elif self.increasing > 0: + self.increasing -= 1 + self.previous = error + return self.increasing > 1 + def check_retry(self,z_positions): + if self.max_retries == 0: + return + error = max(z_positions) - min(z_positions) + if self.check_increase(error): + self.gcode.respond_error( + "Retries aborting: %s is increasing. %s" % ( + self.value_label, self.error_msg_extra)) + return + self.gcode.respond_info( + "Retries: %d/%d %s: %0.6f tolerance: %0.6f" % ( + self.current_retry, self.max_retries, self.value_label, + error, self.retry_tolerance)) + if error <= self.retry_tolerance: + return "done" + self.current_retry += 1 + if self.current_retry > self.max_retries: + self.gcode.respond_error("Too many retries") + return + return "retry" + class ZTilt: def __init__(self, config): self.printer = config.get_printer() |