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:
parent
459e521991
commit
770b92863f
|
@ -73,17 +73,17 @@ class MCU_stepper:
|
||||||
def calc_position_from_coord(self, coord):
|
def calc_position_from_coord(self, coord):
|
||||||
return self._ffi_lib.itersolve_calc_position_from_coord(
|
return self._ffi_lib.itersolve_calc_position_from_coord(
|
||||||
self._stepper_kinematics, coord[0], coord[1], coord[2])
|
self._stepper_kinematics, coord[0], coord[1], coord[2])
|
||||||
def set_position(self, newpos):
|
def set_position(self, coord):
|
||||||
spos = self.calc_position_from_coord(newpos)
|
self.set_commanded_position(self.calc_position_from_coord(coord))
|
||||||
self._mcu_position_offset += self.get_commanded_position() - spos
|
|
||||||
self._ffi_lib.itersolve_set_commanded_pos(
|
|
||||||
self._stepper_kinematics, spos)
|
|
||||||
def get_commanded_position(self):
|
def get_commanded_position(self):
|
||||||
return self._ffi_lib.itersolve_get_commanded_pos(
|
return self._ffi_lib.itersolve_get_commanded_pos(
|
||||||
self._stepper_kinematics)
|
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):
|
def get_mcu_position(self):
|
||||||
pos_delta = self.get_commanded_position() + self._mcu_position_offset
|
mcu_pos_dist = self.get_commanded_position() + self._mcu_position_offset
|
||||||
mcu_pos = pos_delta / self._step_dist
|
mcu_pos = mcu_pos_dist / self._step_dist
|
||||||
if mcu_pos >= 0.:
|
if mcu_pos >= 0.:
|
||||||
return int(mcu_pos + 0.5)
|
return int(mcu_pos + 0.5)
|
||||||
return int(mcu_pos - 0.5)
|
return int(mcu_pos - 0.5)
|
||||||
|
@ -122,11 +122,11 @@ class MCU_stepper:
|
||||||
return
|
return
|
||||||
params = self._get_position_cmd.send_with_response(
|
params = self._get_position_cmd.send_with_response(
|
||||||
[self._oid], response='stepper_position', response_oid=self._oid)
|
[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:
|
if self._invert_dir:
|
||||||
pos = -pos
|
mcu_pos_dist = -mcu_pos_dist
|
||||||
self._ffi_lib.itersolve_set_commanded_pos(
|
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):
|
def step_itersolve(self, cmove):
|
||||||
ret = self._itersolve_gen_steps(self._stepper_kinematics, cmove)
|
ret = self._itersolve_gen_steps(self._stepper_kinematics, cmove)
|
||||||
if ret:
|
if ret:
|
||||||
|
|
|
@ -69,8 +69,9 @@ class PrinterStepper:
|
||||||
self.set_ignore_move = mcu_stepper.set_ignore_move
|
self.set_ignore_move = mcu_stepper.set_ignore_move
|
||||||
self.calc_position_from_coord = mcu_stepper.calc_position_from_coord
|
self.calc_position_from_coord = mcu_stepper.calc_position_from_coord
|
||||||
self.set_position = mcu_stepper.set_position
|
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.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
|
self.get_step_dist = mcu_stepper.get_step_dist
|
||||||
def get_name(self, short=False):
|
def get_name(self, short=False):
|
||||||
if short and self.name.startswith('stepper_'):
|
if short and self.name.startswith('stepper_'):
|
||||||
|
@ -259,9 +260,12 @@ class PrinterRail:
|
||||||
def set_max_jerk(self, max_halt_velocity, max_accel):
|
def set_max_jerk(self, max_halt_velocity, max_accel):
|
||||||
for stepper in self.steppers:
|
for stepper in self.steppers:
|
||||||
stepper.set_max_jerk(max_halt_velocity, max_accel)
|
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:
|
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):
|
def motor_enable(self, print_time, enable=0):
|
||||||
for stepper in self.steppers:
|
for stepper in self.steppers:
|
||||||
stepper.motor_enable(print_time, enable)
|
stepper.motor_enable(print_time, enable)
|
||||||
|
|
Loading…
Reference in New Issue