stepper: Add STEPPER_BUZZ command
Add a new command that can help diagnose stepper motor connectivity. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
e50c2aa38d
commit
ee4f37fe0c
|
@ -88,6 +88,9 @@ The following standard commands are supported:
|
|||
[ADVANCE_LOOKAHEAD_TIME=<pressure_advance_lookahead_time>]`:
|
||||
Set pressure advance parameters. If EXTRUDER is not specified, it
|
||||
defaults to the active extruder.
|
||||
- `STEPPER_BUZZ STEPPER=<config_name>`: Move the given stepper forward
|
||||
one mm and then backward one mm, repeated 10 times. This is a
|
||||
diagnostic tool to help verify stepper connectivity.
|
||||
- `RESTART`: This will cause the host software to reload its config
|
||||
and perform an internal reset. This command will not clear error
|
||||
state from the micro-controller (see FIRMWARE_RESTART) nor will it
|
||||
|
|
|
@ -78,12 +78,15 @@ class MCU_stepper:
|
|||
return int(mcu_pos + 0.5)
|
||||
return int(mcu_pos - 0.5)
|
||||
def set_ignore_move(self, ignore_move):
|
||||
was_ignore = (self._stepcompress_push_const
|
||||
is not self._ffi_lib.stepcompress_push_const)
|
||||
if ignore_move:
|
||||
self._stepcompress_push_const = (lambda *args: 0)
|
||||
self._stepcompress_push_delta = (lambda *args: 0)
|
||||
else:
|
||||
self._stepcompress_push_const = self._ffi_lib.stepcompress_push_const
|
||||
self._stepcompress_push_delta = self._ffi_lib.stepcompress_push_delta
|
||||
return was_ignore
|
||||
def note_homing_start(self, homing_clock):
|
||||
ret = self._ffi_lib.stepcompress_set_homing(
|
||||
self._stepqueue, homing_clock)
|
||||
|
|
|
@ -35,6 +35,7 @@ def lookup_enable_pin(ppins, pin):
|
|||
# Code storing the definitions for a stepper motor
|
||||
class PrinterStepper:
|
||||
def __init__(self, printer, config):
|
||||
self.printer = printer
|
||||
self.name = config.get_name()
|
||||
if self.name.startswith('stepper_'):
|
||||
self.name = self.name[8:]
|
||||
|
@ -50,6 +51,11 @@ class PrinterStepper:
|
|||
self.step_const = self.mcu_stepper.step_const
|
||||
self.step_delta = self.mcu_stepper.step_delta
|
||||
self.enable = lookup_enable_pin(ppins, config.get('enable_pin', None))
|
||||
# Register STEPPER_BUZZ command
|
||||
self.gcode = printer.lookup_object('gcode')
|
||||
self.gcode.register_mux_command(
|
||||
'STEPPER_BUZZ', 'STEPPER', config.get_name(), self.cmd_STEPPER_BUZZ,
|
||||
desc=self.cmd_STEPPER_BUZZ_help)
|
||||
def _dist_to_time(self, dist, start_velocity, accel):
|
||||
# Calculate the time it takes to travel a distance with constant accel
|
||||
time_offset = start_velocity / accel
|
||||
|
@ -68,6 +74,30 @@ class PrinterStepper:
|
|||
if self.need_motor_enable != (not enable):
|
||||
self.enable.set_enable(print_time, enable)
|
||||
self.need_motor_enable = not enable
|
||||
cmd_STEPPER_BUZZ_help = "Oscillate a given stepper to help id it"
|
||||
def cmd_STEPPER_BUZZ(self, params):
|
||||
logging.info("Stepper buzz %s", self.name)
|
||||
need_motor_enable = self.need_motor_enable
|
||||
# Move stepper
|
||||
toolhead = self.printer.lookup_object('toolhead')
|
||||
toolhead.wait_moves()
|
||||
pos = self.mcu_stepper.get_commanded_position()
|
||||
print_time = toolhead.get_last_move_time()
|
||||
if need_motor_enable:
|
||||
self.motor_enable(print_time, 1)
|
||||
print_time += .1
|
||||
was_ignore = self.mcu_stepper.set_ignore_move(False)
|
||||
for i in range(10):
|
||||
self.step_const(print_time, pos, 1., 4., 0.)
|
||||
print_time += .3
|
||||
self.step_const(print_time, pos + 1., -1., 4., 0.)
|
||||
toolhead.reset_print_time(print_time + .7)
|
||||
print_time = toolhead.get_last_move_time()
|
||||
self.mcu_stepper.set_ignore_move(was_ignore)
|
||||
if need_motor_enable:
|
||||
print_time += .1
|
||||
self.motor_enable(print_time, 0)
|
||||
toolhead.reset_print_time(print_time)
|
||||
|
||||
# Support for stepper controlled linear axis with an endstop
|
||||
class PrinterHomingStepper(PrinterStepper):
|
||||
|
|
Loading…
Reference in New Issue