**2. The processor in the loop (PIL) and hardware in the loop (HIL) simulation approach**

In Software-In-The-Loop (SIL) the model used in the MIL test is replaced by an executable code running at the same computer platform in a fixed-point arithmetic manner. This step helps the system developer to find fast some wrong memory sizing choices. Normally these two steps are made using a single integrated platform in a PC. The SIL step can be bypassed if your controller system will run in a piece of hardware that has a floating point dedicated

The following test consists in the PIL (Processor-In-The-Loop) that goes beyond the PC platform. This step introduces some hardware features that permit to achieve more realistic situations where the control algorithm will run. In PIL the target processor is a non-real time environment and the communication with the external processors is given by using specific

PIL requires drivers to communicate the computer platform with the aimed hardware. The resulting object code generated in the PC links with other test-management functionality and is then downloaded, typically to an off-the-shelf evaluation board with the target processor. The simulation tool, running on the PC machine, then communicates with the downloaded

The PIL simulation follows the simulation tool installed in the computer send test values to the firmware installed in the processor of the evaluation board, through a serial link and waits

The software real time operation cannot be tested in the PIL, this step is done by the HIL test. Although at first sight, this can be seen as a limitation, in fact this permits to break the simulation problem in two parts that can be verified before we have the certainty that the controller firmware will run correctly in the standalone processor platform. PIL permits to test if the compile optimizations effects in a non-real time execution platform with the presence of

As the last step of an embedded controller system development HIL is presented. HIL simulation must include electrical emulation of sensors and actuators in a real time target platform before the controller be validated with real sensors and actuators of the plant. These electrical emulations act as the interface between the plant simulation and the embedded system under test all of them in the same platform. The value of each electrically emulated sensor is controlled by the plant simulation and is read by the embedded system under test bringing a real time feedback next to the real situation that the controller will face before to be

Nowadays there are some model-driven platforms that allows the engineer develop the above simulation step of the controller. Latelly, Mathworks© and National Instruments© are the most known platforms. This work concentrates in presenting the development steps of an

functions installed in a simulation integrated environment installed in the host PC.

for the processor response through the same or another communication channel.

an off-the-shelf processor platform where the firmware will finally run.

attitude control model in the MATLAB – Simulink tool from Mathworks©.

software, typically via a serial communication link.

installed to control a physical plant.

unit in its CPU datapath.

158 Computational and Numerical Simulations

In the PIL application example described in section 3, we use MATLAB/Simulink environment both for a design procedure, code generation and for perform a PIL co-simulation together with a device. In the following paragraphs we describe some works that has some relationship with our work regarding the use of a development environment, code generation and cosimulation. The focus was in works with aerospace application where we presented their proposition, the hardware and tools used as well as the co-simulation scheme done.

In [2], simulations SIL and PIL were performed to obtain an attitude determination and control system (ADCS) for the microsatellite CKUTEX from Cheng Kung University. The SIL simu‐ lation is made using the MATLAB software and after, the PIL simulation is implemented using a PIC microcontroller to the implantation of the ADCS algorithm while the satellite dynamics is implemented in NI-PXI platform and coded by Labview software. According to the authors, the attitude determination and control system that was obtained and tested, provided good results once the plant dynamic response obeyed the project specifications. In [3], the MATLAB software is used with the purpose of generate the code of an entire control system and the dynamics of two satellites (represented by two robots). In this work a physical simulator using two industrial robots is assembled for a simulation of proximity operations between satellites as *on-orbit servicing* (OOS) activities. A model of the satellites dynamics, its control, actuators and sensors (constituting the named Application Control System - ACS) is made in MATLAB/ Simulink by the tool named Real-Time Workshop (RTW). It generates a code supported by the operating system VxWorks that on the other hand, operate according this code, the monitoring and control system of the facility where the movement commands desired are sent to the robots. It is a HIL simulation where controllers, actuators, state observers, among other modeled modules in the MATLAB/Simulink can be removed of the ACS and included in their own hardware if necessary.

In [4], a true co-simulation approach is studied for control application running on a Field Programmable Gate Array processor (FPGA). The proposed approach adopts the LABVIEW Real-Time environment (from National Instruments©) to perform the simulation of an artificial satellite' dynamic model. This study simulates a reaction wheel and its control in Simulink exclusively for the controller design. Subsequently, the generated code is imple‐ mented on the FPGA. The entire system model attitude control is previously built and simulated in Simulink. The RTW generates the code that represents the satellite dynamics' mathematical model inside LABVIEW environment. In the case of the reaction wheel and its control, RTW generates the C code to simulate the dynamic model that must be adapted to the LABVIEW rules for FPGA programming.

