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:
NamedTupleThree-component vector reading (acceleration, gravity, rotation rate).
- class juno.motion.Attitude(roll, pitch, yaw)¶
Bases:
NamedTupleDevice attitude in radians around the device-fixed axes.
- juno.motion.is_available()¶
Return whether device motion sensors are present on this device.
- Returns:
TrueifCMMotionManagerreports motion data available. Simulator and Macs without sensors typically returnFalse.- Return type:
- juno.motion.is_updating()¶
Return whether device-motion updates are currently being delivered.
- Return type:
- 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:
TypeError – If
secondsis not a real number.ValueError – If
secondsis not positive.
- Return type:
None
- juno.motion.updates()¶
Context manager that starts and stops device-motion updates.
Inside the
withblock the snapshot getters return live readings (orNoneuntil 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:
Vector3ofx,y,zin g, orNoneif 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:
Vector3ofx,y,zin g (so the magnitude is approximately 1.0 when the device is stationary), orNoneif no reading is available.- Return type:
Vector3 | None