## 2 AHRS Principles of Operation  
Figure 1 presents a general scheme of a typical AHRS. Angular rates \(P,Q,R\) in the body frame \(F_{b}\) are measured by rate sensors. To calculate the attitude angles and heading, these rates need to be transformed to the \(F_{b}\) frame [31]. The \(F_{b}\) frame is parallel to the Earth frame, with its origin at the same point as the body frame \(F_{b}\). Two algorithms can be used for the transformation. The first is the Tait-Bryan algorithm [31,32], which assumes three rotations around known axes. Equation (1) presents the transformation algorithm. \[\dot{\overline{\Phi}}=L_{VB}\times\overline{\Omega}_{K} \tag{1}\]  
where  
\[\overline{\Phi}= \begin{bmatrix}\Phi\\ \Theta\\ \Psi\end{bmatrix}  \tag{2}\]  
represents Euler angles in the Earth frame \(F_{V}\) (roll, pitch, and yaw angles);  
\[\overline{\Omega}_{K}= \begin{bmatrix}P\\ Q\\ R\end{bmatrix}  \tag{3}\]  
represents angular rates in the body frame \(F_{B}\) (roll rate, pitch rate, yaw rate); and  
\[L_{VB}= \begin{bmatrix}1&\sin\Phi\tan\Theta&\cos\Phi\tan\Theta\\ 0&\cos\Phi&-\sin\Phi\\ 0&\frac{\sin\Phi}{\cos\Theta}&\frac{\cos\Phi}{\cos\Theta}\end{bmatrix}  \tag{4}\]  
represents the angular rate transformation matrix from \(F_{B}\) to \(F_{V}\). A well known disadvantage of the presented algorithm is the discontinuity for a pitch angle of 90 degrees. To eliminate this inconvenience, an algorithm based on quaternion algebra is used [31,32]. It assumes one rotation around a known axis. The relationship between the quaternion derivative and angular rates measured in the body frame \(F_{B}\) is as follows:  
\[\epsilon=\frac{1}{2}L_{e}\times\overline{\Omega}_{K} \tag{5}\]  
Figure 1: Attitude and heading reference system—general scheme. where  
\[\epsilon= \begin{bmatrix}\epsilon_{0}\\ e_{1}\\ e_{2}\\ e_{3}\end{bmatrix}  \tag{6}\]  
represents the quaternion  
\[L_{e}= \begin{bmatrix}-e_{1}&-e_{2}&e_{3}\\ e_{0}&-e_{3}&e_{2}\\ e_{3}&e_{0}&-e_{1}\\ -e_{2}&e_{1}&e_{0}\end{bmatrix}  \tag{7}\]  
A quaternion can be obtained from the attitude and heading:  
\[e_{0} =\cos\frac{\[PERSON]}{2}\cos\frac{\[PERSON]}{2}\cos\frac{\[PERSON]}{2}+\sin \frac{\[PERSON]}{2}\sin\frac{\[PERSON]}{2}\sin\frac{\[PERSON]}{2} \tag{8}\] \[e_{1} =\sin\frac{\[PERSON]}{2}\cos\frac{\[PERSON]}{2}\cos\frac{\Psi}{2}-\cos \frac{\[PERSON]}{2}\sin\frac{\[PERSON]}{2}\sin\frac{\[PERSON]}{2}\] (9) \[e_{2} =\cos\frac{\[PERSON]}{2}\sin\frac{\[PERSON]}{2}\cos\frac{\[PERSON]}{2}+\sin \frac{\[PERSON]}{2}\cos\frac{\[PERSON]}{2}\sin\frac{\[PERSON]}{2}\] (10) \[e_{3} =\cos\frac{\[PERSON]}{2}\cos\frac{\[PERSON]}{2}\sin\frac{\[PERSON]}{2}-\sin \frac{\[PERSON]}{2}\sin\frac{\[PERSON]}{2}\cos\frac{\Psi}{2} \tag{11}\]  
The attitude and heading can be calculated from the quaternion:  
\[\tan\Phi=\frac{2e_{0}e_{1}+e_{3}e_{2}}{e_{0}^{2}-e_{1}^{2}-3_{2}^{2}+e_{3}^{2}} \tag{12}\]  
\[\sin\Theta=2(e_{0}e_{2}-e_{3}e_{1}) \tag{13}\]  
\[\tan\Psi=\frac{2e_{0}e_{3}+e_{1}e_{2}}{e_{0}^{2}-e_{1}^{2}-3_{2}^{2}+e_{3}^{2}} \tag{14}\]  
The correction angles in the block of correction angle calculation are determined using a geometric relationship. An important task for ensuring the proper behavior of the AHRS system is the achievement of a correction. As mentioned in the introduction, several different solutions can be implemented. For the purposes of this article, a complementary filter was applied to correct the attitude and heading. Figure 2 presents a general scheme of a measurement system with a complementary filter. Signal 1 and Signal 2 represent the same physical value; however, they are affected by different errors. Signal 1 is affected by a low-frequency error, which grows over time. Signal 2 is affected by noise. The errors typical for both signals are filtered by high-pass (for Signal 1) and low-pass (for Signal 2) filters. For proper measurement, the sum of the transfer functions must be equal to 1. Figure 3 presents a scheme of the complementary filter for the AHRS system. Figure 2: Measurement system with a complementary filter—a general scheme.