1. Cell phone's coordinate chart
The Core Motion Motion Manager lets you specify how often (in seconds) to receive updates from the accelerometer and gyroscope, and lets you specify a handler block directly (handle block), which executes the handler block whenever the update is ready.
The actual acceleration is broken down into two parts in core motion: Gravity and Useracceleration. Gravity represents gravity 1g in the distribution of equipment, useracceleration represents the acceleration distribution in the equipment movement. Adding the two equals the actual acceleration. The gravity of the gravity three axes is always equal to 1g, while the useracceleration depends on the amplitude of the action within the unit time.
The cmrotationrate x, Y, z, respectively, represent the rotation rate on three axes in radians per second. A rotational speed of 1 radians per second means that the device rotates half a turn per second. Here to review the conversion of radians and angles:
1 Angle =π/180 radians
1 radians = 180/π angle
360 angle = 360 *π/180 = 2π radians = Full Circle
Cmattitude's three properties Yaw,pitch and roll represent sway, pitch and scroll respectively. The device can be imagined as an airplane, and the following GIF shows the various motion states:
Yaw State of Motion:
Pitch State of motion:
The motion state of roll
Cmmotionmanager Common Properties
Cmattitude's three properties Yaw,pitch and roll represent sway, pitch and scroll respectively. Its size has nothing to do with speed, only the position.
MotionManager.attitude.yaw (swing left and right)
MotionManager.attitude.pitch (Tilt)
MotionManager.attitude.roll (scrolling)
The three properties of the gravity x, Y, z represent the gravity distribution of a gravity 1g device on three axes, and its size has nothing to do with the velocity but the position.
motionmanager.gravity.x
Motionmanager.gravity.y
Motionmanager.gravity.z
Useracceleration three properties x, Y, z represent the acceleration distribution of the motion of the device on three axes, and its size has nothing to do with its position, but only with the velocity variation within a unit time.
Motionmanager.useracceleration.x
Motionmanager.useracceleration.y
Motionmanager.useracceleration.z
The cmrotationrate x, Y, z, respectively, represent the rotation rate on three axes in radians per second. Its size has nothing to do with the size of the speed.
Motionmanager.rotationrate.x
Motionmanager.rotationrate.y
Motionmanager.rotationrate.z
It's used:
Add header File
#import <CoreMotion/CoreMotion.h>
-(void) Viewdidload {
[Superviewdidload];
Self. Motionmanager=[[cmmotionmanageralloc]init];
Self. MOTIONMANAGER.DEVICEMOTIONUPDATEINTERVAL=1/1;
[Self. Motionmanagerstartdevicemotionupdatestoqueue:[nsoperationqueuecurrentqueue] withhandler:^ (CMDeviceMotion *_ Nullable Motion,nserror * _nullable error) {
self.x.text=[nsstringstringwithformat:@ "%f", Motion.attitude.yaw];
self.y.text=[nsstringstringwithformat:@ "%f", Motion.attitude.pitch];
self.z.text=[nsstringstringwithformat:@ "%f", Motion.attitude.roll];
self.xgravity.text=[nsstringstringwithformat:@ "%f", motion.gravity.x];
self.ygravity.text=[nsstringstringwithformat:@ "%f", motion.gravity.y];
self.zgravity.text=[nsstringstringwithformat:@ "%f", motion.gravity.z];
self.xuseracceleration.text=[nsstringstringwithformat:@ "%f", motion.useracceleration.x];
self.yuseracceleration.text=[nsstringstringwithformat:@ "%f", MOTION.USERACCELERATION.Y];
self.zuseracceleration.text=[nsstringstringwithformat:@ "%f", motion.useracceleration.z];
self.xrotationrate.text=[nsstringstringwithformat:@ "%f", motion.rotationrate.x];
self.yrotationrate.text=[nsstringstringwithformat:@ "%f", motion.rotationrate.y];
self.zrotationrate.text=[nsstringstringwithformat:@ "%f", motion.rotationrate.z];
}];
}
Effect Diagram:
Additional properties: Frequency of Devicemotionupdateinterval accelerometer updates (1/4 = Four updates per second)
Accelerometeravailable whether the accelerometer is used.
Accelerometeractive whether to return the latest accelerometer data
Accelerometerdata gets the latest acceleration data and gets the final data if the accelerometer updater is not updated.
Startaccelerometerupdates Start updating data
Stopaccelerometerupdates Stop updating data
Gyroscope Properties
Gyroupdateinterval the frequency of updating data is similar to the accelerometer
Gyroavailable
Gyroactive
Gyrodata
Startgyroupdates
Stopgyroupdates
Startgyroupdatestoqueue: (nsoperationqueue *) queue Withhandler: (Cmgyrohandler) handler
Several other properties are similar to the gyroscope's properties.
If you have any comments or suggestions, please leave a message to me, thank you.