Saturday, September 25, 2010

Core Motion Framework

  • There are 8 header files - they can be grouped into four categories: Initialization (CMMotionManager.h), Reporting (CMError.h, CMErrorDomain.h, and CMLogItem.h), Combined Motion Sensing (CMDeviceMotion.h), and Individual Motion Sensing (CMAccelerometer.h, CMAttitude.h and CMGyro.h).
  • After creating an instance of CMMotionManager, an application can use it to receive 3 types of motion: raw accelerometer data, raw gyroscope data, and processed device-motion data. The processed device-motion data provided by Core Motion's sensor fusion algorithms gives the device's attitude and rotation-rate; the direction of gravity, and the acceleration the user is imparting to the device.
  • An application can take one of 2 approaches when receiving motion data: by handling it at specified update intervals or periodically sampling the motion data.
  • For handling motion updates at specified intervals, the following 3 steps should be taken: (Step:1) set accelerometerUpdateInterval property in the unit of seconds, (Step:2) call startAccelerometerUpdatesToQueue: withHandler:, passing in a block of type CMAccelerometerHandler, and (Step:3) accelerometer data is passed into the block as CMAccelerometerData. Similar 3 steps should be taken for Gyroscope or Device Motion.
  • For periodic sampling of motion data, the following 2 steps should be taken: (Step:1) call startAccelerometerUpdates, and (Step:2) periodically access CMAccelerometerData objects by reading accelerometerData property. Similar 2 steps should be taken for Gyroscope and Device Motion.
  • The availability of hardware and its activity status are accessible through the following 2 properties: accelerometerAvailable and accelerometerActive. Similar 2 properties are there for Gyroscope and Device Motion.
  • CMAccelerometerData has a struct type property called acceleration (CMAcceleration) which contains 3 double's for the accelerations along the 3 axes in the unit of G's (gravitational force).
  • CMGyroData has a struct type property called rotationRate (CMRotationRate) which contains 3 double's for the rotation rates around the 3 axes in the unit of radians per second. The sign follows the right hand rule: if the right hand is wrapped around one of the axes such that the tip of the thumb points toward the positive direction of that axis, a positive rotation is one toward the tips of the other fingers.
  • CMDeviceMotion encapsulates measurements of the attitude, rotation rate, and acceleration of a device. There is a catch: the accelerometer by itself actually measures the sum of two distinct acceleration vectors: gravity and user acceleration; user acceleration being the acceleration that the user imparts on the device. Due to the fact that Core Motion is able to track a device's attitude using both the gyroscope and the accelerometer, it can differentiate between those two acceleration vectors, namely gravity and user acceleration. The 2 properties: gravity and userAcceleration, correspond to them. In toto, CMDeviceMotion has 4 properties: attitude (CMAttitude type, orientation of the device relative to a given frame of reference), gravity (CMAcceleration type, a vector expressed in the device's reference frame), rotationRate (CMRotationRate type, contains a measurement of gyroscope data whose bias has been removed by Core Motion Algorithms and is different from CMGyroData that gives raw gyroscope data), and userAcceleration (CMAcceleration type).
  • CMAttitude represents a measurement of the device's attitude at a point in time. It offers 3 different mathematical representations of attitude: a rotation matrix (as rotationMatrix property of type CMRotationMatrix), a quaternion (as quaternion property of type CMQuaternion), and Euler angles (in radians, as roll, pitch, and yaw properties). Roll is a rotation around a longitudinal axis that passes through the device from its top to bottom, pitch is a rotation around a lateral axis that passes through the device from side to side, and yaw is a rotation around an axis that runs vertically through the device and this axis is perpendicular to the body of the device, with its origin at the center of gravity and directed toward the bottom of the device. CMRotationMatrix is of struct type and it contains 9 double's representing 9 entries (m11 through m33, e.g., m31 is the element in row 3 and column 1) of a 3-by-3 rotation matrix. CMQuaternion is also of struct type having 4 doubles (x (a value for X-axis), y, z, and w) in it. A quaternion offers a way to parameterize attitude. If q is an instance of CMQuaternion, mathematically it represents the following unit quaternion: q.x * i + q.y * j + q.z * k + q.w and a unit quaternion represents a rotation of theta radians about the unit vector {x, y, z} and {q.x, q.y, q.z, q.w} satisfies 4 relations: q.x = x * sin(theta/2), q.y = y*sin(theta/2), q.z = z*sin(theta/2), and q.w = cos(theta/2). CMAttitude class has a crucial instance method called, multiplyByInverseOfAttitude which takes in a CMAttitude object and multiplies its inverse with the receiving CMAttitude object and it replaces the receiving object with the change of attitude with respect to the passed-in attitude object. In order to use a CMAttitude object as a reference, it must be cached and passed as an argument to this method in subsequent calls.
  • CMLogItem 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. It has a read-only property called, timestamp, of type NSTimeInterval which records the time when a motion-event measurement was taken.
  • CMErrorDomain has a NSString in it called, CMErrorDomain and it identifies the domain of the NSError objects returned from Core Motion.
  • CMError is of enum type which currently (description is forthcoming, says the library reference!) has one value defined in it called, CMErrorNull = 100.

No comments:

Post a Comment