## 3 Simulation Environment and Approaches
### Model in the Loop
#### 3.1.2 Magnetorquer Model  
The implementation of the magnetorquer models in Simulink aimed to enhance simulation reliability by incorporating the various components that influence the system of these actuators. The control system circuit for this setup is depicted in Figure 6. Additionally, the objective was to examine whether the effects of loading and unloading the coils significantly impact the controller's performance. The design of the magnetorquer system included selecting components and setting values to simulate common errors that occur during the operation of integrated circuits. Each magnetorquer is depicted in a diagram with a set of four coils, configurable using MOSFETs, as shown in Figure 6b. This flexibility allows each magnetorquer to be arranged in parallel, series, or mixed arrays. Moreover, the ICDRV8848 motor controller [46] is considered for precise current flow control [47]. To meet the dipole moment requirements determined by the tested control system, values are processed using known and established data on the number of turns and the area of each magnetorquer, as expressed in Equation (5). This calculation determines the necessary current flow through each set of coils. These calculated values are then trans  
Figure 5: Simulink block with the conditioning trans-impedance circuit for each SLCD-61N8 sun sensor. Figure 6: Integrated magnetorquer design and simulation diagram. (**a**) CAD-rendered 3D model of the magnetorquer PCB, (**b**) diagram of reconfigurable magnetorquer coils, (**c**) schematic of the magnetorquer circuit, (**d**) Simscape Electrical blocks integrated within the Simulink model. mitted to the controller ports to ensure an adequate current supply to the magnetorquers. Depending on the current demands, the configuration control system adjusts the arrangement of the four coils by varying the activation and deactivation of ten MOSFETs, visible in Figure 6d, that act as switches. Representative models were chosen for each coil to closely approximate real component behaviors, incorporating resistance and capacitance [48] into each coil model. This comprehensive approach ensures that the simulations closely mimic real-world scenarios, thereby enhancing the accuracy and reliability of the magnetorquer system's performance evaluation. For each coil in any magnetorquer configuration, the magnetic moment is given by a term \(D_{or}\), so the relationship between voltage and current must be adjusted so that each coil receives the same current. The voltage and current supplied by the controller are characterized by the following equivalences:  
\[V=n\cdot V_{o},I=m\cdot I_{o} \tag{27}\]  
Likewise, the total magnetic moment generated by each magnetorquer is given by the following:  
\[D_{total}=(n\cdot m)\cdot D_{o} \tag{28}\]  
where \(n\) and \(m\) are the number of rows and columns of coils for the established configuration. This process was integrated into the magnetorquer control system in Simulink with its general behavior previously explained. For a more detailed simulation, physical aspects such as the number of turns of 60 and a resistance of \(70[\Omega]\) are considered within the modeling of each of the three magnetorquer systems. The other parameters adopted are shown in Table 3, determined thanks to [49]. The current through each coil is 0.020 A, the maximum current allowed being 0.80 A in the configuration of the four coils in parallel. The schematic design of this magnetorquer control circuit was performed at PROTEUS, where the assembly for the PCB was carried out. Figure 6a shows a CAD model of the PCB for this model. In Figure 6c, the circuit layout can be seen, as well as the magnetorquer coils integrated on the PCB. In the model visible in Figure 6d, the circuit designed in Simulink can be observed, where the data processing based on the calculated current is performed. Through a PWM signal with a current direction indicator, a simulated block mimics the driver behavior with outputs coupled to the reconfigurable magnetorquer coil circuit.