This tutorial descibes how an accelerometer can be used to determine an aircraft’s attitude (pitch and roll).
An accelerometer measures, as it’s name hints, acceleration along a predefined axis. As you probably remember from you physics class, the earth’s gravity is also an acceleration (a falling stone keeps going faster and faster). So: with an accelerometer, we can measure the earth’s gravity! This image shows how we do it:
The red arrow represents the earth’s gravity. The blue arrow shows how the accelerometer senses gravity. Note that the axis of this accelerometer is perpendicular to the aircraft (we placed it like that in our aircraft!).
The angle theta between the actual gravity vector and the measured gravity is related to the pitch of the aircraft (pitch = theta + 90°). If we know theta, we know our pitch! Since we know the magnetude of the earth’s gravity, simple calculus gives us our pitch angle:
accelerometer = cos (theta) * gravity
theta = acos (accelerometer / gravity)
And since pitch = theta + 90°
pitch = asin (accelerometer / gravity)
Woooow, we calculated the pitch orientation of our airplane using an accelerometer. Pretty easy, huh?
Calculating the roll angle is pretty much the same. We only need an extra accelerometer with an axis perpendicular to the pitch-accelerometer.
Reality is a bit different from this simplified example. The inverse sinus can’t give you the full 360 degrees ranging pitch angle. A plane heading for the sky and one heading for the ground would both result in a 0 (zero) measurement. We’ll need an extra accelerometer to distinguish these cases. The 2-argument inverse tangens makes sure the resulting angle is in the correct quandrant. Thus:
pitch = atan2(accelerometer / gravity, z / gravity)
Now you know most about using accelerometers to calculate pitch and roll, don’t start building your own autopilot system just yet! There are more forces working on a flying airplane then just good old gravity! Just think about the centripetal force when following a circle path. We’ll need gyroscopes to correct this over short period of time (also usefull to eliminate the effect of vibrations on the accelerometer). Over a longer period of time, we’ll need some more advanced physics to estimate these other forces so we can compensate for them. I’ll write later about the different approaches you can use to do this.
The gyroscopes are covered in the next tutorial: gyroscope to roll, pitch and yaw