The DriveCheck app helps measure the safety of a user’s driving by collecting data from the iPhone and manipulating them to measure how safe a user is driving. The app records measurements, such as acceleration, gravity, rotation, and speed, from the phone’s reference frame using measurement programs such as CLLocationManager and CMMotionManager which are provided by Apple and built into Swift.
Due to the fact that the measurements recorded are from the point of view of the phone and not the car, which is what ultimately needs to be measured, the values recorded by the phone need to be manipulated to the point of view of the car. This is done by rotating the values of acceleration from the point of view of the phone to the point of view of the car. The rotation of the phone is recorded using the CMMotionManager object of the phone and is measured in terms of angular rotation in degrees: Pitch about the X axis, Roll about the Y axis, and Yaw about the Z axis.

These angles are measured from a set reference frame where the Z axis of the phone is always vertical and the X axis of the phone is always pointed to Magnetic North. This reference frame is included in Swift.

Using the roll, pitch, and yaw values measured using CMMotionManager, a rotation matrix is created to represent the phone’s rotation from the ground’s reference frame. A second rotation matrix is then created that represents the car’s rotation from the ground’s reference frame using the “course” value recorded from the phone which represents the angle at which the phone is moving relative to true north, independent of the phone’s orientation or rotation and is accessed from CLLocationManager. Since it can be assumed that the car is not rotated along it’s X or Y axis since it is flat on the ground, the rotation of the car is simply the rotation about the Z axis which is equal to the “course” value. The rotation from the car to the phone is then solved for using the two rotations already known since the rotations from ground to car and then car to phone is equal to the rotation from ground to phone. Using an algorithm that inverses the rotation matrix for the rotation between the ground and the car and then multiplies that matrix by the rotation from the ground to the phone, the rotation matrix from the car to the phone can be solved for. Using this rotation matrix, the recorded values for acceleration from the phone’s reference frame can be rotated along the same rotation from the car’s reference frame to the phone’s reference frame to find the x, y, and z components of the car’s acceleration.