From ee4f37fe0c61dd525d4f03e800da38c42781b66f Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 24 May 2018 09:42:33 -0400 Subject: [PATCH] stepper: Add STEPPER_BUZZ command Add a new command that can help diagnose stepper motor connectivity. Signed-off-by: Kevin O'Connor --- docs/G-Codes.md | 3 +++ klippy/mcu.py | 3 +++ klippy/stepper.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 009debc1..65f01f9d 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -88,6 +88,9 @@ The following standard commands are supported: [ADVANCE_LOOKAHEAD_TIME=]`: Set pressure advance parameters. If EXTRUDER is not specified, it defaults to the active extruder. +- `STEPPER_BUZZ STEPPER=`: 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 diff --git a/klippy/mcu.py b/klippy/mcu.py index 1bfb14c1..7f1f7f51 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -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) diff --git a/klippy/stepper.py b/klippy/stepper.py index 8767fd12..aac7a96f 100644 --- a/klippy/stepper.py +++ b/klippy/stepper.py @@ -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):