From 17c6d6433d194d10a08c677f00eb891324f9f63d Mon Sep 17 00:00:00 2001 From: Brandon Date: Tue, 19 Dec 2023 13:42:09 -0500 Subject: [PATCH] Sensorless retract dist fix (#109) * move retract_dist calc * conditionally retract --- klippy/extras/homing.py | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/klippy/extras/homing.py b/klippy/extras/homing.py index 4f43d7e2a..c1335a772 100644 --- a/klippy/extras/homing.py +++ b/klippy/extras/homing.py @@ -280,17 +280,15 @@ def home_rails(self, rails, forcepos, movepos): for i, dist in enumerate(hmove.distance_elapsed) if i in homing_axes ] - + needs_rehome = False + retract_dist = hi.retract_dist + if any( + [abs(dist) < hi.min_home_dist for dist in homing_axis_distances] + ): + needs_rehome = True + retract_dist = hi.min_home_dist # Perform second home - if hi.retract_dist: - needs_rehome = False - retract_dist = hi.retract_dist - if any( - [abs(dist) < hi.min_home_dist for dist in homing_axis_distances] - ): - needs_rehome = True - retract_dist = hi.min_home_dist - + if retract_dist: logging.info("needs rehome: %s", needs_rehome) # Retract startpos = self._fill_coord(forcepos) @@ -321,17 +319,17 @@ def home_rails(self, rails, forcepos, movepos): "Endstop %s still triggered after retract" % (hmove.check_no_movement(),) ) - - # Retract (again) - startpos = self._fill_coord(forcepos) - homepos = self._fill_coord(movepos) - axes_d = [hp - sp for hp, sp in zip(homepos, startpos)] - move_d = math.sqrt(sum([d * d for d in axes_d[:3]])) - retract_r = min(1.0, hi.retract_dist / move_d) - retractpos = [ - hp - ad * retract_r for hp, ad in zip(homepos, axes_d) - ] - self.toolhead.move(retractpos, hi.retract_speed) + if hi.retract_dist: + # Retract (again) + startpos = self._fill_coord(forcepos) + homepos = self._fill_coord(movepos) + axes_d = [hp - sp for hp, sp in zip(homepos, startpos)] + move_d = math.sqrt(sum([d * d for d in axes_d[:3]])) + retract_r = min(1.0, hi.retract_dist / move_d) + retractpos = [ + hp - ad * retract_r for hp, ad in zip(homepos, axes_d) + ] + self.toolhead.move(retractpos, hi.retract_speed) self._set_current_post_homing(homing_axes) # Signal home operation complete self.toolhead.flush_step_generation()