optogrid
optogrid.py
BLE driver for the OptoGrid device with optional IMU logging, extracted and cleaned from erlichlab/optogrid-manager’s HeadlessOptoGridClient.
Removed from the original: ZMQ, GPIO, rsync. Kept and reworked: the BLE control API and the IMU acquisition/logging, now fully configurable.
Design notes
BLE runs on a dedicated background thread with its own asyncio event loop (bleak is async and the connection must stay alive between commands). The public API is synchronous so it can be called from PyQt slots.
Each IMU notification carries all 9 sensor values (accel, gyro, mag) in one packet, so reading them costs nothing extra. What you configure with the on/off flags is which COLUMNS get written to disk, not what is read.
- IMU logging flags (independent, “enfoque C”):
save_accel_gyro : write acc_x/y/z, gyro_x/y/z
- save_orientationwrite roll/pitch/yaw (requires save_accel_gyro);
uses the magnetometer when available, falls back to accel+gyro only when not (yaw will drift)
save_magnetometer : write mag_x/y/z (raw)
The ‘sample’ and ‘sync’ columns are always written.
Data is written to Parquet; export_csv() converts a Parquet file to CSV.
Requires: bleak, numpy, pyarrow, pandas, ahrs
Functions
|
Convert a Parquet IMU log to CSV. |
|
Create and connect an OptoGrid. |
Classes
|
What to WRITE to disk. |
|
Synchronous, thread-safe BLE driver for the OptoGrid, with optional IMU logging. |
|
Optogenetic stimulation parameters. |