Stabilizing a hovering aerial vehicle is the most important task when working with such vehicles. Precise measurement of its orientation and rate is an easy task when using a commercial IMU (Inertial Measurement Unit). Nevertheless, these commercial sensors are generally expensive. Using low-cost inertial sensors, as accelerometers and gyrometers, becomes popular for aerial prototypes. The main problem with these sensors is that they do not include good estimation algorithms and classical techniques are used with great simplicity yielding worse estimation results. In this chapter, different observers are proposed and validated to estimate the attitude of a quadcopter. The main idea is to include the sensor characterization to take into account bias estimation and correct the estimated states. The algorithms are validated in simulation and also in real time. The obtained results are compared with those for a commercial and popular IMU. The KF (Kalman Filter) appears as the most suitable method for UAV purposes.
Inertial sensors; Data fusion; Observers; Kalman filter; Orientation estimation
The problem of attitude estimation consists in recovering the true attitude using the signals provided by the gyroscopes and accelerometers. The gyroscopes measure the angular velocity of the body, and thus they can be integrated to obtain the attitude. This approach quickly produces a drift due to the errors introduced by the integration of bias and noise, as will be discussed below [1]. The accelerometers sense the orientation of the gravity acceleration, from which the attitude can be obtained directly. However, the accelerometer signal is highly corrupted by noise due to vibrations, and this approach yields an estimate too noisy to be used in practice. A simple approach that is widely used and provides good results is complementary filtering where the accelerometers are low-pass filtered and the gyroscopes are high-pass filtered [2].
This chapter aims at providing a comparative evaluation of attitude estimation algorithms using low-cost sensors (gyroscopes and accelerometers). Several aspects must be taken into account while choosing the most suitable approach for a given application: singularity existence, convergence guarantee, computational time, bias estimation, etc. The comparison is focused on Kalman filtering methods as they provide a suitable framework for an easy integration in higher level localization techniques based on laser range finders, cameras, or GPS [3]. The results show that it is possible to obtain a performance with a hobbyist-grade IMU similar to that of an industrial-grade IMU. The chapter is ended by explaining in detail the simplified Kalman filtering algorithm, and it is shown that such a proposal is very easy-to-code, computationally efficient, and yet has good performance.
Let us denote by the unit basis vectors of the Earth-centered Earth-fixed (ECEF) reference frame, , which is assumed to be inertial. Let , denoted simply by Ω in what follows, be the angular velocity of the aircraft with respect to expressed in the body frame . Thus the rotational kinematics relating these angular velocities to the Euler angles are expressed as
It is a well-known result that the rate of change of the basis vectors is given by
where the skew-symmetric operator is defined as
According to the roll–pitch–yaw sequence of Euler angles, the rotation matrix is expressed as
where maps vectors from onto . Noticing that and the time derivative of this rotation matrix can be derived by generalizing (3.2), it follows that the kinematics in terms of the rotation matrix, also referred to as the Direct Cosine Matrix (DCM), is given by
Rotations are also represented using quaternions, which are an extension to the complex numbers. Quaternions are mainly used because they provide a singularity-free representation, and also because quaternion algebra is computationally efficient, see Sect. 2.4 of Chap. 2. The unitary quaternion could be also represented by where defines the scalar part of the quaternion and represents the vector part. From (2.30) the rigid body angular motion can be written using quaternion notation as
where
The rotation matrix (3.4) expressed in terms of the quaternion components is defined as follows:
The output of an MEMS (Micro-Electro-Mechanical System) sensor is corrupted by noise and an offset, and is usually referred to as bias [4]. The bias can be calibrated prior to each flight. However, it is dependent on temperature, causing the bias to drift. This effect is especially noticeable within the first few minutes of operation because of the internal warm-up of the electronic components [5].
For the attitude estimation problem, the biases of the gyroscopes are much more crucial than of the other components because they are time-forward integrated, originating an error that grows linearly with time. Even when considering an ideal scenario without bias, integration of the gyro output corrupted by white noise would give rise to an error growing with the square root of time. As a consequence, a method is needed to correct the errors introduced by the integration of bias and white noise. Regarding the biases of the accelerometers, they are not so important because after calibration they will result only in a small offset with respect to the actual horizontal plane (perpendicular to the gravity vector).
Let us consider the following error models for the sensors:
where the velocity measurement is composed of its actual value , bias , and noise . The same applies to the acceleration measurements but the biases are not included. As mentioned above, these errors are not so critical as they are not integrated over time. The measurement noises are considered subject to a Gaussian representation as follows:
where defines the variance, represents the identity matrix, and denotes the diagonal covariance matrix. A random walk process,
is used to model the “slowly-varying” biases of the gyros. The variance determines how much the bias drifts.
Now, it is necessary to know how the measurements are related to the variables to be estimated. The relation of the gyroscope measurements with the different representations of the kinematic model of the vehicle have been already presented in (3.1)–(3.8). Regarding the accelerometers, they measure the specific force acting on the vehicle expressed in , as they are aligned with the body-fixed reference frame. The measurement can be expressed as
where is the acceleration vector due to the external forces vector , both of them are expressed in . In case the vehicle is not expected to perform aggressive maneuvers, the linear acceleration () can be neglected. If the vector of acceleration measurements is normalized, it can be simply related to the roll and pitch angles as
Several attitude estimation algorithms are compared and presented in the following. The Kalman Filter (KF) approach is used in all of them, regardless of the formulation of the system. If the resulting system is nonlinear then the Extended Kalman Filter (EKF) is applied. Recall that the Kalman Filter is derived under the assumption of Gaussian errors for both the system and the measurement models. Therefore, it is necessary to include the biases in the vector of estimated variables, as they are not removed in the filtering process. The equations of the discrete EKF for a general nonlinear system1
can be found in [6] and are summarized as
where
The KF equations are simply obtained by applying (3.13)–(3.14) to a linear system.
All of the algorithms presented in the next section, except for the first one, lead to nonlinear formulations. Some of them are referred to as DCM-based because the elements of the DCM are manipulated directly. Also, formulations using both Euler angles and quaternions are explored.
Algorithms based on the DCM directly update the components of the matrix, avoiding the representation by means of Euler angles. The time variation of the elements of the DCM is given by (3.5). Although the whole matrix could be updated, the last column (denoted by ) suffices when providing information about ϕ and θ, as can be seen in (3.4). Using the common notation in control theory, the state vector is denoted by , and the system is described by
Assuming that can be identified by analyzing the static output of the accelerometers, there is only one tuning parameter, , which determines the relative importance of the state propagation with respect to the information recovered from the accelerometers. Notice that this methodology results in a very simple filter, but it would imply the need of zero-velocity updates in practice as the bias of the gyroscopes is not explicitly estimated. For more details about this formulation see [7].
The previous filter can be modified to include the bias estimation [8]. According to the measurement model in (3.9), the bias-free angular velocity is given by . Denoting by the state vector, the resulting system can be expressed as
where
Notice that there is an extra parameter, , accounting for the bias noise. It has a physical meaning as it describes the random walk model for the bias. Although used as a tuning parameter, it has to be small enough to allow only slow variations of the bias, which is known to happen in reality.
In order to improve the angular velocity estimation, the above algorithm can be extended by including the angular velocity in the state vector, . The process model for the angular velocities is assumed to be constant, so they are only modified in the updating phase of the Kalman filter. In practice, this will work as a low-pass filter, controlled by the parameter . In this case, the matrices describing the system are
In this algorithm six variables are estimated: three Euler angles and three biases of the gyroscopes. The state vector can be written as . The nonlinear equations are described in a state-space form as
where
The process equation is derived from (3.1) by directly incorporating the measurements from the gyroscopes as follows:
while the measurement model is given by (3.12), i.e.,
In this case the parameter determines how reliable the state propagation (based on gyroscopes measurements) is with respect to the observations made by the accelerometers.
Four quaternions and two biases of the gyroscope variables are estimated in this algorithm. The state vector can be written as . The nonlinear equations are described as
where
The measurement model is given by the third column of (3.8), namely,
The algorithms presented in the previous section have different levels of complexity, make use of different orientation representations, and even estimate different variables. A comparison was carried out in order to see if the different formulations have a significant impact on the estimation accuracy.
The experimental platform used for the comparative analysis is shown in Fig. 3.1. It is the 3D HOVER platform manufactured by Quanser and thought of as a test-bed platform of control algorithms for vertical take-off and landing (VTOL) vehicles, so that the translational degrees of freedom are clamped for convenience [9]. The Euler angles are measured by means of three optical encoders with an accuracy of 0.04 degrees, which can be sampled with a frequency up to 1000 Hz. These encoders provide a reliable pattern for the evaluation and comparison of the algorithms.
For the sake of comparison, two Inertial Measurement Units (IMU) have been used, the MicroStrain 3DM-GX2 and the Sparkfun Sensor Stick. The 3DM-GX2 has typical inertial sensor sets which are internally processed [10]. The angle estimations can be delivered in either Euler angles or rotational matrix at up to 250 Hz. The Sensor Stick is a hobbyist-level unit which consists of only a plain circuit board that gathers inertial sensors connected to a unique bus [11]. Some of the relevant information about these devices is shown in Table 3.1.
Table 3.1
IMUs specifications
Microstrain 3DM-GX2 | Sensor stick | MPU-6050 | |
Size | 41 × 63 × 32 | 35 × 10 × 2 | 21 × 17 × 2 |
Weight | 50 g | 1.2 g | 6 g |
Gyro range | ±75 to ±1200 degree/s | ±2000 degree/s | ±250 to ±2000 degree/s |
Gyro bias | ±0.2 degree/s | Not defined | ±20 degree/s |
Gyro nonlinearity | 0.2% | 0.2% | 0.2% |
Gyro noise performance | 0.17 degree/s (rms)a | 0.38 degree/s (rms) | 0.025 degree/s (rms) |
Acc. bias | ±5 mg (for ±5 g) | Not defined | ±50 mg |
Acc. nonlinearity | 0.2% | 0.5% | 0.5% |
Acc. noise performance | 0.6 mg (rms)a | 2.9 mg (rms) | 1.3 mg (rms) |
a Measured from static output of the sensor.
In order to evaluate the performance of the different algorithms, the platform described in Sect. 3.3.6.1 was used to follow alternating step references. These references were tracked using a PD controller. The angular estimates of the encoders and the 3DM-GX2 were stored, along with the information of gyroscopes and accelerometers of the Sensor Stick. The whole sampling procedure was implemented in a single real-time C++ code running at 100 Hz. This frequency was selected since it allows for a reasonable time to run the algorithms in a low-cost microcontroller. The estimation algorithms are executed offline using Matlab and the sampled data.
One of the experiments comparing the attitude measured by the encoders with that of the 3DM-GX2 and the one computed with the Euler EKF algorithm during an experiment with ±2 degree step references is presented in Fig. 3.2. At first sight the angular estimate obtained with the Sensor Stick is fast and noise-free, very similar to the estimate given by the 3DM-GX2.
Since it is very difficult to reach any conclusion from the naked eye observations, a set of five experiments like the one in Fig. 3.2 were carried out for different step amplitudes. The root mean square value (rmse) was chosen as a performance index, taking the encoder measurement as the ideal one. This index was averaged over the whole set of experiments for each step amplitude and for every algorithm. For each algorithm an optimization by trial and error was carried out to find the tuning of the parameters leading to the best performance.
The results of these experiments are depicted in Fig. 3.3 where the mean value of the rmse is represented along with its standard deviation. As can be seen, the accuracy of the estimation gets worse as the amplitude of the steps increases. All the algorithms perform very well for low angle oscillations.
However, for higher angles the 3DM-GX2 performs slightly better. This is sensible given that higher outputs of the sensors will manifest their imperfections, e.g., scale factor inaccuracy, nonlinearity, or cross-axis sensitivity. In any case, performance is very similar, and the comparison points out that a cheap board like the Sensor Stick and a simple linear KF provides sufficient accuracy for small angles.
Fig. 3.4 shows a situation in which the algorithms did not perform so well. It is possible to observe that one of the main sources of error is the deviation in a stationary position, far from the horizontal. One of the reasons for that is due to small nonlinearities of the accelerometers as they are calibrated using a linear model. There is also another effect, which is not so obvious. The estimation is slightly worse in one of the axes when there is velocity in the other. This is a consequence of the cross-sensitivity of the gyroscopes.
Among the evaluated algorithms, the DMC3-based is the only one which includes the angular velocities as estimated variables. Fig. 3.5 shows an example of how the estimation looks like, compared to the angular velocity extracted from the 3DM-GX2. The estimation exhibits less noise, and no delay is appreciated.
Some of the aforementioned algorithms may need a large amount of computational resources. Computationally efficient algorithms are crucial because of two reasons. First of all, the computational resources onboard are limited, especially in small aerial vehicles. Second, the fast rotational dynamics of these vehicles requires high frequency controllers, and thus the measurements should be updated as fast as possible.
After several tests, we have arrived at a computationally efficient algorithm to estimate the attitude of a rotorcraft. The algorithm uses a Kalman filter applied to the kinematics of the vehicle represented by means of the Euler formulation and includes the biases of the gyroscopes into the vector of estimated variables. It was validated in flight tests, and the experimental results were compared with the data coming from a commercial IMU showing good behavior of the estimation algorithm which is presented next; for more details see [12].
An advantage of the Euler formulation is that the yaw angle can be removed from the equations if the rotation matrix is well defined. Let us denote the vector of variables to be estimated by . It is reasonable to simplify the equations by assuming non-aggressive maneuvers, and , with . From previous considerations, the kinematics of an aerial vehicle and the measurement model can be expressed by (3.1) and (3.12), respectively, which leads to the following linear equations:
where the input vector consists of the angular velocity measurements , and contains the acceleration measurements. The third equation of the measurement model which involves the third accelerometer axis has been removed, as it has very low sensitivity with respect to the roll–pitch orientation for small angles.
These simplifications result in a smaller-size linear system, thus reducing the computational load substantially. Furthermore, it will be shown next how the structure of the matrices can also be exploited to reduce the Kalman filter to a set of simple equations. The continuous-time system (3.20) can be discretized with sample time , assuming zero-order hold of the input, as follows:
where
Notice that, as a consequence of the simplifications, the resulting system is decoupled. Therefore, two different Kalman filters could be separately implemented for roll and pitch dynamics. Furthermore, one can take advantage of the fact that matrix P is symmetric, so that only three of its entries need to be stored in the memory. Using (3.13) and (3.14), the following equations for the Kalman filter of the roll angle can be derived:
where
In a similar way, the derivation of the Kalman filter equations for the pitch angle leads to the following set of equations:
where
The Kalman filter algorithm for estimating the roll and pitch angle (Eqs. (3.22)–(3.25)) has been first validated using the encoders of the Quanser platform. A commercial IMU (3DM-GX2) and a low cost inertial sensor (MPU6050) were also included in the platform in order to validate and compare the measurements. The MPU6050 is composed of a 3-axis gyroscope and a 3-axis accelerometer. It does not provide the angles of the rigid body, only the raw measurements of the sensors. The characteristics of the both devices are given in Table 3.1.
Since the angles of the experimental platform are unstable, a simple PD controller was used to stabilize the system to constant references of pitch and roll. The system was then perturbed by applying manual disturbances. All data was collected at 333 Hz, and the algorithm equations (3.22)–(3.25) were computed offline using Matlab. A trial and error tuning process resulted in the following covariance matrices:
The estimation obtained by means of this procedure can be seen in Fig. 3.6. At first sight, it can be noticed that the proposed algorithm performs fairly well, thus validating the simplifications made in its derivation.
As it is difficult to visually evaluate the quality of both estimations, three performance indexes were chosen, namely, the root mean squared error, the maximum absolute error, and the delay, all of them computed with respect to the estimate given by the encoders (which are assumed to provide a “real” measurement). Table 3.2 gathers the information of these indices for an experiment of several minutes where the system was again stabilized around zero and perturbed manually. Notice that the proposed algorithm performs even better than the 3DM-GX2.
Table 3.2
Performance indices
rmse (degrees) | (degrees) | Delay (ms) | ||
3DM-GX2 | Roll | 0.3 | 1.56 | 25 |
Pitch | 0.27 | 1.46 | ||
MPU 6050 | Roll | 0.14 | 0.72 | 15 |
Pitch | 0.19 | 0.91 |
The evolution of the bias estimate is shown in Fig. 3.7. The real bias of the gyroscopes was computed by averaging the first few seconds during which the system remains steady. It is possible to see how the estimated bias converges to the real value within a few seconds.
Although the platform described above is a suitable scenario for numerical comparison, there are still some handicaps to overcome in real flight, like vibrations and linear accelerations. The estimation algorithm is finally tested online and onboard to compute the roll and pitch angles and to stabilize a quadrotor prototype.
The quadrotor prototype developed at the UPV (Universidad Politécnica de Valencia, Spain) is depicted in Fig. 3.8. It has a distance of 41 cm between rotors, weighs around 1.3 kg without battery, and is outfitted with the IMU MicroStrain 3DM-GX2 and MPU6050, among other sensors. The basic hardware consists of a MikroKopter frame, YGE 25i electronic speed controllers, RobbeRoxxy 2827-35 brushless motors, and plastic propellers. All the computations are made onboard using an Arduino Due which is based on an Atmel SAM3X8E ARM Cortex-M3 microcontroller running at 84 MHz, and an Igep v2 board running Xenomai real-time operating system at 1 GHz.
The Arduino Due is in charge of reading every sensor, computing the Kalman filter and attitude control algorithms, controlling the motor's speed, and sending the data to the Igep board. The control algorithm consists of a PD controller with nested saturations. The Igep board is only used for data storage and also serves as a WiFi bridge. Although the proposed Kalman filter takes only 2 ms to run, the main loop in the microcontroller runs at 333 Hz restricted by the communications with the 3DM-GX2 and Igep board.
The quadrotor was controlled by adjusting roll and pitch angles using PD controllers computed with the estimated values , and . Furthermore, angular references were sent to the vehicle using a joystick. The yaw angle was stabilized separately with the measurement of the Microstrain sensor, also with a PD controller.
Due to the lack of a motion capture system, the in-flight attitude estimate of the proposed algorithm is compared to that of the 3DM-GX2. Fig. 3.9 shows the attitude estimate during one minute of flight. One can see that both estimates are very similar (an rmse of 2.7 degrees and 1.6 degrees in pitch and roll axes, respectively). Although the 3DM-GX2 is not a fully reliable pattern, it can be seen that the proposed algorithm provides a fast, noise-free, and drift-free estimate. Furthermore, it should be also noticed that the control is computed with the estimated attitude. The small oscillations around the equilibrium point evidence that the attitude and velocity estimates lead to a very good control performance.
The angular velocities are shown in Fig. 3.10. The estimated angular velocities consist of the raw gyroscope measurements corrected with the estimated biases. The estimation of the bias avoids the need of correcting the offset of the gyroscopes prior to each flight and allows operating over long time periods. This comparison shows that, in spite of the simplifications, the accuracy of the estimates is fairly good compared to that of a commercial device, at least for non-aggressive flights. Because of the low computational cost of the algorithm, the angular estimates exhibit a very small delay, which also improves control performance.
Attitude estimation is a serious problem for many research teams working in UAVs. The best solution for some teams is to buy classical IMUs such as MicroStrain; nevertheless, their price (around 2000 USD) demotivates small research groups (also particular researchers). Low-priced arrays of MEMS (accelerometers and gyrometers) can be found on the market; nevertheless, in some cases an estimation algorithm needs to be used. In this chapter the most common estimation algorithms were described and analyzed. When evaluating performance, it is important to take into account the computational load of the algorithms and the available resources onboard, as the controllers must run at very high frequencies. In our results, Kalman filter exhibited a performance that could be compared with a commercial IMU, the Microstrain 3DM-GX2. The performance of these algorithms can be further improved by using other control techniques; for example, in the next chapter, we propose a predictor scheme to restore all the states and improve the precision of the estimation algorithm.