# In-Orbit Attitude Determination of the UVSQ-SAT CubeSat Using TRIAD and MEKF Methods
## 3 Attitude Determination Methods  
### Tri-Axial Attitude Determination Method (TRIAD)  
#### Formulation of the Method  
The TRIAD algorithm aims to determine the attitude of the CubeSat. The output of the algorithm is the rotation matrix from the orbit reference frame (O) to the body reference frame (B). This matrix is also called the attitude matrix. The calculations are done instantaneously using two known vectors in both of the reference frames. The inputs required to compute the attitude matrix are the Sun LOS and the magnetic field in the two reference frames. In the body reference frame, the vectors are determined from the UVSQ-SAT measurements. In the orbit reference frame, the inputs are computed from the International Geomagnetic Reference Field [22] and orbital models at the satellite's location and time. We note that in an eclipse, we use nadir vectors instead of Sun LOS vectors. The nadir vector is defined as \(N\) in the body frame and \(N_{o}\) in the local orbital frame. The method is described in sunlight in the Equations (10) and (11). For the eclipse periods, \(N\) and \(S\) would commute. Nevertheless, less accurate results are expected in an eclipse since it is more complicated to determine the nadir from the infrared sensors rather than the Sun LOS.  
To compute the attitude from the TRIAD algorithm, we introduce a new reference frame based on the body and orbital reference frames. This new reference frame is called the TRIAD frame and was described in [23; 24]. The TRIAD frame is meant to be an intermediary between the orbital and the body frame; therefore, it should be easily defined in each of those reference frames. This reference frame is based on the magnetic field and the Sun LOS vectors. Let us start by expressing the TRIAD frame in the body reference frame, which is described as \(\{\textbf{t}_{\textbf{1b}},\ \textbf{t}_{\textbf{2b}},\ \textbf{t}_{\textbf{3b}}\}\) in Figure 7. Ideally, the most accurate vector should be used as the first axis. Usually, Sun sensors are more accurate than magnetometers. The Sun LOS is therefore chosen as the first direction. This axis is often called the anchor as it remains unchanged. Thus, the frame can be described in the body reference frame as (Equation (10))  
\[\textbf{t}_{\textbf{1b}}=\frac{\textbf{S}}{\|\textbf{S}\|},\ \textbf{t}_{ \textbf{2b}}=\frac{\textbf{S}\times\textbf{B}}{\|\textbf{S}\times\textbf{B}\| },\ \textbf{t}_{\textbf{3b}}=\textbf{t}_{\textbf{1b}}\times\textbf{t}_{\textbf{2b}} \tag{10}\]  
where **S** and **B** are the Sun LOS and magnetic field vector in the body frame retrieved from the instruments on-board the spacecraft, and the TRIAD's basis can be expressed as \(\{\textbf{t}_{\textbf{1o}},\ \textbf{t}_{\textbf{2o}},\ \textbf{t}_{\textbf{3o}}\}\) in the orbital frame, in Equation (11):  
\[\textbf{t}_{\textbf{1o}}=\frac{\textbf{S}_{\textbf{o}}}{\|\textbf{S}_{\textbf {o}}\|},\ \textbf{t}_{\textbf{2o}}=\frac{\textbf{S}_{\textbf{o}}\times\textbf{B}_{\textbf {o}}}{\|\textbf{S}_{\textbf{o}}\times\textbf{B}_{\textbf{o}}\|},\ \textbf{t}_{\textbf{3o}}=\textbf{t}_{\textbf{1o}}\times\textbf{t}_{\textbf{2o}} \tag{11}\]  
where \(\textbf{S}_{\textbf{o}}\) and \(\textbf{B}_{\textbf{o}}\) are the Sun LOS and magnetic field vectors in the orbital frame computed from models. Therefore, it is rather simple to recover the transfer matrix from the orbital to body frame via the TRIAD frame. The rotation matrix can be written as in Equation (12):  
\[R_{TRIAD,O\xrightarrow{}B}=[\textbf{t}_{\textbf{1o}},\ \textbf{t}_{\textbf{2o}}, \ \textbf{t}_{\textbf{3o}}][\textbf{t}_{\textbf{1b}},\ \textbf{t}_{\textbf{2b}},\ \textbf{t}_{\textbf{3b}}]^{T} \tag{12}\]