aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/clocksync.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-05-31 18:18:23 -0400
committerKevin O'Connor <kevin@koconnor.net>2018-05-31 18:20:30 -0400
commitff9543eee2c41befe5945ec7a60d102d03026472 (patch)
tree2757b897a494aa92c6fa7799fe177e09477e9c73 /klippy/clocksync.py
parent1b1d2adb31122648d8ba28fdbef9f4d2044cc5f5 (diff)
downloadkutter-ff9543eee2c41befe5945ec7a60d102d03026472.tar.gz
kutter-ff9543eee2c41befe5945ec7a60d102d03026472.tar.xz
kutter-ff9543eee2c41befe5945ec7a60d102d03026472.zip
clocksync: Simplify is_active() check
In some rare circumstances it was possible for the host software to become so busy that it does not transmit a get_clock request for several seconds. (In particular, this could occur with some complex calls to coordinate_descent.) If that happened, it was possible for the code to incorrectly report a "Timeout with MCU" error. Rework the is_active() check to prevent that. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/clocksync.py')
-rw-r--r--klippy/clocksync.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/klippy/clocksync.py b/klippy/clocksync.py
index 9c58e6fa..07e78513 100644
--- a/klippy/clocksync.py
+++ b/klippy/clocksync.py
@@ -1,11 +1,10 @@
# Micro-controller clock synchronization
#
-# Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
+# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import logging, threading, math
+import logging, math
-COMM_TIMEOUT = 3.5
RTT_AGE = .000010 / (60. * 60.)
DECAY = 1. / 30.
TRANSMIT_EXTRA = .001
@@ -16,6 +15,7 @@ class ClockSync:
self.serial = None
self.get_clock_timer = self.reactor.register_timer(self._get_clock_event)
self.get_clock_cmd = None
+ self.queries_pending = 0
self.mcu_freq = 1.
self.last_clock = 0
self.clock_est = (0., 0., 0.)
@@ -57,10 +57,12 @@ class ClockSync:
# MCU clock querying (_handle_clock is invoked from background thread)
def _get_clock_event(self, eventtime):
self.get_clock_cmd.send()
+ self.queries_pending += 1
# Use an unusual time for the next event so clock messages
# don't resonate with other periodic events.
return eventtime + .9839
def _handle_clock(self, params):
+ self.queries_pending = 0
# Extend clock to 64bit
last_clock = self.last_clock
clock = (last_clock & ~0xffffffff) | params['clock']
@@ -138,10 +140,8 @@ class ClockSync:
if clock_diff & 0x80000000:
return last_clock + 0x100000000 - clock_diff
return last_clock - clock_diff
- def is_active(self, eventtime):
- print_time = self.estimated_print_time(eventtime)
- last_clock_print_time = self.clock_to_print_time(self.last_clock)
- return print_time < last_clock_print_time + COMM_TIMEOUT
+ def is_active(self):
+ return self.queries_pending <= 4
def dump_debug(self):
sample_time, clock, freq = self.clock_est
return ("clocksync state: mcu_freq=%d last_clock=%d"