In [5], the Simulink is used together with another MATLAB toolbox called xPC Target. This toolbox allows to perform prototyping, testing and development of real-time systems for running in general-purpose computers. The MATLAB/Simulink tools were used to generate executable code for the target computer from the model built in Simulink. The goal is to achieve simulation and real-time implementation of an algorithm integrating inertial navigation and GPS, using the validation and testing of the proposed algorithm in the FlightGear flight simulator (inside MATLAB), running on the host computer.

**3.1. The satellite attitude control problem**

handed coordinate frame.

rotation matrix is given by [9].

then:

y q

> fq

 fq

 y

 y

*ωib b* = *ϕ*˙ *θ*˙ *ψ*˙

*J ω*˙ *ib*

where *J* is the inertia matrix of the satellite, *τ<sup>d</sup>*

tions acting on the satellite, and *τ<sup>p</sup>*

*<sup>b</sup>* <sup>+</sup> *<sup>S</sup>*(*ωib b* )*J ωib <sup>b</sup>* <sup>=</sup>*τ<sup>d</sup> <sup>b</sup>* <sup>+</sup> *<sup>τ</sup><sup>p</sup>*

fy

fy

kinematic equation is given by:

equation is given by:

The mathematical model of the satellite attitude considers two reference systems: the orbital frame and the satellite body frame. The orbital frame moves jointly with the satellite. Its origin coincides with the satellite's center of the mass. The axis *z*<sup>0</sup> of the orbital frame is defined by the satellite radius vector, the axis *y*<sup>0</sup> by the orbital normal, and the axis *x*<sup>0</sup> completes a right

Processor-in-the-Loop Simulations Applied to the Design and Evaluation of a Satellite Attitude Control

The body frame (*x*, *y*, *z*) has its origin in the center of mass of the satellite. Their axes coincide with the satellite's principal axes of inertia. We consider the case where the nominal attitude has axes of the body frame aligned with the axes of the orbital frame [8]. The Euler angles are adopted as parameters of attitude, considering the sequence of rotations 3-2-1. In this case, the

> cos cos cos cos sin cos sin sin sin cos cos cos sin sin sin sin cos sin sin cos sin cos sin cos cos sin sin cos cos

*<sup>X</sup> Rx* (1)

 f y

é ù ê ú =- + <sup>+</sup> ë û + -+

 f y

The kinematics equation is obtained by the time derivative of the rotation matrix equation [8],

The kinematics equation can be simplified if one considers small angle maneuvers, in this case we can approximate: sin*ϕ* ≈*ϕ*, sin*θ* ≈*θ*, sin*ψ*≈*ψ*, cos*ϕ* ≈1, cos*θ* ≈1 and cos*ψ*≈1. Moreover, the non-linear terms (*ψ*˙ *θ*, *ψ*˙ *ϕ*, *θ*˙*ϕ*) are very small compared to the linear ones. The velocities are also small compared to the orbital velocity [10]. Considering those approximations the

+ *ω*<sup>0</sup>

In this work the satellite is modeled as a rigid body. Therefore the dynamic model can be obtained with the Euler equation that describes the rotation of a rigid body [9, 11]. The dynamic

*b*

−*ψ* −1 0

y q

fqy

fqy

*R*˙ (*t*)=*S*(*ω*(*t*))*R*(*t*) (2)

q

http://dx.doi.org/10.5772/57219

161

(3)

 f q

 f q

*<sup>b</sup>* (4)

represents the torques from external perturba‐

*<sup>b</sup>* represent the control torques (*τx*, *<sup>τ</sup>y*, *<sup>τ</sup>z*), all vectors

In order to exemplify the possibility of use of different development environment to perform SIL and PIL simulations of a satellite control system; in the work of [6], a SIL simulation is made in MATRIXx environment where is obtained and tested the control algorithm, simulated the space environment and the satellite dynamics. This same software is used to generate the controller code, that after is downloaded in the satellite processor while its model is ported to a DSP that is controlled by a computer. This computer runs the real-time simulation together with the satellite processor, controlling the actuators and sensors signals too, in a PIL simula‐ tion. An interface allows the user to interact with the simulation, monitoring and changing simulation parameters in real-time.

In the cited works, is observed as the simulations SIL, PIL and HIL can be useful in controllers project and test to aerospace applications and as this simulations can be implemented in different ways, different virtual development environments and together with several hardware platforms. The results are not only obtained much more quickly but come from tests very cheap that those made in a real platform, which is often not accessible to the researchers. Furthermore, the interaction with the user in real-time and the analysis instruments, available by co-simulation tools, make the tests much more dynamic and enables the analysis of the system response in situations more realistic.

Today there are many co-simulation tools and many are the possibilities of combination between these tools and the several processors hardware platforms. Such tools are in contin‐ uous development and making possible the coupling with several hardware platforms from different manufacturers, including additional functional facilities to become easier the task of development.

In these studies, the Simulink is used as a friendly graphical tool for systems development, design and generation of executable code for various devices and applications. The following section presents more details of a control system design procedure using the PIL approach, Simulink tools and a DSP processor.
