2018-06-14 19:01:22 +03:00
|
|
|
# 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
|
2018-06-14 20:44:01 +03:00
|
|
|
import chelper
|
|
|
|
|
|
|
|
BUZZ_VELOCITY = 4.
|
2018-06-14 19:01:22 +03:00
|
|
|
|
|
|
|
class StepperBuzz:
|
|
|
|
def __init__(self, config):
|
|
|
|
self.printer = config.get_printer()
|
|
|
|
self.steppers = {}
|
2018-06-14 20:44:01 +03:00
|
|
|
# Setup iterative solver
|
|
|
|
ffi_main, ffi_lib = chelper.get_ffi()
|
|
|
|
self.cmove = ffi_main.gc(ffi_lib.move_alloc(), ffi_lib.free)
|
|
|
|
self.move_fill = ffi_lib.move_fill
|
|
|
|
self.stepper_kinematics = ffi_main.gc(
|
|
|
|
ffi_lib.cartesian_stepper_alloc('x'), ffi_lib.free)
|
2018-06-14 19:01:22 +03:00
|
|
|
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)
|
2018-06-14 20:44:01 +03:00
|
|
|
def manual_move(self, print_time, stepper, start_pos, dist):
|
|
|
|
self.move_fill(
|
|
|
|
self.cmove, print_time, 0., abs(dist / BUZZ_VELOCITY), 0.,
|
|
|
|
start_pos, 0., 0., dist, 0., 0., 0., BUZZ_VELOCITY, 0.)
|
|
|
|
stepper.step_itersolve(self.cmove)
|
2018-06-14 19:01:22 +03:00
|
|
|
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]
|
2018-06-22 00:58:18 +03:00
|
|
|
need_motor_enable = not stepper.is_motor_enabled()
|
2018-06-14 19:01:22 +03:00
|
|
|
# Move stepper
|
|
|
|
toolhead = self.printer.lookup_object('toolhead')
|
|
|
|
toolhead.wait_moves()
|
2018-06-22 01:15:23 +03:00
|
|
|
pos = stepper.get_commanded_position()
|
2018-06-14 19:01:22 +03:00
|
|
|
print_time = toolhead.get_last_move_time()
|
|
|
|
if need_motor_enable:
|
|
|
|
stepper.motor_enable(print_time, 1)
|
|
|
|
print_time += .1
|
2018-06-22 01:15:23 +03:00
|
|
|
was_ignore = stepper.set_ignore_move(False)
|
|
|
|
prev_sk = stepper.setup_itersolve(self.stepper_kinematics)
|
2018-06-14 19:01:22 +03:00
|
|
|
for i in range(10):
|
2018-06-14 20:44:01 +03:00
|
|
|
self.manual_move(print_time, stepper, 0., 1.)
|
2018-06-14 19:01:22 +03:00
|
|
|
print_time += .3
|
2018-06-14 20:44:01 +03:00
|
|
|
self.manual_move(print_time, stepper, 1., -1.)
|
2018-06-14 19:01:22 +03:00
|
|
|
toolhead.reset_print_time(print_time + .7)
|
|
|
|
print_time = toolhead.get_last_move_time()
|
2018-06-22 01:15:23 +03:00
|
|
|
stepper.setup_itersolve(prev_sk)
|
|
|
|
stepper.set_ignore_move(was_ignore)
|
2018-06-14 19:01:22 +03:00
|
|
|
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)
|