A Robust Nonlinear Observer for Real-Time Attitude Estimation Using Low-Cost MEMS Inertial Sensors

This paper deals with the attitude estimation of a rigid body equipped with angular velocity sensors and reference vector sensors. A quaternion-based nonlinear observer is proposed in order to fuse all information sources and to obtain an accurate estimation of the attitude. It is shown that the observer error dynamics can be separated into two passive subsystems connected in “feedback”. Then, this property is used to show that the error dynamics is input-to-state stable when the measurement disturbance is seen as an input and the error as the state. These results allow one to affirm that the observer is “robustly stable”. The proposed observer is evaluated in real-time with the design and implementation of an Attitude and Heading Reference System (AHRS) based on low-cost MEMS (Micro-Electro-Mechanical Systems) Inertial Measure Unit (IMU) and magnetic sensors and a 16-bit microcontroller. The resulting estimates are compared with a high precision motion system to demonstrate its performance.


Motivations and Background
The attitude control problem of a rigid body has attracted a strong interest during the past few decades, and it has been extensively studied. This interest comes from the fact that many aerospace systems, such as spacecrafts, satellites, tactical missiles and many others, enter within the framework of a rigid body with the requirement of precise attitude information [1]. In the last decade, the application of micro-electro-mechanical systems (MEMS) has gained a strong interest. Therefore, the attitude estimation problem has been tackled within new areas, such as terrestrial and aerial robotics [2,3], virtual reality [4], biomechanics [5] and wearable robots [6]. In these cases, the attitude information is obtained from inertial and magnetic sensors, namely, three rate gyros, three accelerometers and three magnetometers, orthogonally mounted, such that the sensor frame axes coincide with the principal axes of the rigid body. Since the attitude is not directly measured, it must be estimated via the measurements of the mentioned sensors. In general, these sensors can be classified into two main categories: Angular velocity sensors that measure the angular velocity of the body with respect to some inertial frame and reference vector sensors that give the coordinates of a fixed vector in the mobile frame.
Rate gyros are angular velocity sensors, and they provide continuous attitude information with good short-term stability when their measurements are integrated by means of the rigid body kinematic Equation. However, since rate gyro measurements are affected by drifts and noise, the attitude estimation based on these sensors diverges slowly from the real attitude. On the other hand, when reference vector sensors measurements, known as vector observations, are available, the attitude can be determinated by algebraic or optimization techniques [7]. Therefore, in order to decrease the effect of noise induced by the vector observations, as well as the attitude divergence provoked by the rate gyro drifts, it is important to fuse both information sources.
To this effect, various estimators have been proposed, using the quaternion attitude parametrization [8]. The Extended Kalman Filter (EKF) [9] and new alternatives to the standard EKF have been applied extensively (see [10] and the references therein). However, the divergence problem [11], the non-Gaussian noise induced [12] and the computational cost render difficult the embedded implementation of the Extended Kalman Filter (EKF). In recent years, significant research efforts have been addressed toward the synthesis of nonlinear attitude observers in order to tackle the previously mentioned issues. The first work on this topic was presented in [13]. Subsequently, in [14][15][16], quaternion-based nonlinear observers and gyro bias observers are proposed in the framework of satellite sensors calibration and marine vehicle navigation, respectively. Furthermore, the formulation of nonlinear attitude observers based on the the orthogonal group, SO(3), have been proposed in the few last years [17][18][19][20]. Recently, an excellent overview of rigid body attitude estimation and comparative study was given in [21,22]. Nevertheless, it is well known that a nonlinear observer is generally vulnerable to measurement disturbance, in the sense that a small arbitrary disturbance can lead to the divergence of the error state [23]. The above mentioned nonlinear attitude observers (with the exception of [20]) do not consider either the present noise in the gyro measurements nor a time-varying gyro bias term. Furthermore, the computational complexity in these approaches is a drawback, since the algorithms work with 3 × 3 matrices and they have to preserve orthogonality properties. The singular value decomposition (SVD) is a well-known approach and an extremely powerful and useful tool in linear control theory and signal processing. However, few works have exploited this approach in the framework of attitude estimation. In [24], the authors use the SVD method to estimate the attitude matrix minimizing Wahba's cost function. In the work reported in [25], the authors use the SVD approach for finding the relative orientation of a robotic manipulator. Nevertheless, the problem of attitude estimation from magnetic and inertial sensors using an SVD approach has not been addressed in the literature.
Furthermore, unlike sensors and computer systems used in the marine and aerospace community, the signal output of the low-cost sensors is subject to high levels of noise and a time-varying bias term.
These problems must be addressed, since, in a practical framework, the design of efficient and embedded attitude estimator using low-cost sensors is an important issue.

