Detecting the pitch of an iPhone while in motion
Using CoreMotion, we can easily measure the pitch an iPhone in real-time but it requires the phone to be stationary. When in motion (e.g. when the phone is mounted on a vehicle), the sensor fusion algorithm will start drifting due to the accelerometer noise (from vibrations and constant acceleration and deceleration) and is ultimately unable to correctly measure the gravity. The gravity from the accelerometer is a critical reference frame for the pitch and roll.