From 6c3db80d89f32bd399f4cd757aa4671d7b3b5da1 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 14 May 2018 11:18:31 -0400 Subject: [PATCH] homing: Apply speed rounding after calling home_prepare() The step speed rounding and the cpu delay must be run after running the endstop specific preparation code. Otherwise, a delay in the home_prepare() code could undo those calculations. Specifically, this could lead to errors on a multi-mcu setup when the Z is homed using a virtual_z_offset and there is a delay in the activate_gcode section. Signed-off-by: Kevin O'Connor --- klippy/homing.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/klippy/homing.py b/klippy/homing.py index 97879730..b3427854 100644 --- a/klippy/homing.py +++ b/klippy/homing.py @@ -40,10 +40,8 @@ class Homing: dist_ticks = adjusted_freq * mcu_stepper.get_step_dist() ticks_per_step = math.ceil(dist_ticks / speed) return dist_ticks / ticks_per_step - def homing_move(self, movepos, endstops, speed, probe_pos=False): + def _homing_move(self, movepos, endstops, speed, probe_pos=False): # Start endstop checking - for mcu_endstop, name in endstops: - mcu_endstop.home_prepare() print_time = self.toolhead.get_last_move_time() for mcu_endstop, name in endstops: min_step_dist = min([s.get_step_dist() @@ -76,6 +74,10 @@ class Homing: mcu_endstop.home_finalize() if error is not None: raise EndstopError(error) + def homing_move(self, movepos, endstops, speed, probe_pos=False): + for mcu_endstop, name in endstops: + mcu_endstop.home_prepare() + self._homing_move(movepos, endstops, speed, probe_pos) def home(self, forcepos, movepos, endstops, speed, second_home=False): if second_home and forcepos == movepos: return @@ -83,6 +85,9 @@ class Homing: homing_axes = [axis for axis in range(3) if forcepos[axis] is not None] self.toolhead.set_position( self._fill_coord(forcepos), homing_axes=homing_axes) + # Notify endstops of upcoming home + for mcu_endstop, name in endstops: + mcu_endstop.home_prepare() # Add a CPU delay when homing a large axis if not second_home: est_move_d = sum([abs(forcepos[i]-movepos[i]) @@ -96,7 +101,7 @@ class Homing: start_mcu_pos = [(s, name, s.get_mcu_position()) for es, name in endstops for s in es.get_steppers()] # Issue homing move - self.homing_move(movepos, endstops, speed) + self._homing_move(movepos, endstops, speed) # Verify retract led to some movement on second home if second_home and self.verify_retract: for s, name, pos in start_mcu_pos: