From 77bc5e438851c8a8a8f160fd112e43f460a54241 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 29 May 2021 21:29:00 -0400 Subject: [PATCH] stepper: Improve get_past_commanded_position() Pass a print_time instead of a clock to get_past_commanded_position(). Fix calculation on steppers that home and use an inverted direction pin. Signed-off-by: Kevin O'Connor --- klippy/kinematics/extruder.py | 4 +--- klippy/stepper.py | 12 +++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py index ea5161a9..6f2138ae 100644 --- a/klippy/kinematics/extruder.py +++ b/klippy/kinematics/extruder.py @@ -152,9 +152,7 @@ class PrinterExtruder: 1., pressure_advance, 0., start_v, cruise_v, accel) def find_past_position(self, print_time): - mcu = self.stepper.get_mcu() - clock = mcu.print_time_to_clock(print_time) - return self.stepper.get_past_commanded_position(clock) + return self.stepper.get_past_commanded_position(print_time) def cmd_M104(self, gcmd, wait=False): # Set Extruder Temperature temp = gcmd.get_float('S', 0.) diff --git a/klippy/stepper.py b/klippy/stepper.py index ab981e96..d6800a94 100644 --- a/klippy/stepper.py +++ b/klippy/stepper.py @@ -112,10 +112,12 @@ class MCU_stepper: return self._tag_position def set_tag_position(self, position): self._tag_position = position - def get_past_commanded_position(self, clock): + def get_past_mcu_position(self, print_time): + clock = self._mcu.print_time_to_clock(print_time) ffi_main, ffi_lib = chelper.get_ffi() - sq = self._stepqueue - mcu_pos = ffi_lib.stepcompress_find_past_position(sq, clock) + return ffi_lib.stepcompress_find_past_position(self._stepqueue, clock) + def get_past_commanded_position(self, print_time): + mcu_pos = self.get_past_mcu_position(print_time) return mcu_pos * self._step_dist - self._mcu_position_offset def set_stepper_kinematics(self, sk): old_sk = self._stepper_kinematics @@ -139,12 +141,12 @@ class MCU_stepper: return params = self._get_position_cmd.send([self._oid]) last_pos = params['pos'] + if self._invert_dir: + last_pos = -last_pos ret = ffi_lib.stepcompress_set_last_position(self._stepqueue, last_pos) if ret: raise error("Internal error in stepcompress") mcu_pos_dist = last_pos * self._step_dist - if self._invert_dir: - mcu_pos_dist = -mcu_pos_dist self._mcu_position_offset = mcu_pos_dist - self.get_commanded_position() def set_trapq(self, tq): ffi_main, ffi_lib = chelper.get_ffi()