stepper_buzz: Move STEPPER_BUZZ command from stepper.py to new file

Add a klippy/extras/stepper_buzz.py file to handle the STEPPER_BUZZ
command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-06-14 12:01:22 -04:00
parent c60c9ee302
commit bedbfceafc
2 changed files with 49 additions and 28 deletions

View File

@ -0,0 +1,47 @@
# Utility for moving a stepper back and forth to help identify it
#
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
class StepperBuzz:
def __init__(self, config):
self.printer = config.get_printer()
self.steppers = {}
def register_stepper(self, stepper, name):
self.steppers[name] = stepper
# Register STEPPER_BUZZ command
self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_mux_command(
'STEPPER_BUZZ', 'STEPPER', name, self.cmd_STEPPER_BUZZ,
desc=self.cmd_STEPPER_BUZZ_help)
cmd_STEPPER_BUZZ_help = "Oscillate a given stepper to help id it"
def cmd_STEPPER_BUZZ(self, params):
name = self.gcode.get_str('STEPPER', params)
logging.info("Stepper buzz %s", name)
stepper = self.steppers[name]
need_motor_enable = stepper.need_motor_enable
# Move stepper
toolhead = self.printer.lookup_object('toolhead')
toolhead.wait_moves()
pos = stepper.mcu_stepper.get_commanded_position()
print_time = toolhead.get_last_move_time()
if need_motor_enable:
stepper.motor_enable(print_time, 1)
print_time += .1
was_ignore = stepper.mcu_stepper.set_ignore_move(False)
for i in range(10):
stepper.step_const(print_time, pos, 1., 4., 0.)
print_time += .3
stepper.step_const(print_time, pos + 1., -1., 4., 0.)
toolhead.reset_print_time(print_time + .7)
print_time = toolhead.get_last_move_time()
stepper.mcu_stepper.set_ignore_move(was_ignore)
if need_motor_enable:
print_time += .1
stepper.motor_enable(print_time, 0)
toolhead.reset_print_time(print_time)
def load_config(config):
return StepperBuzz(config)

View File

@ -52,10 +52,8 @@ class PrinterStepper:
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)
stepper_buzz = printer.try_load_module(config, 'stepper_buzz')
stepper_buzz.register_stepper(self, config.get_name())
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
@ -74,30 +72,6 @@ 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):