CMMotionManager¶
Inherits: RefCounted < Object
Streams accelerometer, gyroscope, magnetometer, and fused device-motion data from the device.
Description¶
Wraps Apple’s CMMotionManager. Configure an update interval, call one of the start_*_updates methods, and connect to the matching signal to receive samples.
Prefer device_motion_updated over raw accelerometer_updated / gyro_updated / magnetometer_updated when you need gravity-separated user acceleration, bias-corrected rotation, or device attitude.
Platform availability: Real implementation on iOS. On other platforms the manager exists but is_*_available returns false and calling start_*_updates emits update_failed.
See Apple’s CMMotionManager reference.
Tutorials¶
Properties¶
Methods¶
void |
|
void |
start_device_motion_updates(referenceFrame: AttitudeReferenceFrame) |
void |
|
void |
|
void |
|
void |
|
void |
|
void |
Signals¶
accelerometer_updated(accelerometer: CMAccelerometerData) 🔗
Emitted on the main thread when a new accelerometer sample is available.
device_motion_updated(deviceMotion: CMDeviceMotion) 🔗
Emitted on the main thread when a new fused device-motion sample is available.
gyro_updated(gyro: CMGyroData) 🔗
Emitted on the main thread when a new gyroscope sample is available.
magnetometer_updated(magnetometer: CMMagnetometerData) 🔗
Emitted on the main thread when a new magnetometer sample is available.
update_failed(message: String) 🔗
Emitted when CoreMotion reports an error or when the API is unavailable on the current platform.
Enumerations¶
enum AttitudeReferenceFrame: 🔗
AttitudeReferenceFrame XARBITRARY_Z_VERTICAL = 1
Z axis vertical, X axis aligned with an arbitrary direction in the horizontal plane.
AttitudeReferenceFrame XARBITRARY_CORRECTED_Z_VERTICAL = 2
Same as XARBITRARY_Z_VERTICAL but corrected for magnetometer drift.
AttitudeReferenceFrame XMAGNETIC_NORTH_Z_VERTICAL = 4
Z axis vertical, X axis pointing toward magnetic north. Requires the magnetometer.
AttitudeReferenceFrame XTRUE_NORTH_Z_VERTICAL = 8
Z axis vertical, X axis pointing toward true north. Requires the magnetometer and Location Services.
Property Descriptions¶
CMAccelerometerData accelerometer_data 🔗
CMAccelerometerData get_accelerometer_data()
The most recent accelerometer sample, or null if none is available.
float accelerometer_update_interval 🔗
Desired interval between accelerometer samples in seconds.
CMDeviceMotion device_motion 🔗
CMDeviceMotion get_device_motion()
The most recent device-motion sample, or null if none is available.
float device_motion_update_interval 🔗
Desired interval between device-motion samples in seconds.
CMGyroData gyro_data 🔗
CMGyroData get_gyro_data()
The most recent gyroscope sample, or null if none is available.
Desired interval between gyroscope samples in seconds.
bool is_accelerometer_active 🔗
bool get_is_accelerometer_active()
true when accelerometer updates are currently being delivered.
bool is_accelerometer_available 🔗
bool get_is_accelerometer_available()
true when the device has an accelerometer available to this binding.
bool is_device_motion_active 🔗
bool get_is_device_motion_active()
true when device-motion updates are currently being delivered.
bool is_device_motion_available 🔗
bool get_is_device_motion_available()
true when fused device-motion is available on this device.
bool get_is_gyro_active()
true when gyroscope updates are currently being delivered.
bool get_is_gyro_available()
true when the device has a gyroscope available to this binding.
bool get_is_magnetometer_active()
true when magnetometer updates are currently being delivered.
bool is_magnetometer_available 🔗
bool get_is_magnetometer_available()
true when the device has a magnetometer available to this binding.
CMMagnetometerData magnetometer_data 🔗
CMMagnetometerData get_magnetometer_data()
The most recent magnetometer sample, or null if none is available.
float magnetometer_update_interval 🔗
Desired interval between magnetometer samples in seconds.
Method Descriptions¶
void start_accelerometer_updates() 🔗
Begins delivering accelerometer samples via accelerometer_updated. Sampling cadence is controlled by accelerometer_update_interval.
void start_device_motion_updates(referenceFrame: AttitudeReferenceFrame) 🔗
Begins delivering fused CMDeviceMotion samples via device_motion_updated. referenceFrame selects how attitude is referenced. Pass XMAGNETIC_NORTH_Z_VERTICAL or XTRUE_NORTH_Z_VERTICAL to align yaw with magnetic or true north (requires the magnetometer).
void start_gyro_updates() 🔗
Begins delivering gyroscope samples via gyro_updated. Sampling cadence is controlled by gyro_update_interval.
void start_magnetometer_updates() 🔗
Begins delivering magnetometer samples via magnetometer_updated. Sampling cadence is controlled by magnetometer_update_interval.
void stop_accelerometer_updates() 🔗
Stops accelerometer updates.
void stop_device_motion_updates() 🔗
Stops device-motion updates.
void stop_gyro_updates() 🔗
Stops gyroscope updates.
void stop_magnetometer_updates() 🔗
Stops magnetometer updates.