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:
27
visualise.py
27
visualise.py
@ -47,10 +47,30 @@ 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
|
||||
|
||||
# 关键:避免 ESP32 因 DTR/RTS 被 pyserial 拉动而自动 reset / 进入 boot mode
|
||||
ser.dtr = False
|
||||
ser.rts = False
|
||||
|
||||
ser.open()
|
||||
|
||||
try:
|
||||
ser.dtr = False
|
||||
ser.rts = False
|
||||
ser.reset_input_buffer()
|
||||
ser.reset_output_buffer()
|
||||
|
||||
print("Reading {} at {} baud...".format(port, baud), file=sys.stderr)
|
||||
print("Waiting for ESP32 main.py startup...", file=sys.stderr)
|
||||
time.sleep(4.0)
|
||||
|
||||
start = time.monotonic()
|
||||
|
||||
while True:
|
||||
if seconds is not None and time.monotonic() - start >= seconds:
|
||||
@ -97,6 +117,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(
|
||||
"Ignored {} abnormal packet time delta(s).".format(bad_delta_count),
|
||||
|
||||
Reference in New Issue
Block a user