## 5 Discussion
Given that the computational capabilities of the microcontrollers are not exceeded, it can be seen that there is no relationship between the capacity usage and the controller performance as seen in Table 6 for nadir pointing and in Table 7 for detumbling. The originally proposed framework is applicable for the validation of any control system that includes a magnetometer as attitude sensor. Moreover, the scalable potential of this framework allows its adaptation to validate systems of higher volume and complexity due to the modularity and flexibility of the proposed system, allowing developers to include in the simulation the dynamics of the analyzed spacecrafts and mathematical models of sensors or actuators, or even to physically implement other sensors, which also involves modifying the controlled environment to obtain reliable results. In addition, the versatility of the proposed approach provides the necessary tools to implement code generation using SIL and PIL in embedded systems with low computational resources, assuming that the sensor readings are performed directly by the controller and considering the restrictions discussed in Section 3.2, such as the alignment of sampling times between the simulation and the controller, as well as that the controller board supports C99 (ISO), to ensure the consistency of the model and its corresponding code. Based on the HIL environment, the on-orbit calibration task was also simulated and executed, since the magnetometer is supposed to obtain accurate data once in orbit. In addition, the magnetometer was calibrated considering external and internal errors modeled with a robust algorithm. Subsequently, the algorithm was run during detumbling mode, so that the physical magnetometer was able to collect data in all axes simulating on-orbit performance. Given that the same controller was executed in all the environments and in the same conditions, a clear relationship between the high latency in HIL (4 ms and 12 ms) and the performance of the B-dot controller could be inferred due to its high angular velocity resultant seen in Figure 20, resulting in an error of approximately 0.07% compared to MIL. As a result, to increase the fidelity of HIL, the latency must be reduced in order to obtain significant results. The accuracy of SIL decreases compared to MIL, possibly because dedicated Simulink blocks optimize the MIL environment. The use of the \"C Caller\" block in SIL can introduce dependencies that result in algebraic loops, negatively affecting the accuracy and performance of the simulation. Regarding the performance of the evaluated controller, SIL stands out as an ideal simulation environment to establish the initial optimal conditions, since its performance is not influenced by other hardware. Taking advantage of this characteristic, the sensitivity analysis was conducted to obtain the most optimal control gains to minimize the pointing accuracy error in nadir pointing. The sensitivity analysis using Monte Carlo provided an insightful approach to the effect of the initial conditions of the simulated environment on the performance of the controller. In this regard, starting with a high initial angular velocity requires increased effort from the actuators, leading to a higher pointing error as seen in Figure 15. As angular velocity decreases, the error should also decrease. Nevertheless, small fluctuations in the velocity make the error increase. It must be noted that this phenomenon could be caused by factors of the system dynamics model, such as numerical method inaccuracies, sensor reading anomalies prevalent at exceedingly low velocities, sampling noise, Gaussian perturbations, or, predominantly, quantization effects inherent to bit resolution.