juno.motion

Device motion sensor readings (accelerometer, gyroscope, attitude).

Backed by CMMotionManager’s fused device-motion stream, which combines the raw accelerometer and gyroscope to produce calibrated user-acceleration, gravity, attitude, and rotation-rate readings.

Typical usage:

from juno import motion

if motion.is_available():
    with motion.updates():
        for _ in range(10):
            accel = motion.get_acceleration()
            if accel is not None:
                print(accel.x, accel.y, accel.z)
            time.sleep(0.1)

The simulator usually reports is_available() is False (no motion sensors), in which case the getters return None.

class juno.motion.Vector3(x, y, z)

Bases: NamedTuple

Three-component vector reading (acceleration, gravity, rotation rate).

Parameters:
x: float

Alias for field number 0

y: float

Alias for field number 1

z: float

Alias for field number 2

class juno.motion.Attitude(roll, pitch, yaw)

Bases: NamedTuple

Device attitude in radians around the device-fixed axes.

Parameters:
roll: float

Alias for field number 0

pitch: float

Alias for field number 1

yaw: float

Alias for field number 2

juno.motion.is_available()

Return whether device motion sensors are present on this device.

Returns:

True if CMMotionManager reports motion data available. Simulator and Macs without sensors typically return False.

Return type:

bool

juno.motion.is_updating()

Return whether device-motion updates are currently being delivered.

Return type:

bool

juno.motion.set_update_interval(seconds)

Set the device-motion update interval.

Parameters:

seconds (float) – Polling interval in seconds. Must be greater than zero.

Raises:
Return type:

None

juno.motion.updates()

Context manager that starts and stops device-motion updates.

Inside the with block the snapshot getters return live readings (or None until the first sample arrives, typically within one update interval). When the block exits, updates are stopped and any cached reading is cleared.

Yields:

None. The caller drives polling itself; this context manager only owns the start/stop lifecycle.

Return type:

Iterator[None]

juno.motion.get_acceleration()

Return the latest user-acceleration reading.

Excludes gravity. Units are g.

Returns:

Vector3 of x, y, z in g, or None if no reading is available yet (updates not started, simulator, or first sample has not arrived).

Return type:

Vector3 | None

juno.motion.get_gravity()

Return the latest gravity reading.

Returns:

Vector3 of x, y, z in g (so the magnitude is approximately 1.0 when the device is stationary), or None if no reading is available.

Return type:

Vector3 | None

juno.motion.get_attitude()

Return the latest device attitude.

Returns:

Attitude with roll, pitch, yaw in radians, or None if no reading is available.

Return type:

Attitude | None

juno.motion.get_rotation_rate()

Return the latest calibrated rotation-rate reading.

Returns:

Vector3 of x, y, z in radians/second, or None if no reading is available.

Return type:

Vector3 | None