stepper: Reset the next step time on a stepper stop

Automatically reset the next step time to zero on a stepper_stop()
call.  This makes the host code simpler as it no longer needs to
schedule an explicit reset_step_clock command on the step after a
homing operation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-11-14 13:10:14 -05:00
parent 941427554a
commit 9ad8153d33
3 changed files with 5 additions and 8 deletions

View File

@ -22,7 +22,6 @@ class MCU_stepper:
self._oid = mcu.create_oid() self._oid = mcu.create_oid()
step_pin, pullup, invert_step = parse_pin_extras(step_pin) step_pin, pullup, invert_step = parse_pin_extras(step_pin)
dir_pin, pullup, self._invert_dir = parse_pin_extras(dir_pin) dir_pin, pullup, self._invert_dir = parse_pin_extras(dir_pin)
self._need_reset = True
self._mcu_freq = mcu.get_mcu_freq() self._mcu_freq = mcu.get_mcu_freq()
min_stop_interval = int(min_stop_interval * self._mcu_freq) min_stop_interval = int(min_stop_interval * self._mcu_freq)
max_error = int(max_error * self._mcu_freq) max_error = int(max_error * self._mcu_freq)
@ -47,11 +46,8 @@ class MCU_stepper:
def get_invert_dir(self): def get_invert_dir(self):
return self._invert_dir return self._invert_dir
def note_stepper_stop(self): def note_stepper_stop(self):
self._need_reset = True self.ffi_lib.stepcompress_reset(self._stepqueue, 0)
def check_reset(self, mcu_time): def reset_step_clock(self, mcu_time):
if not self._need_reset:
return
self._need_reset = False
clock = int(mcu_time * self._mcu_freq) clock = int(mcu_time * self._mcu_freq)
self.ffi_lib.stepcompress_reset(self._stepqueue, clock) self.ffi_lib.stepcompress_reset(self._stepqueue, clock)
data = (self._reset_cmd.msgid, self._oid, clock & 0xffffffff) data = (self._reset_cmd.msgid, self._oid, clock & 0xffffffff)
@ -486,7 +482,7 @@ class Dummy_MCU_stepper:
self._stepid, dirstr, countstr, addstr, interval)) self._stepid, dirstr, countstr, addstr, interval))
def set_next_step_dir(self, dir): def set_next_step_dir(self, dir):
self._sdir = dir self._sdir = dir
def check_reset(self, clock): def reset_step_clock(self, clock):
self._mcu.outfile.write("G6S%dT%d\n" % (self._stepid, clock)) self._mcu.outfile.write("G6S%dT%d\n" % (self._stepid, clock))
def print_to_mcu_time(self, print_time): def print_to_mcu_time(self, print_time):
return self._mcu.print_to_mcu_time(print_time) return self._mcu.print_to_mcu_time(print_time)

View File

@ -71,8 +71,8 @@ class PrinterStepper:
self.need_motor_enable = True self.need_motor_enable = True
def prep_move(self, move_time): def prep_move(self, move_time):
mcu_time = self.mcu_stepper.print_to_mcu_time(move_time) mcu_time = self.mcu_stepper.print_to_mcu_time(move_time)
self.mcu_stepper.check_reset(mcu_time)
if self.need_motor_enable: if self.need_motor_enable:
self.mcu_stepper.reset_step_clock(mcu_time)
self.motor_enable(move_time, 1) self.motor_enable(move_time, 1)
self.need_motor_enable = False self.need_motor_enable = False
return (mcu_time, self.mcu_stepper) return (mcu_time, self.mcu_stepper)

View File

@ -238,6 +238,7 @@ void
stepper_stop(struct stepper *s) stepper_stop(struct stepper *s)
{ {
sched_del_timer(&s->time); sched_del_timer(&s->time);
s->next_step_time = 0;
s->position = -stepper_get_position(s); s->position = -stepper_get_position(s);
s->count = 0; s->count = 0;
s->flags &= SF_INVERT_STEP; s->flags &= SF_INVERT_STEP;