From 0ab4c1e22bbb5a017c430d1fae7b3ebfe639d866 Mon Sep 17 00:00:00 2001 From: Ismail Hassaballa Date: Tue, 2 Dec 2025 22:28:06 +0100 Subject: [PATCH] filterd incoming data with timestamp conditioning --- mainplot.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mainplot.py b/mainplot.py index 8189ee8..7bcf45c 100644 --- a/mainplot.py +++ b/mainplot.py @@ -146,12 +146,18 @@ def update_SI(value: SD.ReturnDecoder): file.write(f"{value.timestamp},{value.log_message}\n") print(f"\033[F\033[2Ktime:{value.timestamp}, SI:{value.log_message}", end="\n") +Last_history_call: int = 0 def append_history(adc_values: list, timestamp: int): """Store the new sample in the rolling history (derived units).""" - if len(history_x)> 0 and timestamp < history_x[-1]: + global Last_history_call + if len(history_x) > 0 and timestamp < history_x[-1]: return # discard out-of-order samples + if len(history_x) > 0 and (history_x[-1] + (int(time.time_ns() / 1000000) - Last_history_call)*2) < timestamp: + print(f"Discarding future sample: {timestamp} > {history_x[-1]} + {(int(time.time_ns() / 1000000) - Last_history_call)*2}") + return # discard samples too far in future history_x.append(timestamp) + Last_history_call = int(time.time_ns() / 1000000) # in ms # 0: Thrust (average of load cells 0 and 1) lc_avg = (adc_values[0] + adc_values[1]) / 2 @@ -167,6 +173,7 @@ def append_history(adc_values: list, timestamp: int): for i in range(8, 16): # eight pressure sensors pres = 0.0000153522 * adc_values[i] - 6.5652036917 history_y[i - 1].append(pres) # 8→7, 15→14 + def update_plot():