aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2016-11-28 11:22:01 -0500
committerKevin O'Connor <kevin@koconnor.net>2016-11-28 11:22:01 -0500
commita5637bb9d486969db3f1127c1ac75fb9bbeb9a7c (patch)
treea1ed5df496fa02511e72916a4a28caed7cf2af94
parent1e1364c3d4bc09f39f64f7ac49bf9d51de9694fc (diff)
downloadkutter-a5637bb9d486969db3f1127c1ac75fb9bbeb9a7c.tar.gz
kutter-a5637bb9d486969db3f1127c1ac75fb9bbeb9a7c.tar.xz
kutter-a5637bb9d486969db3f1127c1ac75fb9bbeb9a7c.zip
mcu: Track the stepper position in the MCU in the MCU_stepper class
Support tracking of both the commanded_position and the mcu_position in the MCU_stepper class. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--klippy/mcu.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/klippy/mcu.py b/klippy/mcu.py
index e10b82b3..0066d24b 100644
--- a/klippy/mcu.py
+++ b/klippy/mcu.py
@@ -32,6 +32,7 @@ class MCU_stepper:
min_stop_interval = int(min_stop_interval * self._mcu_freq)
max_error = int(max_error * self._mcu_freq)
self.commanded_position = 0
+ self._mcu_position_offset = 0
mcu.add_config_cmd(
"config_stepper oid=%d step_pin=%s dir_pin=%s"
" min_stop_interval=%d invert_step=%d" % (
@@ -53,7 +54,12 @@ class MCU_stepper:
def get_invert_dir(self):
return self._invert_dir
def set_position(self, pos):
+ self._mcu_position_offset += self.commanded_position - pos
self.commanded_position = pos
+ def set_mcu_position(self, pos):
+ self._mcu_position_offset = pos - self.commanded_position
+ def get_mcu_position(self):
+ return self.commanded_position + self._mcu_position_offset
def note_stepper_stop(self):
self.ffi_lib.stepcompress_reset(self._stepqueue, 0)
def reset_step_clock(self, mcu_time):
@@ -150,7 +156,11 @@ class MCU_endstop:
return False
last_sent_time = self._last_state.get('#sent_time', -1.)
if last_sent_time >= self._min_query_time:
- if not self._homing or not self._last_state.get('homing', 0):
+ if not self._homing:
+ return False
+ if not self._last_state.get('homing', 0):
+ self._stepper.set_mcu_position(self.get_last_position())
+ self._homing = False
return False
if (self._mcu.serial.get_clock(last_sent_time)
> self._home_timeout_clock):