mcu: Add a set_commanded_position() method to MCU_stepper

Add the ability to directly set the "commanded" stepper position.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-10-08 20:50:45 -04:00
parent 459e521991
commit 770b92863f
2 changed files with 17 additions and 13 deletions

View File

@ -73,17 +73,17 @@ class MCU_stepper:
def calc_position_from_coord(self, coord):
return self._ffi_lib.itersolve_calc_position_from_coord(
self._stepper_kinematics, coord[0], coord[1], coord[2])
def set_position(self, newpos):
spos = self.calc_position_from_coord(newpos)
self._mcu_position_offset += self.get_commanded_position() - spos
self._ffi_lib.itersolve_set_commanded_pos(
self._stepper_kinematics, spos)
def set_position(self, coord):
self.set_commanded_position(self.calc_position_from_coord(coord))
def get_commanded_position(self):
return self._ffi_lib.itersolve_get_commanded_pos(
self._stepper_kinematics)
def set_commanded_position(self, pos):
self._mcu_position_offset += self.get_commanded_position() - pos
self._ffi_lib.itersolve_set_commanded_pos(self._stepper_kinematics, pos)
def get_mcu_position(self):
pos_delta = self.get_commanded_position() + self._mcu_position_offset
mcu_pos = pos_delta / self._step_dist
mcu_pos_dist = self.get_commanded_position() + self._mcu_position_offset
mcu_pos = mcu_pos_dist / self._step_dist
if mcu_pos >= 0.:
return int(mcu_pos + 0.5)
return int(mcu_pos - 0.5)
@ -122,11 +122,11 @@ class MCU_stepper:
return
params = self._get_position_cmd.send_with_response(
[self._oid], response='stepper_position', response_oid=self._oid)
pos = params['pos'] * self._step_dist
mcu_pos_dist = params['pos'] * self._step_dist
if self._invert_dir:
pos = -pos
mcu_pos_dist = -mcu_pos_dist
self._ffi_lib.itersolve_set_commanded_pos(
self._stepper_kinematics, pos - self._mcu_position_offset)
self._stepper_kinematics, mcu_pos_dist - self._mcu_position_offset)
def step_itersolve(self, cmove):
ret = self._itersolve_gen_steps(self._stepper_kinematics, cmove)
if ret:

View File

@ -69,8 +69,9 @@ class PrinterStepper:
self.set_ignore_move = mcu_stepper.set_ignore_move
self.calc_position_from_coord = mcu_stepper.calc_position_from_coord
self.set_position = mcu_stepper.set_position
self.get_mcu_position = mcu_stepper.get_mcu_position
self.get_commanded_position = mcu_stepper.get_commanded_position
self.set_commanded_position = mcu_stepper.set_commanded_position
self.get_mcu_position = mcu_stepper.get_mcu_position
self.get_step_dist = mcu_stepper.get_step_dist
def get_name(self, short=False):
if short and self.name.startswith('stepper_'):
@ -259,9 +260,12 @@ class PrinterRail:
def set_max_jerk(self, max_halt_velocity, max_accel):
for stepper in self.steppers:
stepper.set_max_jerk(max_halt_velocity, max_accel)
def set_position(self, newpos):
def set_commanded_position(self, pos):
for stepper in self.steppers:
stepper.set_position(newpos)
stepper.set_commanded_position(pos)
def set_position(self, coord):
for stepper in self.steppers:
stepper.set_position(coord)
def motor_enable(self, print_time, enable=0):
for stepper in self.steppers:
stepper.motor_enable(print_time, enable)