From 770b92863f391df5af45909070bc2e87609c5d45 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 8 Oct 2018 20:50:45 -0400 Subject: [PATCH] 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 --- klippy/mcu.py | 20 ++++++++++---------- klippy/stepper.py | 10 +++++++--- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/klippy/mcu.py b/klippy/mcu.py index 47b6c423..37a7eec0 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -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: diff --git a/klippy/stepper.py b/klippy/stepper.py index ce262006..dcbc9484 100644 --- a/klippy/stepper.py +++ b/klippy/stepper.py @@ -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)