# Micro-Satellite Systems Design, Integration, and Flight
## 4 Attitude Control System (ACS) Development
### Attitude Control
#### 4.3.3 The Controller Software  
The ACS software for Alpha is built in Simulink with the parameters set in a MATLAB(r) script. The Simulink model has a controller that can switch between the Kane damper and the PD controller when needed. A plant was added to simulate the system dynamics. The final goal was to put the controller that was tuned in the end into the Arduino flight code as a C++ library file. [PERSON] created the original code for his master's \begin{table}
\begin{tabular}{c c c c c} \hline \hline  & **Quadratic Cost** & \(\theta\) **End Point Error** & \(\theta\) **Standard Deviation** & **Rise Time** \\ \hline PD controller & 1.309573 & 9.28393 \(\times\) 10\({}^{-2}\) & 4.857353 \(\times\) 10\({}^{-2}\) & 8.57 \(\times\) 10\({}^{-1}\) \\ P + V Controller & 55.709082 & 8.239661 \(\times\) 10\({}^{-3}\) & 1.061509 \(\times\) 10\({}^{-2}\) & 3.90 \(\times\) 10\({}^{-1}\) \\ P + V Double Integrator & 2.544054 & 1.216665 \(\times\) 10\({}^{-1}\) & 1.044603 \(\times\) 10\({}^{-2}\) & N/A * \\ Double Integrator gain tuning & 6.579885 & 1.087292 \(\times\) 10\({}^{-1}\) & 1.085613 \(\times\) 10\({}^{-2}\) & 7.80 \(\times\) 10\({}^{-1}\) \\
2 DOF feed forward & 6.147382 & 2.911532 \(\times\) 10\({}^{-2}\) & 1.115621 \(\times\) 10\({}^{-2}\) & 8.00 \(\times\) 10\({}^{-1}\) \\ P + V Control Law Inversion & 6.127791 & 2.929454 \(\times\) 10\({}^{-2}\) & 1.106685 \(\times\) 10\({}^{-2}\) & 8.00 \(\times\) 10\({}^{-1}\) \\ Open loop guidance (DQC) & 6.181200 & 5.775071 \(\times\) 10\({}^{-3}\) & 5.761962 \(\times\) 10\({}^{-2}\) & 8.00 \(\times\) 10\({}^{-1}\) \\ Real-Time Optimal Controller & 6.169038 & 1.865604 \(\times\) 10\({}^{-5}\) & 2.710996 \(\times\) 10\({}^{-3}\) & 8.10 \(\times\) 10\({}^{-1}\) \\ \hline \hline \end{tabular}  
* does not have a formal rise time.  
\end{table} 
Table 6: Characteristics of optimized industry standard controllers. \begin{table}
\begin{tabular}{c c} \hline \hline
**Sample Rates (Seconds)** & **Rise Time (Seconds)** \\ \hline
0.1 & 8.67 \(\times\) 10\({}^{-1}\) \\
0.01 & 8.29 \(\times\) 10\({}^{-1}\) \\
0.001 & 8.20 \(\times\) 10\({}^{-1}\) \\ \hline \hline \end{tabular}  
\end{table} 
Table 7: Robustness of the controller to varying sample rates. thesis [19]. However, traceability was needed to meet the system requirements for the CubeSat ACS. Traceability began with naming each flow with the correct variable. Also, at every point where something interacted, the equation that was used was referenced. Referencing each calculation made it possible for outside experts to easily check the control algorithm. Each step could be linked back to a basic equation, ensuring the algorithm was accurate. After traceability was performed, the controller was checked for functionality. A Verification Cross Reference Matrix (VCRM) was used to check for functionality. The VCRM showed the changes that were needed in the code. Some of the values that were changed were the starting spin conditions, expected orbital inclination, orbital height, the mass of the CubeSat, the number of loops in each coil of the magnetorquer, and the area of the magnetic torquer. These variables were redefined in the MATLAB(r) script. The controller was checked by running a simulation with a plant model of the dynamics. When the simulation ran, it was clear that a certain parameter made the controller achieve stable steady-state values too quickly. See Figure 34 below for the first results of the simulation. The CubeSat ACS parameters were tested for validation after seeing the simulation outcomes. The first try was to revise the principal moment of inertias. Experimental moments of inertia values were needed because the values estimated by SOLIDWORKS lacked many of the smaller components, making their evaluation artificially low. Experimentally Calculating the Moment of Inertia of the ChipSat  
The angular acceleration is found using [PERSON]'s second law of rotation and acquiring Alpha from the net torque that the magnetic torque coils apply and the CubeSat's moment of inertia.