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 <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2025-09-01 14:22:36 -04:00
parent 1f14e950e7
commit 5056e1031c
2 changed files with 15 additions and 9 deletions

View File

@ -49,11 +49,9 @@ class ManualStepper:
else: else:
self.next_cmd_time = print_time self.next_cmd_time = print_time
def do_enable(self, enable): def do_enable(self, enable):
self.sync_print_time()
stepper_names = [s.get_name() for s in self.steppers] stepper_names = [s.get_name() for s in self.steppers]
stepper_enable = self.printer.lookup_object('stepper_enable') stepper_enable = self.printer.lookup_object('stepper_enable')
stepper_enable.set_motors_enable(stepper_names, enable) stepper_enable.set_motors_enable(stepper_names, enable)
self.sync_print_time()
def do_set_position(self, setpos): def do_set_position(self, setpos):
toolhead = self.printer.lookup_object('toolhead') toolhead = self.printer.lookup_object('toolhead')
toolhead.flush_step_generation() toolhead.flush_step_generation()

View File

@ -1,6 +1,6 @@
# Support for enable pins on stepper motor drivers # Support for enable pins on stepper motor drivers
# #
# Copyright (C) 2019-2021 Kevin O'Connor <kevin@koconnor.net> # Copyright (C) 2019-2025 Kevin O'Connor <kevin@koconnor.net>
# #
# This file may be distributed under the terms of the GNU GPLv3 license. # This file may be distributed under the terms of the GNU GPLv3 license.
import logging import logging
@ -90,19 +90,27 @@ class PrinterStepperEnable:
self.enable_lines[name] = EnableTracking(mcu_stepper, enable) self.enable_lines[name] = EnableTracking(mcu_stepper, enable)
def set_motors_enable(self, stepper_names, enable): def set_motors_enable(self, stepper_names, enable):
toolhead = self.printer.lookup_object('toolhead') toolhead = self.printer.lookup_object('toolhead')
toolhead.dwell(DISABLE_STALL_TIME) # Flush steps to ensure all auto enable callbacks invoked
print_time = toolhead.get_last_move_time() toolhead.flush_step_generation()
print_time = None
did_change = False did_change = False
for stepper_name in stepper_names: for stepper_name in stepper_names:
el = self.enable_lines[stepper_name] 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: if enable:
el.motor_enable(print_time) el.motor_enable(print_time)
else: else:
el.motor_disable(print_time) el.motor_disable(print_time)
if was_enabled != el.is_motor_enabled(): did_change = True
did_change = True # Dwell to ensure sufficient delay prior to a future auto enable
toolhead.dwell(DISABLE_STALL_TIME) if did_change and not enable:
toolhead.dwell(DISABLE_STALL_TIME)
return did_change return did_change
def motor_off(self): def motor_off(self):
self.set_motors_enable(self.get_steppers(), False) self.set_motors_enable(self.get_steppers(), False)