force_move: Simplify STEPPER_BUZZ code

Separate the setup and movement parts of cmd_STEPPER_BUZZ() into their
own functions.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-07-26 11:39:57 -04:00
parent 2c5eba44ee
commit a434341aa9
1 changed files with 35 additions and 26 deletions

View File

@ -7,6 +7,7 @@ import logging
import chelper import chelper
BUZZ_VELOCITY = 4. BUZZ_VELOCITY = 4.
STALL_TIME = 0.100
class ForceMove: class ForceMove:
def __init__(self, config): def __init__(self, config):
@ -25,41 +26,49 @@ class ForceMove:
def register_stepper(self, stepper): def register_stepper(self, stepper):
name = stepper.get_name() name = stepper.get_name()
self.steppers[name] = stepper self.steppers[name] = stepper
def manual_move(self, print_time, stepper, start_pos, dist): def force_enable(self, stepper):
self.move_fill( toolhead = self.printer.lookup_object('toolhead')
self.cmove, print_time, 0., abs(dist / BUZZ_VELOCITY), 0., print_time = toolhead.get_last_move_time()
start_pos, 0., 0., dist, 0., 0., 0., BUZZ_VELOCITY, 0.) was_enable = stepper.is_motor_enabled()
if not was_enable:
stepper.motor_enable(print_time, 1)
toolhead.dwell(STALL_TIME)
was_ignore = stepper.set_ignore_move(False)
return was_enable, was_ignore
def restore_enable(self, stepper, was_enable, was_ignore):
stepper.set_ignore_move(was_ignore)
if not was_enable:
toolhead = self.printer.lookup_object('toolhead')
toolhead.dwell(STALL_TIME)
print_time = toolhead.get_last_move_time()
stepper.motor_enable(print_time, 0)
toolhead.dwell(STALL_TIME)
def manual_move(self, stepper, dist, speed):
toolhead = self.printer.lookup_object('toolhead')
print_time = toolhead.get_last_move_time()
move_t = abs(dist / speed)
prev_sk = stepper.set_stepper_kinematics(self.stepper_kinematics)
stepper.set_position((0., 0., 0.))
self.move_fill(self.cmove, print_time, 0., move_t, 0.,
0., 0., 0., dist, 0., 0., 0., speed, 0.)
stepper.step_itersolve(self.cmove) stepper.step_itersolve(self.cmove)
stepper.set_stepper_kinematics(prev_sk)
toolhead.dwell(move_t)
cmd_STEPPER_BUZZ_help = "Oscillate a given stepper to help id it" cmd_STEPPER_BUZZ_help = "Oscillate a given stepper to help id it"
def cmd_STEPPER_BUZZ(self, params): def cmd_STEPPER_BUZZ(self, params):
name = self.gcode.get_str('STEPPER', params) name = self.gcode.get_str('STEPPER', params)
if name not in self.steppers: if name not in self.steppers:
raise self.gcode.error("Unknown stepper %s" % (name,)) raise self.gcode.error("Unknown stepper %s" % (name,))
logging.info("Stepper buzz %s", name)
stepper = self.steppers[name] stepper = self.steppers[name]
need_motor_enable = not stepper.is_motor_enabled() logging.info("Stepper buzz %s", name)
# Move stepper was_enable, was_ignore = self.force_enable(stepper)
toolhead = self.printer.lookup_object('toolhead') toolhead = self.printer.lookup_object('toolhead')
toolhead.wait_moves()
pos = 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.set_ignore_move(False)
prev_sk = stepper.set_stepper_kinematics(self.stepper_kinematics)
for i in range(10): for i in range(10):
self.manual_move(print_time, stepper, 0., 1.) self.manual_move(stepper, 1., BUZZ_VELOCITY)
print_time += .3 toolhead.dwell(.050)
self.manual_move(print_time, stepper, 1., -1.) self.manual_move(stepper, -1., BUZZ_VELOCITY)
toolhead.reset_print_time(print_time + .7) toolhead.dwell(.450)
print_time = toolhead.get_last_move_time() self.restore_enable(stepper, was_enable, was_ignore)
stepper.set_stepper_kinematics(prev_sk)
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): def load_config(config):
return ForceMove(config) return ForceMove(config)