Contributions
In the present work, a quaternion-based attitude observer/estimator of a rigid body is presented. In the proposed approach, the attitude estimation problem is solved in two parts. Firstly, a quaternion attitude is estimated by means of vector observations. In this first step, the attitude estimation is performed using an SVD (singular value decomposition) approach. Then, the quaternion obtained in this step is considered an attitude measurement. Contrary to conventional techniques, the SVD maintains the quaternion's unit constraint naturally. Furthermore, the numerical robustness and numerical stability are guaranteed [26].
The second part of the proposed method consists of the design of a nonlinear observer in order to produce an estimate of the time-varying gyro bias and the attitude quaternion. This observer is driven by an attitude error obtained by means of the quaternion propagated by the observer, and this one obtained from the SVD technique. Asymptotic convergence of the estimation error is proven. Moreover, it is shown that the error dynamics can be decomposed in two passive subsystems connected in "feedback". This result is exploited to prove that the observer is input-to-state stable (ISS) [27,28] when the rate gyro noise is seen as the input and the error as the state. In this sense, using the small gain theorem, one claims that the observer is "robustly stable". To evaluate the proposed attitude observer behavior in real-time, a complete Attitude and Heading Reference System (AHRS) based on low-cost inertial and magnetic sensors and a 16-bit microcontroller is designed and implemented. A comparison with a high precision motion system is carried out, in order to demonstrate the observer performance.
The ISS paradigm in an attitude observer, the problem of estimating the attitude from vector observations using an SVD approach, as well as a real-time implementation have never been addressed in the literature. These facts show the originality of the present work.
The document is organized as follows. In Section 2, a mathematical background of the attitude parametrization and sensors modeling is given. The main problem is formulated in Section 3. The formulation of the nonlinear attitude observer and stability analysis is presented in Sections 4-6. The AHRS implementation and experimental results are given in Section 7. Finally, conclusions and further research are mentioned in Section 8.

Unit Quaternions and Attitude Kinematics
Consider two orthogonal, right-handed coordinate frames: the body coordinate frame, , located at the center of mass of the rigid body, and the inertial coordinate frame, 1 , e f 2 , e f 3 ], located at some point in the space. The rotation of the body frame, E b , with respect to the fixed frame, E f , is represented by the attitude matrix The cross product between two vectors, χ, ξ ∈ R 3 , is represented by a matrix multiplication The n-dimensional unit sphere embedded in R n+1 is denoted as S n = {x ∈ R n+1 : x T x = 1}.
Members of SO(3) are often parametrized in terms of a rotation, β ∈ R, about a fixed axis, e ∈ S 2 , by the map, U : R × S 2 → SO(3), defined as: Hence, a unit quaternion, q ∈ S 3 , is defined as: q = [q 1 q 2 q 3 ] T ∈ R 3 and q 0 ∈ R are known as the vector and scalar parts of the quaternion, respectively.
q represents an element of SO(3) through the map, R : S 3 → SO(3), defined as: Note that R = R(q) = R(−q) for each q ∈ S 3 , i.e., quaternions q and −q represent the same physical attitude. The inverse unit quaternion is given by q −1 := [q 0 − q T ] T , and the quaternion product is defined by: Denoting by ω = [ω 1 ω 2 ω 3 ] T the angular velocity vector of the the body coordinate frame, E b , relative to the inertial coordinate frame, E f , expressed in E b , the kinematics equation is given by: The attitude error is used to quantify the mismatch between two attitudes. If q defines the true attitude quaternion andq is the estimated quaternion, then the error quaternion that represents the attitude error between the true orientation and the estimated one is given by [8]: In the case that the true quaternion and the estimated one coincide, the quaternion error becomes:

Sensor Modeling
The sensors in the rigid body are classified into the two following categories.

Angular Velocity Sensors
The angular velocity ω = (ω 1 ω 2 ω 3 ) T is measured by three rate gyros orthogonally mounted. The output signal of a rate gyro is influenced by noise and by a slowly varying function, ν, called bias [29], that is: where η G and η ν ∈ R 3 are bounded noises and T = τ I 3 is a diagonal matrix of time constants.

