diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2016-11-10 12:44:04 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2016-11-13 18:29:45 -0500 |
commit | 7554c7f69423bf3d22f340a8b4851c25de855983 (patch) | |
tree | 18a29f6829b7eb0cd77a49b4dc29b98631350c70 /klippy/mcu.py | |
parent | 79da35d023dade5718c9979405b6637f0f40888b (diff) | |
download | kutter-7554c7f69423bf3d22f340a8b4851c25de855983.tar.gz kutter-7554c7f69423bf3d22f340a8b4851c25de855983.tar.xz kutter-7554c7f69423bf3d22f340a8b4851c25de855983.zip |
stepcompress: Do all step rounding in C code
Commits f0cefebf and 8f331f08 changed the way the code determined what
steps to take on fractional steps. Unfortunately, it was possible in
some situations for the C code to round differently from the python
code which could result in warnings and lost steps.
Change the code so that all fractional step handling is done in the C
code. Implementing the step rounding logic in one location avoids any
conflicts.
In order to efficiently handle the step rounding in the C code, the C
code has also been extended to directly send the "set_next_step_dir"
command.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/mcu.py')
-rw-r--r-- | klippy/mcu.py | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/klippy/mcu.py b/klippy/mcu.py index 7e172f63..79537ed6 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -22,7 +22,7 @@ class MCU_stepper: self._oid = mcu.create_oid() step_pin, pullup, invert_step = parse_pin_extras(step_pin) dir_pin, pullup, self._invert_dir = parse_pin_extras(dir_pin) - self._sdir = -1 + self._need_reset = True self._mcu_freq = mcu.get_mcu_freq() min_stop_interval = int(min_stop_interval * self._mcu_freq) max_error = int(max_error * self._mcu_freq) @@ -39,30 +39,26 @@ class MCU_stepper: "reset_step_clock oid=%c clock=%u") ffi_main, self.ffi_lib = chelper.get_ffi() self._stepqueue = self.ffi_lib.stepcompress_alloc( - max_error, self._step_cmd.msgid, self._oid) + max_error, self._step_cmd.msgid + , self._dir_cmd.msgid, self._invert_dir, self._oid) self.print_to_mcu_time = mcu.print_to_mcu_time def get_oid(self): return self._oid def get_invert_dir(self): return self._invert_dir def note_stepper_stop(self): - self._sdir = -1 - def _reset_step_clock(self, clock): + self._need_reset = True + def check_reset(self, mcu_time): + if not self._need_reset: + return + self._need_reset = False + clock = int(mcu_time * self._mcu_freq) self.ffi_lib.stepcompress_reset(self._stepqueue, clock) data = (self._reset_cmd.msgid, self._oid, clock & 0xffffffff) self.ffi_lib.stepcompress_queue_msg(self._stepqueue, data, len(data)) - def set_next_step_dir(self, mcu_time, sdir): - if self._sdir == sdir: - return - if self._sdir == -1: - clock = int(mcu_time * self._mcu_freq) - self._reset_step_clock(clock) - self._sdir = sdir - data = (self._dir_cmd.msgid, self._oid, sdir ^ self._invert_dir) - self.ffi_lib.stepcompress_queue_msg(self._stepqueue, data, len(data)) - def step(self, mcu_time): + def step(self, mcu_time, sdir): clock = mcu_time * self._mcu_freq - self.ffi_lib.stepcompress_push(self._stepqueue, clock) + self.ffi_lib.stepcompress_push(self._stepqueue, clock, sdir) def step_sqrt(self, mcu_time, steps, step_offset, sqrt_offset, factor): clock = mcu_time * self._mcu_freq mcu_freq2 = self._mcu_freq**2 @@ -477,7 +473,7 @@ class Dummy_MCU_stepper: self._stepid, dirstr, countstr, addstr, interval)) def set_next_step_dir(self, dir): self._sdir = dir - def _reset_step_clock(self, clock): + def check_reset(self, clock): self._mcu.outfile.write("G6S%dT%d\n" % (self._stepid, clock)) def print_to_mcu_time(self, print_time): return self._mcu.print_to_mcu_time(print_time) |