aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/clocksync.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-10-01 21:03:37 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-10-02 11:00:24 -0400
commitc2e1c533561e1cf6f23c37705e9d8b24592b12bf (patch)
treecd6ff1eeae003f88016740fa59b11774ef628516 /klippy/clocksync.py
parenteaeb8311076a2b0f67141019d633da2dfde4dfa2 (diff)
downloadkutter-c2e1c533561e1cf6f23c37705e9d8b24592b12bf.tar.gz
kutter-c2e1c533561e1cf6f23c37705e9d8b24592b12bf.tar.xz
kutter-c2e1c533561e1cf6f23c37705e9d8b24592b12bf.zip
clocksync: Implement a floor on the prediction filter
Don't discard samples that are less than 500us from the prediction regardless of the prediction variance. Also, don't use the prediction variance in the external time estimate. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/clocksync.py')
-rw-r--r--klippy/clocksync.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/klippy/clocksync.py b/klippy/clocksync.py
index 6eaf2a47..0bbde8c9 100644
--- a/klippy/clocksync.py
+++ b/klippy/clocksync.py
@@ -77,11 +77,12 @@ class ClockSync:
self.min_rtt_time = sent_time
logging.debug("new minimum rtt %.3f: hrtt=%.6f freq=%d",
sent_time, half_rtt, self.clock_est[2])
- # Compare clock to predicted clock and track prediction accuracy
+ # Filter out samples that are extreme outliers
exp_clock = ((sent_time - self.time_avg) * self.clock_est[2]
+ self.clock_avg)
clock_diff2 = (clock - exp_clock)**2
- if clock_diff2 > 25. * self.prediction_variance:
+ if (clock_diff2 > 25. * self.prediction_variance
+ and clock_diff2 > (.000500 * self.mcu_freq)**2):
if clock > exp_clock and sent_time < self.last_prediction_time + 10.:
logging.debug("Ignoring clock sample %.3f:"
" freq=%d diff=%d stddev=%.3f",
@@ -112,7 +113,7 @@ class ClockSync:
self.serial.set_clock_est(new_freq, self.time_avg + TRANSMIT_EXTRA,
int(self.clock_avg - 3. * pred_stddev))
self.clock_est = (self.time_avg - self.min_half_rtt,
- self.clock_avg + 3. * pred_stddev, new_freq)
+ self.clock_avg, new_freq)
#logging.debug("regr %.3f: freq=%.3f d=%d(%.3f)",
# sent_time, new_freq, clock - exp_clock, pred_stddev)
# clock frequency conversions