-
Notifications
You must be signed in to change notification settings - Fork 0
Module Usage
Haoqing Yang edited this page Apr 1, 2026
·
2 revisions
In main program:
- create a list of imu managers
managers = IMUFactory.detect_and_create(free_threading, log_data)withfree_threadingbeing flag to enable free_threading andlog_databeing the flag to log recorded data. - Set rotation matrix if needed.
sensor_manager.set_rotation_matrix(matrix)withmatrixbeing a 3x3 rotation matrix. - start each manager
sensor_manager.start() - data stream loop example
data = sensor_manager.get_data()
"""Basic module usage example."""
import time
from loguru import logger
from imu_python.definitions import IMUUpdateTime
from imu_python.factory import IMUFactory
def main() -> None:
"""Run a simple demonstration."""
sensor_managers = IMUFactory.detect_and_create()
for manager in sensor_managers:
manager.start()
try:
while True:
for manager in sensor_managers:
logger.info(manager.get_data())
time.sleep(IMUUpdateTime.freq_hz)
#Note: this read frequency is independent of IMUs actual hardware frequency
except KeyboardInterrupt:
for manager in sensor_managers:
manager.stop()
if __name__ == "__main__":
main()- Running
IMUFactory.detect_and_create(log_data=True)will record data with the following columns:
timein seconds
accels(x, y, z) in m/s^2
gyros(x, y, z) in rad/s
mags(x, y, z) normalized (Calibration transforms data close to the unit sphere)
quatspose as quaternion (w, x, y, z)
- By default, the recorded data file is saved under
data/recordingswith a timestamp
running src/imu_python/data_handler/data_plotter with the argument --filepath or -f followed by the recorded data file path will render a matplot plot with acceleration, gyroscope, magnetic and quaternion plots in relation to time.
note: In Pycharm, the plots would show up when the file is run in terminal; in VSCode, the file would need to be run in an interactive window with Jupyter instead of the terminal.