When estimating attitude and heading, the best results are obtained by combining data from multiple types of sensors to take advantage of their relative strengths. For example, rate gyros can be integrated to produce angle estimates that are reliable in the short-term, but that tend to drift in the long-term. Accelerometers, on the other hand, are sensitive to vibration and other non-gravity accelerations in the short-term, but can be trusted in the long-term to provide angle estimates that do no degrade as time progresses. Combining rate gyros and accelerometers can produce the best of both worlds - angle estimates that are resistant to vibration and immune to long-term angular drift.
In this article, we describe a simple method for combining rate gyros and accelerometers to produce reliable pitch and roll angle estimates. The GP9 and the UM7 use methods that are more sophisticated than what is described here, but the basic intuition behind both methods is the same - gyros are used to give good short-term stability, while accelerometers are used for their better long-term stability.
Note that there are some problems with the simple method described here. We discuss these problems in more detail near the end of the article.
2. Estimating angles with accelerometers
Recall that the output of a three-axis accelerometer can be modeled as
where is the measured acceleration, m is the mass of the body, is the sum of all forces on the body (including gravity) expressed in the sensor body frame, and is the force due to gravity, also expressed in the body frame.
If we assume that in general , then the output of the accelerometer is given by
In the inertial frame, the force of gravity is given by the vector . That is, there is no force on the x and y axes, and there is of force on the axis.
Rotating the gravity into the body-frame of the sensor, we get
Thus, the expected accelerometer measurement in the body-frame is given by
Let the components of be given by , , and . Then we can solve for the pitch () and roll () angles using
The ^ symbol above the angles indicates that they are estimated angles, not actual angles.
This method provides a quick, simple way to estimate pitch and roll using only accelerometers. However, note that we assumed that the only force acting on the accelerometers was gravity. Vibration and other external forces will directly influence our measured pitch and roll angles, making them very noisy and, in many cases, unusable by themselves.
3. Estimating angles with rate gyros
Rate gyros can also be used to measure angles. Unlike accelerometers, rate gyros are nominally unaffected by acceleration, making gyro-based angle estimates immune to external forces that make accelerometers unreliable.
Remember that rate gyros measure angular rates about the x, y, and z axes in the sensor body-frame. We would like to take those measurements and use them to figure out our Euler Angle rates. Since roll, pitch, and yaw each occur in different reference frames, we need to take the rate gyro outputs and rotate them into the appropriate frames (more details about this process can be found here).
Let the variables p, q , and r represent the rate gyro outputs on the x, y, and z axes, respectively. Then the Euler Angle rates are given by
Since we are only estimating pitch and roll in this example, we will ignore the term for yaw ().
Assuming that the rate gyros are sampled at some fixed interval T, we can estimate pitch and roll using Euler Integration as follows:
In the preceding equations, we use the + symbol to distinguish the new angle estimate from the old angle estimate.
This method allows us to use rate gyros to estimate angles that aren't sensitive to vibration and other external forces. However, because rate gyros are noisy and imperfect, every time we add new gyro measurements, we add errors to our angle estimates. Over time, errors will accumulate, causing our gyro-based angles estimates to drift over time. We will solve this problem in the next section.
4. Combining accelerometer and rate gyro data
As described previously, angle estimates based on rate gyros alone drift over time, making them unreliable in the long-term. In contrast, accelerometers do not cause angle estimates to drift, but they are sensitive to external forces like vibration, making short-term estimates unreliable. In this section, we combine the outputs of both types of sensor to produce angle estimates that are resistant to vibration and immune to long-term drift.
The estimation process will be split into two steps, a "prediction" step where we will use the rate gyros to estimate incremental changes in the angle, and an "update" step where we will use the accelerometers to correct rate gyro drift.
The prediction step consists of angular rate integration as we saw in the rate gyro section:
In the update step, we assume that the accelerometer-based angle is usually something close to the truth. We take the measured angle (from the accelerometers) and the predicted angle (from the rate gyros), compute the difference, and add a portion of the difference to the final angle estimate as shown below:
The value is a constant value between 0 and 1. Notice that if is equal to 0, then only the gyro-based angle is used because no accelerometer-based correction is applied. Similarly, if is equal to 1, then the estimated angle is equivalent to the accelerometer-based angle.
As approaches 1, the accelerometers are trusted more and the rate gyros are trusted less. This makes the angle estimates less sensitive to rate gyro noise and biases, but more sensitive to vibration and other external forces.
As approaches 0, the rate gyros are trusted more and the accelerometers are trusted less. This makes the angle estimates more sensitive to rate gyro noise and biases, but less sensitive to vibration and other external forces.
In practice, can be adjusted based on the desired behavior of the angle estimates, but having high-quality rate gyros allows a lower gain to be used, preventing unwanted accelerations from affecting the angle estimates. From an intuitive standpoint, the rate gyros estimate the angle in the short-term while the accelerometers gradually pull the angle estimate toward the average angle, whatever that happens to be.
This formulation can be called a "fixed-gain observer," and it bears a lot of similarity to a Kalman Filter. The main difference is that in a Kalman Filter, the observer gain is selected optimally using known characteristics of the physical system. In addition, a Kalman Filter can exploit knowledge of the physical system so that accelerometer data (and other data) needn't be converted to angles before using it to make corrections to the angle estimates.
The downside of this method is that accelerometers can't always be expected to provide reliable estimates of the actual angle. In some dynamic systems (most notably in aircraft), accelerometers can provide incorrect angle information for arbitrarily large amounts of time. This causes the angle estimates to degrade and possibly even become completely unreliable.
More sophisticated filters combine inertial sensors with other types of sensors (like GPS) to allow the angle estimates to maintain their accuracy even during sustained, high-G maneuvers. Our GP9: GPS-Aided AHRS is an example of a sensor that performs better on moving vehicles.