aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/mcu.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-02-06 13:31:34 -0500
committerKevin O'Connor <kevin@koconnor.net>2017-02-06 13:31:34 -0500
commit20d0936fa256e0caa41a18a79556c8ade3f8347f (patch)
tree230424417d2f1b0c148d677ecf3d1003dfd943ac /klippy/mcu.py
parentc24b7a7ef96b6c9770fdf4c821f5719892732033 (diff)
downloadkutter-20d0936fa256e0caa41a18a79556c8ade3f8347f.tar.gz
kutter-20d0936fa256e0caa41a18a79556c8ade3f8347f.tar.xz
kutter-20d0936fa256e0caa41a18a79556c8ade3f8347f.zip
reactor: Use the system monotonic clock instead of the normal system clock
The normal system clock can have sudden jumps if the system clock is changed. Use the system monotonic clock to avoid these sudden changes in time. It appears the Raspbian OS (which is used by OctoPi) is setup to update the system clock upon network connectivity. This could cause sudden system clock changes which could lead to Klippy processing errors. Using the monotonic clock eliminates these issues. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/mcu.py')
-rw-r--r--klippy/mcu.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/klippy/mcu.py b/klippy/mcu.py
index 4fadc13d..f6a21746 100644
--- a/klippy/mcu.py
+++ b/klippy/mcu.py
@@ -3,7 +3,7 @@
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import sys, zlib, logging, time, math
+import sys, zlib, logging, math
import serialhdl, pins, chelper
class error(Exception):
@@ -163,7 +163,7 @@ class MCU_endstop:
clock = int(mcu_time * self._mcu_freq)
rest_ticks = int(rest_time * self._mcu_freq)
self._homing = True
- self._min_query_time = time.time()
+ self._min_query_time = self._mcu.monotonic()
self._next_query_clock = clock + self._retry_query_ticks
msg = self._home_cmd.encode(
self._oid, clock, rest_ticks, 1 ^ self._invert)
@@ -173,7 +173,7 @@ class MCU_endstop:
self._stepper.note_homing_finalized()
self._home_timeout_clock = int(mcu_time * self._mcu_freq)
def home_wait(self):
- eventtime = time.time()
+ eventtime = self._mcu.monotonic()
while self._check_busy(eventtime):
eventtime = self._mcu.pause(eventtime + 0.1)
def _handle_end_stop_state(self, params):
@@ -211,10 +211,10 @@ class MCU_endstop:
def query_endstop(self, mcu_time):
clock = int(mcu_time * self._mcu_freq)
self._homing = False
- self._min_query_time = time.time()
+ self._min_query_time = self._mcu.monotonic()
self._next_query_clock = clock
def query_endstop_wait(self):
- eventtime = time.time()
+ eventtime = self._mcu.monotonic()
while self._check_busy(eventtime):
eventtime = self._mcu.pause(eventtime + 0.1)
return self._last_state.get('pin', self._invert) ^ self._invert
@@ -377,7 +377,7 @@ class MCU:
if not self._is_fileoutput:
self.serial.connect()
self._printer.reactor.update_timer(
- self._timeout_timer, time.time() + self.COMM_TIMEOUT)
+ self._timeout_timer, self.monotonic() + self.COMM_TIMEOUT)
self._mcu_freq = self.serial.msgparser.get_constant_float('CLOCK_FREQ')
self._stats_sumsq_base = self.serial.msgparser.get_constant_float(
'STATS_SUMSQ_BASE')
@@ -547,5 +547,7 @@ class MCU:
raise error("Internal error in stepcompress")
def pause(self, waketime):
return self._printer.reactor.pause(waketime)
+ def monotonic(self):
+ return self._printer.reactor.monotonic()
def __del__(self):
self.disconnect()