1)CMAccelerometerData
represents an accelerometer event. It is a measurement of acceleration along the three spatial axes at a moment of time.
An application accesses CMAccelerometerData
objects through the block handler specified as the last parameter of thestartAccelerometerUpdatesToQueue:withHandler:
method and through the accelerometerData
property, both declared by the CMMotionManager
class. The superclass of CMAccelerometerData
, CMLogItem
, defines a timestamp
property that records when the acceleration measurement was taken.
[cmmotionmanager startAccelerometerUpdatesToQueue: [NSOperationQueue currentQueue] withHandler:^(CMAccelerometerData*accelerometerData, NSError *error) {
CMAccelerometerData *newestAccel = cmmotionmanager.accelerometerData;
NSLog(@"the value is %f",newestAccel.acceleration.x);
NSLog(@"the yvalue is %f",newestAccel.acceleration.y);
NSLog(@"the zvalue is %f",newestAccel.acceleration.z);
}];
2)CMAttitude
The CMAttitude
class offers three different mathematical representations of attitude: a rotation matrix, a quaternion, and Euler angles (roll, pitch, and yaw values). You access CMAttitude
objects through the attitude property of each CMDeviceMotion
objects passed to an application. An application starts receiving these device-motion objects as a result of calling the startDeviceMotionUpdatesUsingReferenceFrame:toQueue:withHandler:
method, thestartDeviceMotionUpdatesToQueue:withHandler:
method, the startDeviceMotionUpdatesUsingReferenceFrame:
method or thestartDeviceMotionUpdates
method of the CMMotionManager
class.
[ cmmanager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMDeviceMotion *motion, NSError *error) {
CMAttitude *s=motion.attitude;
NSLog(@"the value is######### %f",s.pitch);
NSLog(@"the yvalue is###### %f",s.roll);
NSLog(@"the zvalue is####### %f",s.yaw);
}];
3)CMDeviceMotion
An instance of CMDeviceMotion
encapsulates measurements of the attitude, rotation rate, and acceleration of a device.
An application receives or samples CMDeviceMotion
objects at regular intervals after calling thestartDeviceMotionUpdatesUsingReferenceFrame:toQueue:withHandler:
method, the startDeviceMotionUpdatesToQueue:withHandler:
method, thestartDeviceMotionUpdatesUsingReferenceFrame:
method, or the startDeviceMotionUpdates
method of the CMMotionManager
class.
The accelerometer measures the sum of two acceleration vectors:gravity and user acceleration. User acceleration is the acceleration that the user imparts to the device. Because Core Motion is able to track a device’s attitude using both thegyroscope and the accelerometer, it can differentiate between gravity and user acceleration. ACMDeviceMotion
object provides both measurements in the gravity
and userAcceleration
properties.
attitude
The attitude of the device. (read-only)
Discussion
A CMAttitude
object represents a measurement of attitude—that is, the orientation of a body relative to a given frame of reference.
Availability
- Available in iOS 4.0 and later.
See Also
Declared In
CMDeviceMotion.h
gravity
The gravity acceleration vector expressed in the device's reference frame. (read-only)
Discussion
The total acceleration of the device is equal to gravity plus the acceleration the user imparts to the device (userAcceleration
).
Availability
- Available in iOS 4.0 and later.
Declared In
CMDeviceMotion.h
magneticField
Returns the magnetic field vector with respect to the device. (read-only)
Discussion
The CMCalibratedMagneticField
returned by this property gives you the total magnetic field in the device’s vicinity without device bias. Unlike the magneticField
property of the CMMagnetometer
class, these values reflect the earth’s magnetic field plus surrounding fields, minus device bias.
If the device does not have a magnetometer, the accuracy field of the property’s value (a CMCalibratedMagneticField
structure) isCMMagneticFieldCalibrationAccuracyUncalibrated
.
Availability
- Available in iOS 5.0 and later.
Declared In
CMDeviceMotion.h
rotationRate
The rotation rate of the device. (read-only)
Discussion
A CMRotationRate
structure contains data specifying the device’s rate of rotation around three axes. The value of this property contains a measurement of gyroscope data whose bias has been removed by Core Motion algorithms. The identically name property of CMGyroData
, on the other hand, gives the raw data from the gyroscope. The structure type is declared in CMGyroData.h
.
Availability
- Available in iOS 4.0 and later.
See Also
Declared In
CMDeviceMotion.h
userAcceleration
The acceleration that the user is giving to the device. (read-only)
Discussion
The total acceleration of the device is equal to gravity
plus the acceleration the user imparts to the device.
Availability
- Available in iOS 4.0 and later.
Declared In
CMDeviceMotion.h
4)CMGyroData
An instance of the CMGyroData
class contains a single measurement of the device’s rotation rate.
An application receives or samples CMGyroData
objects at regular intervals after calling the startGyroUpdatesToQueue:withHandler:
method or thestartGyroUpdates
method of the CMMotionManager
class.
rotationRate
The rotation rate as measured by the device’s gyroscope. (read-only)
rotationRate
The rotation rate as measured by the device’s gyroscope. (read-only)
5)CMLogItem
The CMLogItem
class is a base class for Core Motion classes that handle specific types of motion events. Objects of this class represent a piece of time-tagged data that can be logged to a file.
CMLogItem
defines a read-only timestamp
property that records the time a motion-event measurement was taken.
The time when the logged item is valid. (read-only)
Discussion
The time stamp is the amount of time in seconds since the phone booted.
Availability
- Available in iOS 4.0 and later.
Declared In
CMLogItem.h
6)CMMagnetmeterData
Instances of the CMMagnetometerData
class encapsulated measurements of the magnetic field made by the device’s magnetometer.
Your application can obtain samples of magnetometer measurements, as represented by instances of this class, from the block handler of thestartMagnetometerUpdatesToQueue:withHandler:
method or from the magnetometerData
property of the CMMotionManager
class.
Note: The magnetometerData
property of CMMotionManager
provides a non-nil
value only if you have called the startMagnetometerUpdates
method or thestartMagnetometerUpdatesToQueue:withHandler:
method to start magnetometer updates.
7)CMMotionManager
A CMMotionManager
object is the gateway to the motion services provided by iOS. These services provide an application with accelerometer data, rotation-rate data, magnetometer data, and other device-motion data such as attitude. These types of data originate with a device’s accelerometers and (on some models) its magnetometer and gyroscope.