Reference Vector Sensors
Let us consider the representation of a vector, x i , with respect to E f and E b and denoted by r i and b i , respectively. The vectors, r i , are also called the "reference vectors" and, in general, are known quite accurately. The body vectors, b i , are known as "vector observations" and are obtained from on-board sensors (for instance, magnetometers, star trackers, accelerometers). Let b iq and r iq be the associate quaternion to the vectors, b i and r i : these quaternions are related by the quaternion rotation, q, such that: From Equation (4) and using quaternion algebra, the following measure model can be obtained [25]: with H ∈ R 4×4 . Note that Equation (12) is a well-structured linear system of equations.

Problem Statement
The objective is to design an attitude observer that estimates the rigid body attitude doing a trade-off between a good short-term precision given by rate gyro integration and a reliable long-term accuracy provided by vector observations.
If at least two vector observations are non-collinear, the quaternion can be estimated using these simultaneous vector measurements. For this purpose, the measurement Equation (12) ., m} is written as follows: In the case of perfect measurements, the measure EquationHq = 0 is always satisfied. However, in practice, the measurements are polluted with perturbations originated from noise, vibrations, etc.
Therefore, the problem consists of estimating the attitude quaternion from a perturbed observation matrix,H, that is: On the other hand, if the initial value, q(t 0 ), is known and the angular velocity measurements are perfect, i.e., ω = ω G , it is possible to obtain q(t) by integrating the kinematics Equation (5).
Nevertheless, q(t 0 ) is, in general, unknown, furthermore, the angular velocities are polluted with bias and noise (see Equation (8)), which results in slow divergence of attitude over time. Therefore, the observation idea can be used to on-line correct the integration,q(t), of some erroneousq(t 0 ) and attitude errors caused by the bias, and the noise presents in the rate gyro measurements. This correction can be carried out according to the measurable error q e =q −1 ⊗ q ps , where q ps is considered an attitude measure obtained by the vector observations.
The observation problem can then be formulated as follows: Given the kinematic equation of the rigid body and the model of time-varying bias evolution, find an estimateq(t) andν(t) from the knowledge of ω G (t) and q ps (t) for all t ≥ t 0 ∈ R ≥0 .

Attitude Estimation from Vector Observations
Assumption 1. There are at least two linearly independent vectors, b i and b j , with i = j, that is, and an orthonormal matrix S ∈ R 4m×4 , with elements σ k along the diagonal and zeros everywhere else, where k = 1 : 4, such that: Then, the attitude quaternion is given by the last column of the matrix, V , that is: furthermore, the normality condition q ps 2 = 1 is satisfied.
Proof. The proof follows the standard least squares solution of homogeneous equations via the SDV approach [30].

Nonlinear Attitude Observer with Bias Estimation
The proposed attitude nonlinear observer that includes the bias and the error update is given by: where T ∈ R 3×3 has been defined in Equation (9) and K 1 , K 2 are positive constant parameters.q is the prediction of the attitude at time t. It is obtained via the integration of the kinematics Equation (17), using the measured angular velocity, ω G , the bias estimate,ν and q e , which is the vector part of the quaternion error, q e , that measures the discrepancy betweenq and the measured attitude, q ps , obtained by means of Lemma 1, that is: Actually, the observer Equation (17) allows one to fuse the data that arise from the vector observations and the rate gyro measurements. The observer structure is shown in Figure 1. Note that the attitude quaternion, q ps , can be expressed by: where q denotes the true attitude and ∆q represents a perturbation quaternion, which is caused by the sensor measurement noise encountered in practice.
For the first time, a Lyapunov stability analysis is carried out. As is always done, the error dynamic is obtained in a noise-free context; then, the following hypotheses are made: • η G = η ν = 0. The measurement rate gyro noise is not included in the error dynamics.
• ∆q = (1 0 0 0) T , i.e., q = q ps . This is a good assumption for the case of static attitudes and for quasistatic movements [17].
The system Equation (20) admits a set of equilibrium points P := {p e+ , p e− }, where: In both scenarios, one shows that the following stability property is ensured with respect to different sets.
Definition 1. (Asymptotic Stability in the Large) [31]. Let X ⊂ R n be given. The trivial solution x = 0 ofẋ = f (t, x) is called asymptotically stable in the large with respect to X if it is stable in the sense of Lyapunov and every other solution x(t, t 0 , x 0 ) → 0 as t → ∞ for any initial states, x 0 ∈ X , and for any initial times, t 0 ∈ R ≥0 .
One considers that the state space of Equation (20) corresponds to either which target equilibrium is chosen.

