# In-Orbit Attitude Determination of the UVSQ-SAT CubeSat Using TRIAD and MEKF Methods
## 2 UVSQ-SAT Attitude Determination Considerations
### Orbital Reference Frames and Attitude Representation
#### 2.2.2 Attitude Representation  
There are different ways to express the satellite attitude in its reference frame. The first basic representations are known as the Euler angles. The orientation of the body with respect to a reference frame is given by three Euler angles. Those angles define three successive rotations around different axes. Roll, pitch, and yaw angles are defined in Figure 6 and are called \(\phi\), \(\theta\), and \(\psi\), respectively.  
Figure 4: Earth centered orbit reference frame (OC) and orbit (O) reference frames.  
Figure 5: Earth-centered inertial (ECI), Earth-centered Earth-fixed (ECEF), and orbit (O) reference frames.  
In order to avoid singularities that come with the choice of using Euler angles for attitude representation, we define the quaternion representation where a quaternion \(\mathbf{q}\) is defined as  
\[\mathbf{q}=q_{1}+q_{2}\mathbf{i}+q_{3}\mathbf{j}+q_{4}\mathbf{k}=\begin{bmatrix} q_{1}\\ q_{2}\\ q_{3}\\ q_{4}\end{bmatrix} \tag{1}\]  
where \(q_{1}\), \(q_{2}\), \(q_{3}\), and \(q_{4}\) are real numbers with \(\{1,\mathbf{i},\mathbf{j},\text{ and }\mathbf{k}\}\) as a basis for a 4-dimensional vector space. \(i^{2}=j^{2}=k^{2}=ijk=-1\) and as \(\mathbf{q}\
eq\mathbf{0}\). The rotation resulting from the previous quaternion is characterized by its rotation angle \(\alpha\) around its axis of coordinates \((r_{x},r_{y},r_{z})\) defined in Equation (2a,b):  
\[\alpha=2\,\text{atan2}\bigg{(}\sqrt{q_{2}^{2}+q_{3}^{2}+q_{4}^{2}},q_{1}\bigg{)} \tag{2a}\] \[(r_{x},r_{y},r_{z})=\frac{(q_{2},q_{3},q_{4})}{\sqrt{q_{2}^{2}+q_{3}^{2}+q_{4} ^{2}}} \tag{2b}\]  
Then, we obtain Equation (3) as follows:  
\[\begin{bmatrix}q_{1}\\ q_{2}\\ q_{3}\\ q_{4}\end{bmatrix}=\begin{bmatrix}\cos\frac{\alpha}{2}\\ r_{x}\sin\frac{\alpha}{2}\\ r_{y}\sin\frac{\alpha}{2}\\ r_{y}\sin\frac{\alpha}{2}\end{bmatrix} \tag{3}\]  
The quaternions and the Euler angles can be associated as (Equation (4))  
\[\begin{array}{l}q_{1}=\cos(\frac{\alpha}{2})\\ q_{2}=\sin(\frac{\alpha}{2})\cos(\alpha_{x})\\ q_{3}=\sin(\frac{\alpha}{2})\cos(\alpha_{y})\\ q_{4}=\sin(\frac{\alpha}{2})\cos(\alpha_{z})\end{array} \tag{4}\]  
where \(\alpha_{x}\), \(\alpha_{y}\), and \(\alpha_{z}\) are the angles between the axis of rotation and the axes X, Y, and Z, respectively. From those two representations, we can create a third tool--the Direction Cosine Matrix (DCM)--that is used in the algorithm. We define the rotation matrix, also called the attitude matrix, which represents the rotation of the body in the body frame  
Figure 6: Euler angles defined for the satellite.  
(B) with respect to a specified frame--for example, the orbital frame (O)--as follows in Equation (5a,b):  
\[DCM_{\text{O}\to B}(\phi,\theta,\psi)=\begin{bmatrix}1&0&0\\ 0&\cos\phi&\sin\phi\\ 0&-\sin\phi&\cos\phi\end{bmatrix}\begin{bmatrix}\cos\theta&0&-\sin\theta\\ 0&1&0\\ \sin\theta&0&\cos\theta\end{bmatrix}\begin{bmatrix}\cos\psi&\sin\psi&0\\ -\sin\psi&\cos\psi&0\\ 0&0&1\end{bmatrix} \tag{5a}\] \[DCM_{\text{O}\to B}(q)=\begin{bmatrix}1-2s(q_{3}^{2}+q_{4}^{2})&2s(q_{2}q_{3}- q_{4}q_{1})&2s(q_{2}q_{4}+q_{3}q_{1})\\ 2s(q_{2}q_{3}+q_{4}q_{1})&1-2s(q_{2}^{2}+q_{4}^{2})&2s(q_{3}q_{4}-q_{2}q_{1})\\ 2s(q_{2}q_{4}-q_{3}q_{1})&2s(q_{3}q_{4}+q_{2}q_{1})&1-2s(q_{2}^{2}+q_{3}^{2}) \end{bmatrix} \tag{5b}\]  
where \(s\) is the quaternion's norm.