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:
parent
2c5eba44ee
commit
a434341aa9
|
@ -7,6 +7,7 @@ import logging
|
|||
import chelper
|
||||
|
||||
BUZZ_VELOCITY = 4.
|
||||
STALL_TIME = 0.100
|
||||
|
||||
class ForceMove:
|
||||
def __init__(self, config):
|
||||
|
@ -25,41 +26,49 @@ class ForceMove:
|
|||
def register_stepper(self, stepper):
|
||||
name = stepper.get_name()
|
||||
self.steppers[name] = stepper
|
||||
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.)
|
||||
def force_enable(self, stepper):
|
||||
toolhead = self.printer.lookup_object('toolhead')
|
||||
print_time = toolhead.get_last_move_time()
|
||||
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.set_stepper_kinematics(prev_sk)
|
||||
toolhead.dwell(move_t)
|
||||
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)
|
||||
if name not in self.steppers:
|
||||
raise self.gcode.error("Unknown stepper %s" % (name,))
|
||||
logging.info("Stepper buzz %s", name)
|
||||
stepper = self.steppers[name]
|
||||
need_motor_enable = not stepper.is_motor_enabled()
|
||||
# Move stepper
|
||||
logging.info("Stepper buzz %s", name)
|
||||
was_enable, was_ignore = self.force_enable(stepper)
|
||||
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):
|
||||
self.manual_move(print_time, stepper, 0., 1.)
|
||||
print_time += .3
|
||||
self.manual_move(print_time, stepper, 1., -1.)
|
||||
toolhead.reset_print_time(print_time + .7)
|
||||
print_time = toolhead.get_last_move_time()
|
||||
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)
|
||||
self.manual_move(stepper, 1., BUZZ_VELOCITY)
|
||||
toolhead.dwell(.050)
|
||||
self.manual_move(stepper, -1., BUZZ_VELOCITY)
|
||||
toolhead.dwell(.450)
|
||||
self.restore_enable(stepper, was_enable, was_ignore)
|
||||
|
||||
def load_config(config):
|
||||
return ForceMove(config)
|
||||
|
|
Loading…
Reference in New Issue