filterd incoming data with timestamp conditioning
This commit is contained in:
@@ -146,12 +146,18 @@ def update_SI(value: SD.ReturnDecoder):
|
|||||||
file.write(f"{value.timestamp},{value.log_message}\n")
|
file.write(f"{value.timestamp},{value.log_message}\n")
|
||||||
print(f"\033[F\033[2Ktime:{value.timestamp}, SI:{value.log_message}", end="\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):
|
def append_history(adc_values: list, timestamp: int):
|
||||||
"""Store the new sample in the rolling history (derived units)."""
|
"""Store the new sample in the rolling history (derived units)."""
|
||||||
|
global Last_history_call
|
||||||
if len(history_x) > 0 and timestamp < history_x[-1]:
|
if len(history_x) > 0 and timestamp < history_x[-1]:
|
||||||
return # discard out-of-order samples
|
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)
|
history_x.append(timestamp)
|
||||||
|
Last_history_call = int(time.time_ns() / 1000000) # in ms
|
||||||
|
|
||||||
# 0: Thrust (average of load cells 0 and 1)
|
# 0: Thrust (average of load cells 0 and 1)
|
||||||
lc_avg = (adc_values[0] + adc_values[1]) / 2
|
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
|
history_y[i - 1].append(pres) # 8→7, 15→14
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def update_plot():
|
def update_plot():
|
||||||
"""Redraw plot based on selected derived channels and available history."""
|
"""Redraw plot based on selected derived channels and available history."""
|
||||||
ax.clear()
|
ax.clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user