From c2e1c533561e1cf6f23c37705e9d8b24592b12bf Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 1 Oct 2017 21:03:37 -0400 Subject: [PATCH] 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 --- klippy/clocksync.py | 7 ++++--- 1 file 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