Add episode recording functionality and enhance serial communication handling
- Introduced record_episode.py for capturing ESP32 IMU data and RealSense images. - Added SwitchChangeDetector and SwitchLevelController for managing recording triggers. - Enhanced ESP32Bridge with new methods for reading samples and latest packets. - Updated verify.py and visualise.py to improve serial communication stability. - Modified .gitignore to include dataset, csv, and png directories.
This commit is contained in:
30
verify.py
30
verify.py
@ -57,10 +57,33 @@ def read_serial_samples(port, baud, seconds=None, max_samples=None, max_gap_ms=1
|
||||
last_t_ms = None
|
||||
elapsed_s = 0.0
|
||||
bad_delta_count = 0
|
||||
start = time.monotonic()
|
||||
|
||||
with serial.Serial(port, baud, timeout=1) as ser:
|
||||
ser = serial.Serial()
|
||||
ser.port = port
|
||||
ser.baudrate = baud
|
||||
ser.timeout = 0.05
|
||||
ser.write_timeout = 0.05
|
||||
|
||||
# Avoid unwanted ESP32 auto-reset / boot-mode toggling.
|
||||
ser.dtr = False
|
||||
ser.rts = False
|
||||
|
||||
ser.open()
|
||||
|
||||
try:
|
||||
# Some USB-UART adapters may still change line states during open().
|
||||
ser.dtr = False
|
||||
ser.rts = False
|
||||
|
||||
ser.reset_input_buffer()
|
||||
ser.reset_output_buffer()
|
||||
|
||||
print(f"Reading {port} at {baud} baud...", file=sys.stderr)
|
||||
print("Waiting for ESP32 main.py startup...", file=sys.stderr)
|
||||
time.sleep(4.0)
|
||||
|
||||
# Start timing after ESP32 startup wait.
|
||||
start = time.monotonic()
|
||||
|
||||
while True:
|
||||
if seconds is not None and time.monotonic() - start >= seconds:
|
||||
@ -110,6 +133,9 @@ def read_serial_samples(port, baud, seconds=None, max_samples=None, max_gap_ms=1
|
||||
if max_samples is not None and len(samples) >= max_samples:
|
||||
break
|
||||
|
||||
finally:
|
||||
ser.close()
|
||||
|
||||
if bad_delta_count:
|
||||
print(f"Ignored {bad_delta_count} abnormal packet time delta(s).", file=sys.stderr)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user