mcu: Store MCU_stepper commanded_pos as a float

It's valid to consider the stepper at a position that is not on a step
interval - only the "mcu position" needs to be an integer.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-12-07 18:12:06 -05:00
parent 3ffab763c0
commit e0c947e188
1 changed files with 6 additions and 7 deletions

View File

@ -18,9 +18,8 @@ class MCU_stepper:
self._step_pin = pin_params['pin'] self._step_pin = pin_params['pin']
self._invert_step = pin_params['invert'] self._invert_step = pin_params['invert']
self._dir_pin = self._invert_dir = None self._dir_pin = self._invert_dir = None
self._commanded_pos = 0 self._commanded_pos = self._mcu_position_offset = 0.
self._step_dist = self._inv_step_dist = 1. self._step_dist = self._inv_step_dist = 1.
self._mcu_position_offset = 0
self._min_stop_interval = 0. self._min_stop_interval = 0.
self._reset_cmd = self._get_position_cmd = None self._reset_cmd = self._get_position_cmd = None
self._ffi_lib = self._stepqueue = None self._ffi_lib = self._stepqueue = None
@ -66,16 +65,16 @@ class MCU_stepper:
def get_step_dist(self): def get_step_dist(self):
return self._step_dist return self._step_dist
def set_position(self, pos): def set_position(self, pos):
if pos >= 0.: steppos = pos * self._inv_step_dist
steppos = int(pos * self._inv_step_dist + 0.5)
else:
steppos = int(pos * self._inv_step_dist - 0.5)
self._mcu_position_offset += self._commanded_pos - steppos self._mcu_position_offset += self._commanded_pos - steppos
self._commanded_pos = steppos self._commanded_pos = steppos
def get_commanded_position(self): def get_commanded_position(self):
return self._commanded_pos * self._step_dist return self._commanded_pos * self._step_dist
def get_mcu_position(self): def get_mcu_position(self):
return self._commanded_pos + self._mcu_position_offset mcu_pos = self._commanded_pos + self._mcu_position_offset
if mcu_pos >= 0.:
return int(mcu_pos + 0.5)
return int(mcu_pos - 0.5)
def note_homing_start(self, homing_clock): def note_homing_start(self, homing_clock):
ret = self._ffi_lib.stepcompress_set_homing( ret = self._ffi_lib.stepcompress_set_homing(
self._stepqueue, homing_clock) self._stepqueue, homing_clock)