From 5056e1031c92f279caafe49fb8e2fb961dcbb9ad Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 1 Sep 2025 14:22:36 -0400 Subject: [PATCH] stepper_enable: Improve timing of manual stepper enable/disable commands Invoke flush_step_generation() prior to checking motor enable state as this is the best way to ensure all stepper active callbacks have been invoked (which could change the enable line state). Also, there is no longer a reason to add additional toolhead dwells when enabling a stepper motor. Signed-off-by: Kevin O'Connor --- klippy/extras/manual_stepper.py | 2 -- klippy/extras/stepper_enable.py | 22 +++++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/klippy/extras/manual_stepper.py b/klippy/extras/manual_stepper.py index a2ce57da..3c1b29b6 100644 --- a/klippy/extras/manual_stepper.py +++ b/klippy/extras/manual_stepper.py @@ -49,11 +49,9 @@ class ManualStepper: else: self.next_cmd_time = print_time def do_enable(self, enable): - self.sync_print_time() stepper_names = [s.get_name() for s in self.steppers] stepper_enable = self.printer.lookup_object('stepper_enable') stepper_enable.set_motors_enable(stepper_names, enable) - self.sync_print_time() def do_set_position(self, setpos): toolhead = self.printer.lookup_object('toolhead') toolhead.flush_step_generation() diff --git a/klippy/extras/stepper_enable.py b/klippy/extras/stepper_enable.py index cd3f4f73..926e9592 100644 --- a/klippy/extras/stepper_enable.py +++ b/klippy/extras/stepper_enable.py @@ -1,6 +1,6 @@ # Support for enable pins on stepper motor drivers # -# Copyright (C) 2019-2021 Kevin O'Connor +# Copyright (C) 2019-2025 Kevin O'Connor # # This file may be distributed under the terms of the GNU GPLv3 license. import logging @@ -90,19 +90,27 @@ class PrinterStepperEnable: self.enable_lines[name] = EnableTracking(mcu_stepper, enable) def set_motors_enable(self, stepper_names, enable): toolhead = self.printer.lookup_object('toolhead') - toolhead.dwell(DISABLE_STALL_TIME) - print_time = toolhead.get_last_move_time() + # Flush steps to ensure all auto enable callbacks invoked + toolhead.flush_step_generation() + print_time = None did_change = False for stepper_name in stepper_names: el = self.enable_lines[stepper_name] - was_enabled = el.is_motor_enabled() + if el.is_motor_enabled() == enable: + continue + if print_time is None: + # Dwell for sufficient delay from any previous auto enable + if not enable: + toolhead.dwell(DISABLE_STALL_TIME) + print_time = toolhead.get_last_move_time() if enable: el.motor_enable(print_time) else: el.motor_disable(print_time) - if was_enabled != el.is_motor_enabled(): - did_change = True - toolhead.dwell(DISABLE_STALL_TIME) + did_change = True + # Dwell to ensure sufficient delay prior to a future auto enable + if did_change and not enable: + toolhead.dwell(DISABLE_STALL_TIME) return did_change def motor_off(self): self.set_motors_enable(self.get_steppers(), False)