Proposition 1.
Assume that all trajectories with initial conditions, (q e 0 (t 0 ) q T e (t 0 )ν T (t 0 )) T ∈ X + , satisfy sgn(q e 0 (t)) = sgn(q e 0 (t 0 )) ≥ 0 for all t > t 0 (mutatis mutandis for X − ). Then, the equilibrium point, p e+ (respectively, the equilibrium point, p e− ) of the system Equation (20) is asymptotically stable in the large with respect to X + (respectively, with respect to X − ).
Proof. Consider the candidate Lyapunov function, V : S 3 × R 3 → R, which is proper and positive definite: The derivative of Equation (21), together with Equation (20), is given by: Thus, q e → 0 andν → 0 and, due to the normality condition, q e 0 → 1. Hence, solutions of the system Equation (20) whose initial conditions are in X + converge asymptotically to p e+ := 1 0 T 0 T T . That concludes the proof.
This fact can be shown adapting the proof of Proposition 1 using the following Lyapunov function instead: Tν , if q e 0 (t 0 ) ≥ 0 Tν , if q e 0 (t 0 ) < 0 and Q = Q T > 0, such that: Since K 2 is a scalar, the dynamics error Equation (20) for the bias observer can be written as: Although the error system Equation (27) has no output, it is possible to define the following virtual output: Using Equation (28), the error dynamics Equation (20) can be structured as the one shown in Figure 2. Proposition 2. The transfer function matrix of the error system Equations (27) and (28) is SPR. That is, the mapping, q e → y e , satisfies the KYP lemma.
Proof. Since the matrix, −T −1 , is symmetric and a Hurwitz, one has for all Q symmetric positive definite matrices a P symmetric positive definite matrix, such that: If the Q matrix is specified as Q = 2T −1 , one gets: then, which satisfies the equality Equation (26).
Proposition 3. The dynamics of the quaternion error, represented by the system, H 1 , is state strictly passive.
Proof. Consider the candidate Lyapunov function, V q , which is positive, definite and proper: Analyzing for q e 0 ≥ 0, the derivative of Equation (32) along the trajectories of q e (Equation (20)), is or, similarly: Since q e 0 ∈ [0, 1], one obtains: Then: Rate of change of energy stored respectively. Since the two systems are connected in feedback (see Figure 2), the attitude nonlinear observer Equation (17) is passive.

Input to State Stability (ISS) of the Attitude Nonlinear Observer
Note that the convergence and the passivity interpretation of the observer were accomplished within a context free from noise and perturbation. However, the rate gyro measurements are corrupted by measurements noise and bias components that are time-varying. Owing to the nonlinearity of the observer, this type of disturbance can cause instability or even the finite time escape of the estimate.
In this section, the robustness of the proposed observer is discussed, which follows from passivity propriety. It will be shown that the error dynamics is input-to-state stable when the disturbances are viewed as the input and the error quaternion as the state.
In the case that noise is included, the error dynamics Equation (20) becomes: This equation can be described as illustrated in Figure 3, where the inputs, d 1 and d 2 , are such that: It is assumed that the noise components are bounded. That is: However, neither the bounds nor the noise distribution are necessarily known. Proposition 4. The system, H 2 , is input-to-state stable (ISS) with respect to the input, d 2 . Then, the output of H 2 ( y e = K 2 I 3ν ) is always bounded.
Proposition 5. The system, H 1 , is input-to-state stable with respect to d 2 .
The key to showing the ISS of the system, H 1 , is the fact that a system is input-to-state stable if it admits an ISS-Lyapunov function. In this sense, a Lyapunov function will be proposed; then, it will be shown that this function is a ISS-Lyapunov function.
Since the system, H 1 , is ISS, the following inequality is accomplished: where ζ 1 is a KL function and ς 12 ( ν 2 ) = K 2 ν 2 and ς 1 ( η G 2 ) = K 2 η G 2 are K functions. That is, every trajectory of the attitude error dynamics asymptotically approaches a ball around the origin, whose radius is a function of supremum norm of the bias estimation error and of the measure noise of the rate gyro.
Using the interesting properties of ISS systems, the stability of the entire error dynamics is studied.
Then, one has the following result. Theorem 2. Let K 2 be a positive constant, such that K 2 < 1. Then, the attitude nonlinear observer is robust towards to measurement disturbance of the rate gyro.
Proof. The claim follows from the small gain theorem for the interconnection of nonlinear systems that are input-to-state stable [32]. The error dynamics of a nonlinear observer (Equation (37)) is composed of the feedback interconnection of the systems (H 1 -H 2 ). From Propositions 4 and 5, it follows that: The composition of the functions, ς 12 and ς 21 , is given by: Since K 2 < 1, it follows that: Then, the system (H 1 -H 2 ) is ISS, when the measurements disturbances, η G and η ν , are seen as the input and the error state, [ q T eν T ] T , as the state. This means that the attitude observer is robust with respect to measurement disturbance.

