From a47811645e1ead5317c00c9f7bd38ae4307ea78e Mon Sep 17 00:00:00 2001 From: Morton Jonuschat Date: Fri, 10 May 2024 11:12:38 -0700 Subject: [PATCH] bugfix: restore run_current after sensorless homing (#233) When utilizing home_current + sensorless homing the run_current is not being restored after homing was completed. - The needs_home_current_change check will be fales because run_current at that time is equal to home_current - The short circuit code in most drivers is triggering falsely because it's comparing the previous run current to the requested run_current and not looking at the currently set run current, thus never setting this even after switch to a `needs_run_current_change` helper in the condition. --- klippy/extras/homing.py | 2 +- klippy/extras/tmc2130.py | 5 ++++- klippy/extras/tmc2240.py | 5 ++++- klippy/extras/tmc2660.py | 3 +++ klippy/extras/tmc5160.py | 5 ++++- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/klippy/extras/homing.py b/klippy/extras/homing.py index 2dff044c6..56b4cb84d 100644 --- a/klippy/extras/homing.py +++ b/klippy/extras/homing.py @@ -281,7 +281,7 @@ def _set_current_post_homing(self, homing_axes): chs = rail.get_tmc_current_helpers() dwell_time = None for ch in chs: - if ch is not None and ch.needs_home_current_change(): + if ch is not None and ch.needs_run_current_change(): if dwell_time is None: dwell_time = ch.current_change_dwell_time ch.set_current_for_normal(print_time) diff --git a/klippy/extras/tmc2130.py b/klippy/extras/tmc2130.py index 95df2ee85..b34680b6f 100644 --- a/klippy/extras/tmc2130.py +++ b/klippy/extras/tmc2130.py @@ -230,6 +230,9 @@ def __init__(self, config, mcu_tmc): def needs_home_current_change(self): return self._home_current != self.run_current + def needs_run_current_change(self): + return self._prev_current != self.run_current + def set_home_current(self, new_home_current): self._home_current = min(MAX_CURRENT, new_home_current) @@ -281,7 +284,7 @@ def get_current(self): def set_current(self, run_current, hold_current, print_time, force=False): if ( - run_current == self._prev_current + run_current == self.run_current and hold_current == self.req_hold_current and not force ): diff --git a/klippy/extras/tmc2240.py b/klippy/extras/tmc2240.py index 23fc71408..2fe209844 100644 --- a/klippy/extras/tmc2240.py +++ b/klippy/extras/tmc2240.py @@ -300,6 +300,9 @@ def __init__(self, config, mcu_tmc): def needs_home_current_change(self): return self._home_current != self.run_current + def needs_run_current_change(self): + return self._prev_current != self.run_current + def set_home_current(self, new_home_current): self._home_current = min(self.max_cur, new_home_current) @@ -360,7 +363,7 @@ def get_current(self): def set_current(self, run_current, hold_current, print_time, force=False): if ( - run_current == self._prev_current + run_current == self.run_current and hold_current == self.req_hold_current and not force ): diff --git a/klippy/extras/tmc2660.py b/klippy/extras/tmc2660.py index fc334ea24..64021f8c2 100644 --- a/klippy/extras/tmc2660.py +++ b/klippy/extras/tmc2660.py @@ -150,6 +150,9 @@ def __init__(self, config, mcu_tmc): def needs_home_current_change(self): return self._home_current != self.current + def needs_run_current_change(self): + return self._prev_current != self.current + def set_home_current(self, new_home_current): self._home_current = min(MAX_CURRENT, new_home_current) diff --git a/klippy/extras/tmc5160.py b/klippy/extras/tmc5160.py index 54c081ad9..b00b992bd 100644 --- a/klippy/extras/tmc5160.py +++ b/klippy/extras/tmc5160.py @@ -283,6 +283,9 @@ def __init__(self, config, mcu_tmc): def needs_home_current_change(self): return self._home_current != self.run_current + def needs_run_current_change(self): + return self._prev_current != self.run_current + def set_home_current(self, new_home_current): self._home_current = min(MAX_CURRENT, new_home_current) @@ -338,7 +341,7 @@ def get_current(self): def set_current(self, run_current, hold_current, print_time, force=False): if ( - run_current == self._prev_current + run_current == self.run_current and hold_current == self.req_hold_current and not force ):