From 596f5e3e3a0e9cdde47fe1975e13c0b5c166bf34 Mon Sep 17 00:00:00 2001 From: David Smith Date: Mon, 10 Feb 2020 22:34:11 -0500 Subject: [PATCH] stepper_enable: Add SET_STEPPER_ENABLE gcode command (#2463) Signed-off-by: David Smith --- docs/G-Codes.md | 6 ++++++ klippy/extras/stepper_enable.py | 31 ++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 611c3877..cbc2544f 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -161,6 +161,12 @@ The following standard commands are supported: [SMOOTH_TIME=]`: Set pressure advance parameters. If EXTRUDER is not specified, it defaults to the active extruder. +- `SET_STEPPER_ENABLE STEPPER= ENABLE=[0|1]`: Enable or + disable only the given stepper. This is a diagnostic and debugging + tool and must be used with care. Disabling an axis motor does not + reset the homing information. Manually moving a disabled stepper may + cause the machine to operate the motor outside of safe limits. This + can lead to damage to axis components, hot ends, and print surface. - `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. diff --git a/klippy/extras/stepper_enable.py b/klippy/extras/stepper_enable.py index a21c0f98..cad7b58c 100644 --- a/klippy/extras/stepper_enable.py +++ b/klippy/extras/stepper_enable.py @@ -74,9 +74,12 @@ class PrinterStepperEnable: self.printer.register_event_handler("gcode:request_restart", self._handle_request_restart) # Register M18/M84 commands - gcode = self.printer.lookup_object('gcode') - gcode.register_command("M18", self.cmd_M18) - gcode.register_command("M84", self.cmd_M18) + self.gcode = self.printer.lookup_object('gcode') + self.gcode.register_command("M18", self.cmd_M18) + self.gcode.register_command("M84", self.cmd_M18) + self.gcode.register_command("SET_STEPPER_ENABLE", + self.cmd_SET_STEPPER_ENABLE, + desc = self.cmd_SET_STEPPER_ENABLE_help) def register_stepper(self, stepper, pin): name = stepper.get_name() self.enable_lines[name] = EnableTracking(self.printer, stepper, pin) @@ -89,11 +92,33 @@ class PrinterStepperEnable: self.printer.send_event("stepper_enable:motor_off", print_time) toolhead.dwell(DISABLE_STALL_TIME) logging.debug('; Max time of %f', print_time) + def motor_debug_enable(self, stepper=None, enable=1): + toolhead = self.printer.lookup_object('toolhead') + toolhead.dwell(DISABLE_STALL_TIME) + print_time = toolhead.get_last_move_time() + if stepper in self.enable_lines: + el = self.enable_lines.get(stepper, "") + if enable: + el.motor_enable(print_time) + logging.info("%s has been manually enabled", stepper) + else: + el.motor_disable(print_time) + logging.info("%s has been manually disabled", stepper) + else: + self.gcode.respond_info('SET_STEPPER_ENABLE: Invalid stepper "%s"' + % (stepper)) + toolhead.dwell(DISABLE_STALL_TIME) + logging.debug('; Max time of %f', print_time) def _handle_request_restart(self, print_time): self.motor_off() def cmd_M18(self, params): # Turn off motors self.motor_off() + cmd_SET_STEPPER_ENABLE_help = "Enable/disable individual stepper by name" + def cmd_SET_STEPPER_ENABLE(self, params): + stepper_name = self.gcode.get_str('STEPPER', params, None) + stepper_enable = self.gcode.get_int('ENABLE', params, 1) + self.motor_debug_enable(stepper_name, stepper_enable) def lookup_enable(self, name): if name not in self.enable_lines: raise self.printer.config_error("Unknown stepper '%s'" % (name,))