Skip to content

Stream IMU Data

Neon +1.1.2

Data generated by the IMU can be received using the receive_imu_data method. It returns a UTC timestamp in seconds, the head pose as a quaternion, gyro data, and accelerometer data as follows.

IMUData(
    gyro_data=Data3D(x=-0.1659393310546875, y=-0.1964569091796875, z=0.1735687255859375),
    accel_data=Data3D(x=-0.02880859375, y=-0.224609375, z=1.0068359375),
    quaternion=Quaternion(x=-0.06114135682582855, y=-0.090116947889328, z=0.8700147271156311, w=0.48084819316864014),
    timestamp_unix_seconds=1744297102.1941311
)
Check the whole example code here
stream_imu.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import asyncio
import contextlib

from pupil_labs.realtime_api import Device, Network, receive_imu_data


async def main():
    async with Network() as network:
        dev_info = await network.wait_for_new_device(timeout_seconds=5)
    if dev_info is None:
        print("No device could be found! Abort")
        return

    async with Device.from_discovered_device(dev_info) as device:
        status = await device.get_status()
        sensor_imu = status.direct_imu_sensor()
        if not sensor_imu.connected:
            print(f"Imu sensor is not connected to {device}")
            return

        restart_on_disconnect = True
        async for imu_pack in receive_imu_data(
            sensor_imu.url, run_loop=restart_on_disconnect
        ):
            print(imu_pack)


if __name__ == "__main__":
    with contextlib.suppress(KeyboardInterrupt):
        asyncio.run(main())