## 2 ADCS System Model
### Attitude Determination Algorithm  
Before computing the attitude controller, an attitude determination method is needed for both sunlight and eclipse zones. Regardless of the zone, an Extended Kalman Filter (EKF) is applied in order to estimate the state vector \(\mathbf{x}=\left[\mathbf{\omega}^{T}\quad\mathbf{q}^{T}\right]^{T}\). Due to the hardware restrictions of the selected MCU, the aforementioned WMM2020-2025 is used, noting that the change of frame between NED and \(\mathcal{O}\) is given by the following:  
\[\mathcal{O}\mathbf{B}_{\text{Earth}}= \begin{bmatrix}-\sin(\phi)\cdot\cos(\lambda)& -\sin(\phi)\cdot\sin(\lambda)&\cos(\phi)\\ -\sin(\lambda)&\cos(\lambda)&0\\ -\cos(\phi)\cdot\cos(\lambda)&-\cos(\phi)\cdot\sin(\lambda)&-\sin(\phi)\\ \end{bmatrix} ^{NED}\mathbf{B}_{\text{Earth}} \tag{13}\] \begin{table}
\begin{tabular}{c c c} \hline \hline
**Perturbation** & **Abbreviation** & **Value [Nm]** \\ \hline Gravity gradient torque & \(L_{GG}\) & \(1.347\times 10^{-10}\) \\ Aerodynamic torque & \(L_{aero}\) & \(1.205\times 10^{-7}\) \\ Magnetic torque & \(L_{mag}\) & \(1.944\times 10^{-7}\) \\ Total torque & \(L_{d-max}\) & \(3.150\times 10^{-7}\) \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Maximum disturbance torque. Furthermore, assuming a sunlight zone, the Triad method is applied to get the DCM \([BN]\) as follows. First, the Triad vectors are computed:  
\[{}^{B}\hat{\mathbf{t}}_{1}={}^{B}\hat{\mathbf{s}},\quad^{B}\hat{\mathbf{t}}_{2}=\frac{{}^{B} \hat{\mathbf{s}}\times{}^{B}\hat{\mathbf{\varphi}}}{\|{}^{B}\hat{\mathbf{s}}\times{}^{B} \hat{\mathbf{\varphi}}\|},\quad^{B}\hat{\mathbf{t}}_{3}={}^{B}\hat{\mathbf{t}}_{1}\times{}^ {B}\hat{\mathbf{t}}_{2} \tag{14}\]  
And  
\[{}^{N}\hat{\mathbf{t}}_{1}={}^{N}\hat{\mathbf{s}},\quad^{N}\hat{\mathbf{t}}_{2}=\frac{{}^{ N}\hat{\mathbf{s}}\times{}^{N}\hat{\mathbf{\varphi}}}{\|{}^{N}\hat{\mathbf{s}}\times{}^{N} \hat{\mathbf{\varphi}}\|},\quad^{N}\hat{\mathbf{t}}_{3}={}^{N}\hat{\mathbf{t}}_{1}\times{}^ {N}\hat{\mathbf{t}}_{2} \tag{15}\]  
where \(\hat{\mathbf{s}}\) is the sun direction computed by using the gathered measurement for the six sun sensors and \(\hat{\mathbf{\varphi}}\) is the magnetic field vector. Then, the DCM description \([BN]\) is given by the following:  
\[[BT]=\left[{}^{B}\hat{\mathbf{t}}_{1}{}^{B}\hat{\mathbf{t}}_{2}{}^{B} \hat{\mathbf{t}}_{3}\right] \tag{16}\] \[[NT]=\left[{}^{N}\hat{\mathbf{t}}_{1}{}^{N}\hat{\mathbf{t}}_{2}{}^{N} \hat{\mathbf{t}}_{3}\right]\] (17) \[[BN]=[BT][NT]^{T} \tag{18}\]  
So, the quaternion \(\mathbf{q}\) corresponding to \([BN]\) is computed using [PERSON]'s method [41], which avoids division by zero. Additionally, the continuous computation of \(\mathbf{q}\) from \([BN]\) may lead to numerical discontinuities in \(\mathbf{q}\), caused by switching to \(-\mathbf{q}\), which represents the same rotation as \(\mathbf{q}\). Consequently, a mechanism is needed to ensure the numerical continuity of the quaternion. Assuming an adequate sampling time for the ADCS such that a sign switch occurs between \(q_{\max_{k+1}}\) and \(q_{\max_{k}}\), and considering that a quaternion satisfies \(|q_{\max}|\geq 0.5\), it follows that \(|q_{\max_{k+1}}-q_{\max_{k}}|=|-q_{\max_{k+1}}-q_{\max_{k}}|=2|q_{\max_{k+1}}|\geq\) 1. Thus, \(|q_{\max_{k+1}}-q_{\max_{k}}|\geq 1\) is used to check for quaternion sign switching. Additionally, the Shepperd method first computes the largest value \(q_{\max}^{2}\) from \(\{q_{1}^{2},q_{2}^{2},q_{3}^{2},q_{4}^{2}\}\). By applying the aforementioned criteria to \(q_{\max}\) and \(-q_{\max}\), quaternion numerical discontinuity is avoided. Moreover, as it was mentioned earlier, the DCM \([HN]\) can be quantified assuming a circular orbit.