Experimental Results
The estimation methodology proposed in this work is implemented and evaluated in real time, in order to assess its effectiveness. For this purpose,   In order to experimentally evaluate the performance of the proposed AHRS, the experiments were carried out with a two degrees-of-freedom high accuracy system. Actually, this system is the Twin Rotor System [33] (see Figure 6). This system has two rotational joints, which allow for movement about two orthogonally axes with a resolution of 0.35 • considered a true attitude for performance evaluation. In order to test the complete attitude estimation, two trials were carried out. In the first one, the axes, e b e b 3 , of the AHRS coordinate frame (body coordinate frame E b = [ e b 1 , e b 2 , e b 3 ]) coincide with the axes, e t 1 and e t 3 , of the Twin Rotor System. Thus, θ (pitch) and ψ (yaw) angles were evaluated. In order to evaluate the angle, φ (roll), the AHRS was rotated π/2 about the axis, e b 1 , such that e b 1 coincides with e t 1 and e b 2 with e t 3 . Note that the attitude is estimated with respect to the inertial coordinate frame ]. E f is chosen to be the NED (north, east, down) coordinate frame. In this case, the reference vectors are the gravitational and magnetic vectors. The vector observations, i.e., the gravitational and magnetic vectors expressed in the body frame, E b , are obtained from the mentioned tri-axis accelerometer and tri-axis magnetometer. The angular velocity is obtained from three rate gyros.

AHRS
The attitude and gyro bias observer is implemented at 55 Hz using a fourth-order Runge-Kutta method, with tuning parameters, K 1 = 3.2 and K 2 = 0.9, such that the restriction of Theorem 2 is accomplished. No particular emphasis was given on the tuning process, since the resulting performance with these simple parameters is very acceptable. The attitude is maintained as a quaternion, which is normalized at each time step to compensate for numerical errors. After that, the quaternion is converted to Euler Angles, since they are more intuitive, and it allows for comparing with the angles obtained from the Twin Rotor System. For the entire experimentation time span, the vector ν f = ν o + ν r was added to the vector of the rate gyro measurements, in order to test the ability to estimate and compensate for the rate gyro bias. In this case, one has ν o = 0.1(1 − 1 1) T and ν r = 0.0001k(1 1 1) T , where k represents the iteration index. i.e., (φ = 0 • ,θ = 15 • ,ψ = −60 • ). For the second trial, the initial condition for the quaternion estimate isq(t 0 ) = (0.76 0 0 − 0.64) T , i.e., (φ = 0 • ,θ = 0 • ,ψ = −80 • ). In both cases, the rate gyro bias initial estimate was set to zero. The observer angle estimates are compared with the ones obtained from the encoders of the Twin Rotor System. In Figure 7, the evolution of θ (pitch) and ψ (yaw) angles is depicted. Figure 8 shows the evolution of the second trial, i.e., φ (roll) and ψ (yaw) angles. Finally, the convergence of the rate gyros bias estimates is shown in Figure 9. These results indicate that the observer faces up to the slowly time-varying nature of the rate gyro biases.  It is worth mentioning that the algorithm itself uses only 81% of the 55 Hz cycle time. This is depicted in Figure 10. Finally, we invite the readers to watch the following video: https://www.dropbox.com/s/r3pq57rw1f0pxuv/AttitudeObserver.mov.

Conclusions
This paper presented an original quaternion-based strategy for the attitude estimation of a rigid body equipped with angular velocity sensors and reference vector sensors. To accomplish the objective, a robust nonlinear observer for attitude estimation was developed. This observer ensures the asymptotic estimation convergence and local exponential estimation convergence. Furthermore, by means of an ISS analysis, it was shown that the observer is robust towards noise and the disturbance of the rate gyro sensors. Thus, an embedded AHRS was designed and developed. Experimental results were presented, where the AHRS outputs are compared with a two degrees-of-freedom high accuracy motion system. This illustrates the achievable performance of the proposed estimation schema.