filterd incoming data with timestamp conditioning

This commit is contained in:
2025-12-02 22:28:06 +01:00
parent bf8aa6c374
commit 0ab4c1e22b

View File

@@ -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
@@ -169,6 +175,7 @@ def append_history(adc_values: list, timestamp: int):
history_y[i - 1].append(pres) # 8→7, 15→14
def update_plot():
"""Redraw plot based on selected derived channels and available history."""
ax.clear()