# A Tutorial and Review on Flight Control Co-Simulation Using Matlab/Simulink and Flight Simulators

^{*}

## Abstract

**:**

## 1. Introduction

## 2. Communication Protocols for Real-Time Co-Simulation

## 3. A Comparison of Flight Simulation Software Used for Co-Simulation

## 4. Groundstation Programmes and Communication Protocols

## 5. Implementations of Matlab/Simulink with Xplane and FlightGear

#### 5.1. The Matlab/Simulink and Xplane Co-Simulation

#### 5.2. The Matlab/Simulink and FlightGear Co-Simulation

**J**is the moment of inertia matrix. The forces and moments models that relate ${F}_{\mathrm{b}}$ and ${m}_{\mathrm{b}}$ to the elevator, aileron, rudder, throttle inputs, and the states of the system were taken and modified from the model developed by Christopher Lum for the RCAM research aircraft, which was originally developed by the Garteur group (see [27]), but the model was modified for the Rascal-110, which has a single central axial propeller. The trim condition ${x}^{*},{u}^{*}$ where ${x}^{*}={\left[{V}_{\mathrm{b}}{}^{*T},{\omega}_{\mathrm{b}}{}^{*T},{\varphi}^{*},{\theta}^{*},{\psi}^{*}\right]}^{T}$ is the state vector and ${u}^{*}$ is the trimmed control inputs vector was computed by minimizing the quadratic error cost function $J={\dot{x}}^{*T}{W}_{1}{\dot{x}}^{*}+{\dot{u}}^{*T}{W}_{2}{\dot{u}}^{*}$, where ${\varphi}^{*},{\theta}^{*},{\psi}^{*}$ are trim conditions on the roll pitch and yaw angle and ${W}_{1}$

**,**${W}_{2}$ are diagonal weighting matrices that are used for numerical conditioning and are typically multiples of the identity matrix. Minimizing the cost function leads to the equilibrium condition ${\dot{x}}^{*}={\mathbf{0}}_{\mathbf{9}\times \mathbf{1}},{\dot{u}}^{*}={\mathbf{0}}_{\mathbf{4}\times \mathbf{1}}$. The four components of the control vector ${u}^{*}=\left[{\delta}_{e}^{*},{\delta}_{a}^{*},{\delta}_{r}^{*},{\delta}_{t}^{*}\right]$ respectively represent the trimmed elevator, aileron, rudder, and throttle commands. The Simulink model is shown in Figure 13. Note that for Matlab versions 2021A or earlier, the GPS sensor should not be used. The operating condition for the simulation was a trim speed of 85 m/s with an altitude of 1000 m. Flight testing for this model consisted of manual control inputs with elevator inputs between −10 degrees and 25 degrees, throttle inputs between 0.5 degrees and 10 degrees, aileron inputs between −25 degrees and 25 degrees, and rudder inputs between −30 degrees and 30 degrees to validate the aircraft responses for nine state variables, namely the axial, vertical and lateral speeds, the attitudes and angular rates on all three axes.

## 6. Software-in-the-Loop Co-Simulation Using Matlab/Simulink and VFTE

#### 6.1. UAV Toolbox for PX4

^{®}allows for the use of Matlab/Simulink for SIL but also HIL simulation with small UAV NuttX-based autopilots, including the Pixhawk autopilots family. After installing the toolbox, it is necessary to set it up to work with a chosen hardware board using the configuration parameters options. The toolbox also has libraries allowing different types of connections for the key aircraft sensors, including inertial navigation sensors (INS), global positioning system (GPS) receivers, speed pressure sensors, servo actuation for the control surfaces and DC motors, battery monitoring, and other features. Figure 15 shows the Matlab/Simulink layout for a simple model used for initial sensor testing, and the HIL testing of the sensors and gyros is simply started by clicking on Monitor and Tune. Example models are also provided by Matlab to allow for gyro sensor calibration to remove bias and scaling errors, for example.

^{®}Series flight controllers. This requires the installation of the Embedded Coder

^{®}Support Package for PX4 Autopilots.

#### 6.2. SIL Simulation Using Matlab/Simulink and VFTE

**S**is the sensitivity function from low-frequency disturbance to output and

**T**is the complementary sensitivity function from reference to noisy output.

**S**needs to be minimized at low frequencies, and

**T**needs to be minimized at low frequencies, and the two conditions cannot both be satisfied at the same frequency because

**S**+

**T**=

**I**. The conditions in one frequency domain are, however, compatible because, at low frequencies,

**T**has to approach identity to ensure reference tracking.

**S**and

**T**are 2 × 2 matrices.

**K**(s) takes sideslip and bank angle data as inputs and outputs the aileron and rudder deflections. In the SIL example of Figure 17 and Figure 18, given that high-frequency IMU noise is filtered, ${W}_{T}$ is taken to be zero to focus on wind disturbance rejection and reference tracking, but noise rejection can also be explicitly accommodated if necessary using the same H-infinity commands. The ${W}_{s}$ matrix is diagonal with a low-frequency gain of 60 dB for disturbance rejection in both the aileron to roll and the rudder to yaw loops.

#### 6.3. HIL Simulation of A Small UAV Using Matlab/Simulink, VFTE, and CAN Interfacing

## 7. Discussion of the Limitations of Co-Simulation Methods

## 8. Conclusions

## Author Contributions

## Funding

## Institutional Review Board Statement

## Informed Consent Statement

## Acknowledgments

## Conflicts of Interest

## References

- Silva, W.R.; Da Silva, A.L.; Grundling, H. Modelling, Simulation and Control of a Fixed-Wing Unmanned Aerial Vehicle (UAV). In Proceedings of the 24th ABCM International Congress of Mechanical Engineering, Curitiba, Brazil, 3–8 December 2017. [Google Scholar]
- Ribeiro, L.R.; Oliveira, N.M.F. UAV Autopilot Controllers Test Platform Using Matlab/Simulink and X-Plane. In Proceedings of the Frontiers in Education Conference, Arlington, VA, USA, 27–30 October 2010. [Google Scholar]
- Yuceol, O.E.; Akbulut, A. Modeling and Simulation of a Small Unmanned Aerial Vehicle. Adv. Intell. Syst. Comput.
**2013**, 210, 245–255. [Google Scholar] [CrossRef] - Nugroho, L. Comparison of Classical and Modern Landing Control System for a Small Unmanned Aerial Vehicle. In Proceedings of the 2014 International Conference on Computer, Control, Informatics and Its Applications: “New Challenges and Opportunities in Big Data”, IC3INA 2014, Bandung, Indonesia, 21–23 October 2014. [Google Scholar]
- Cameron, B. Development and Implementation of a Cost-Effective Cockpit Interface Architecture for Flight Simulation. Master’s Thesis, The Carleton University, Ottawa, ON, Canada, 2016. [Google Scholar]
- Jalovecky, R.; Boril, J. Analyis of Measured Pilot Resonses during the Flight. Mosatt
**2013**, 2013, 6. [Google Scholar] - Pinguet, J.; Feyel, P.; Sandou, G. A Neural Autopilot Training Platform based on a Matlab and X-Plane co-simulation. In Proceedings of the 2021 International Conference on Unmanned Aircraft Systems (ICUAS), Athens, Greece, 15–18 June 2021; pp. 1200–1209. [Google Scholar] [CrossRef]
- Arif, A.A.; Stepen; Sasongko, R.A. Numerical Simulation Platform for a Generic Aircraft Flight Dynamic Simulation. Int. J. Eng. Technol.
**2018**, 7. [Google Scholar] [CrossRef] - Kaviyarasu, A.; Kumar, K.S. Simulation of Flapping-Wing Unmanned Aerial Vehicle Using x-Plane and Matlab/Simulink. Def. Sci. J.
**2014**, 64, 327–331. [Google Scholar] [CrossRef] - Aschauer, G.; Schirrer, A.; Kozek, M. Co-Simulation of Matlab and FlightGear for Identification and Control of Aircraft. IFAC-Papers
**2015**, 48, 67–72. [Google Scholar] [CrossRef] - Grady, N.B.; Frye, M.T.; Qian, C. The Instrumentation and Flight Testing of a Rotorcraft Vehicle for Undergraduate Flight Control Research. Available online: https://arc.aiaa.org/doi/10.2514/6.2006-6739 (accessed on 30 July 2022).
- Abioye, A.O.; Prior, S.D.; Saddington, P.; Ramchurn, S.D. The Performance and Cognitive Workload Analysis of a Multimodal Speech and Visual Gesture (MSVG) UAV Control Interface. Robot. Auton. Syst.
**2022**, 147, 103915. [Google Scholar] [CrossRef] - Sagliano, M. Open-Source Visualisation of Reusable Rockets Motion: Approaching Simulink–FlightGear Co-simulation. In Proceedings of the 2021 AIAA Scitech Forum, AIAA 2021-0410, Virtual, 11–15 & 19–21 January 2021. [Google Scholar] [CrossRef]
- Bulka, E.; Nahon, M. Autonomous Fixed-Wing Aerobatics: From Theory to Flight. In Proceedings of the IEEE International Conference on Robotics and Automation, Brisbane, Australia, 21–25 May 2018. [Google Scholar]
- Angonese, A.T.; Rosa, P.F.F. Ground Control Station for Multiple UAVs Flight Simulation. In Proceedings of the 2013 IEEE Latin American Robotics Symposium, LARS 2013, Washington, DC, USA, 21–27 October 2013. [Google Scholar]
- Madridano, Á.; Al-Kaff, A.; Martín, D.; de la Escalera, A. 3d Trajectory Planning Method for UAVs Swarm in Building Emergencies. Sensors
**2020**, 20, 642. [Google Scholar] [CrossRef] [PubMed] - Baidya, S.; Shaikh, Z.; Levorato, M. FlynetSim: An Open Source Synchronized UAV Network Simulator Based on Ns-3 and Ardupilot. In Proceedings of the MSWiM 2018—The 21st ACM International Conference on Modeling, Analysis and Simulation of Wireless and Mobile Systems, Montreal, QC, Canada, 28 October–2 November 2018. [Google Scholar]
- Sun, Y.; Zhen, Z.; Ou, C.; Pu, H. 3D Scene Simulation of UAVs Formation Flight Based on FlightGear Simulator. In Proceedings of the 2014 IEEE Chinese Guidance, Navigation and Control Conference, CGNCC 2014, Yantai, China, 8–10 August 2014. [Google Scholar]
- Johnson, C. Development of a Software in The Loop Simulation Approach for Risk Mitigation in Unmanned Aerial System Development. Master’s Thesis, Oklahoma State University, Stillwater, OK, USA, 2020. [Google Scholar]
- Millan, S. Realistic VTOL Simulator. Master’s Thesis, Catalonia Polytechnic University, Barcelona, Spain, 2020. [Google Scholar]
- Mattei, A.L.P.; Orbital, E.S.A.; Toledo, C.F.M.; Arantes, J.D.S.; Trindade, O., Jr. Unmanned Aerial Vehicles Flight Safety Improvement Using In-Flight Fd. Intell. Inf. Manag.
**2021**, 13, 97–123. [Google Scholar] [CrossRef] - Guther, A. Simconnect Toolbox for Matlab/Simulink. Available online: https://github.com/aguther/simconnect-toolbox (accessed on 30 July 2022).
- Koubaa, A.; Allouch, A.; Alajlan, M.; Javed, Y.; Belghith, A.; Khalgui, M. Micro Air Vehicle Link (MAVlink) in a Nutshell: A Survey. IEEE Access
**2019**, 7, 87658–87680. [Google Scholar] [CrossRef] - Allouch, A.; Cheikhrouhou, O.; Koubaa, A.; Khalgui, M.; Abbes, T. MAVSec: Securing the MAVLink Protocol for Ardupilot/PX4 Unmanned Aerial Systems. In Proceedings of the 2019 15th International Wireless Communications and Mobile Computing Conference, IWCMC 2019, Tangier, Morocco, 24–28 June 2019. [Google Scholar]
- Bittar, A. X-Plane Library.zip, MATLAB Central File Exchange. Available online: https://www.mathworks.com/matlabcentral/fileexchange/47516-x-plane-library-zip (accessed on 30 July 2022).
- Christopher Lum Solving Systems of Equations Using the Optimization Penalty Method. Available online: https://www.youtube.com/watch?v=rx2vUzjuDc0 (accessed on 30 July 2022).
- Garteur. Robust Flight Control Design Challenge Problem Formulation and Manual: The Research Civil Aircraft Model (RCAM). Available online: https://www.scienceopen.com/document?vid=127ac6ee-15a3-438d-b3c8-f023dfbb83dd (accessed on 30 July 2022).
- The Mathworks, Inc. Position Tracking for X-Configuration Quadcopter. Available online: https://uk.mathworks.com/help/supportpkg/px4/ref/position-tracking-example.html (accessed on 30 July 2022).
- The Mathworks Inc. Scenario Simulation and Flight Visualization with PX4 Hardware-in-the-Loop (HITL) and UA Dynamics in Simulink. Available online: https://uk.mathworks.com/help/supportpkg/px4/ref/flight-visualisation-hitl-simulink.html (accessed on 30 July 2022).
- Hopf, J.; Dommaschk, J.; Block, N.; Reinfeld, R.; Krachten, M.; Worrmann, P.; Cracau, D.; Köthe, A. Unmanned Aircraft Experimental System: The Flying Lab for Applied Flight Control and Flight Mechanics. Available online: https://www.dglr.de/publikationen/2020/530237.pdf (accessed on 30 July 2022).

**Figure 14.**FlightGear and QGroundControl windows during the Simulink-FlightGear-QGroundControl simulation of the Rascal 110 UAV.

**Figure 16.**Key sensing, actuation and communication libraries of the UAV support package for PX4 from The Mathworks, Inc., Natick, MA, USA.

**Figure 17.**PID autopilots in the X-configured quadcopter SIL position tracking example by The Mathworks, Inc. [28].

**Figure 18.**Control channels allocation/mixing for the X-configured quadcopter SIL position tracking example by The Mathworks, Inc. [28].

**Figure 19.**HIL simulation architecture using a Pixhawk 4 with a Simulink-Unreal Engine co-simulation [29].

**Figure 20.**Example Nano Talon flight control model for Simulink/VFTE lateral flight co-simulation (Developed from Alphalink Engineeing GmbH (Berlin, Germany) training resources).

**Figure 21.**Detail of the observer-based Nano Talon lateral flight controller block of Figure 20.

**Figure 22.**VFTE window view during the SIL co-simulation using the Simulink lateral observer/controller loop.

**Figure 23.**HIL architecture using Pixhawk (courtesy of Alphalink Engineeing GmbH (Berlin, Germany)).

Xplane [1,2,5,8,9,20] | FlightGear [10,18,20] | RealFlight [11,20] | |
---|---|---|---|

Dynamical model | Blade element method allows for a higher fidelity modeling of the effects of local aerodynamic forces and moments acting on the aircraft, even if there are limitations under certain conditions such as stall [1]. | Default model JBSim: A generic 6DoF flight dynamics model written in C++. Mass properties, aerodynamic and control parameters are entered in an XML configuration file. The alternative YASim model can also be selected in FlightGear, which allows for the simulation of the airflow on different parts of the aircraft to account for aircraft geometry information. Live weather model using Metar data. | RealPhysics™ 3D, model was RC pilot tested. Accurate Truflo wind dynamics. |

Aircraft types | General aviation, airliners, large rotorcraft, military aircraft, and custom designs including drones, eVToL, quadcopters, but some popular hybrid configurations such as conventional quadplanes are missing and not straightforward to design using Planemaker. Users can additionally upload aircraft models on https://forums.x-plane.org/index.php?app=downloads accessed on 30 August 2022. | General aviation, airliners, military aircraft, large drones (MQ9) and custom designs are available for small to large UAVs (Rascal, Aerosonde, HALE and MALE UAV) but there is a lack of working quadcopter designs, hybrid UAV, which were not the intended use case of FlightGear at its creation. | Very popular for small UAV designs [20], Remotely controlled (RC) aircraft, from small quadcopters, quadplanes, hybrid aircraft and other autonomous aerial vehicles. More conventional large aircraft from general aviation to airliners, helicopters and fighter jets are also present. |

Aircraft design tools | Planemaker allows for a detailed definition of aircraft geometry for aircraft parts from fuselage to body. | Openscenegraph opens several formats including AC3D VRML1, DXF. It also has a Model Airplane Designer tool. | AccuModel™ aircraft editor can be used to enter key aircraft mass and geometry characteristics. |

3D scene realism | High quality scenery with global coverage. Free OpenSceneryX library of 3D objects. | High definition scenery with particularly good detail over Europe and the USA, as part of a global scenery [18]. | Advanced 3D graphics technology Compatible with the Oculus Rift and HTC Vive |

Product availability | Commercial (USD 60) | Freeware including source code | Commercial (USD 100) |

Platforms | Multi-platform, Windows, macOS, and Linux | Multi-platform Windows, macOS, and Linux | MS Windows only, does not support Linux |

Program execution and co-simulation simplicity | Easy to execute and well documented interfacing with other tools such as Matlab/Simulink and SITL. | Simple to run but co-simulation process requires careful editing and use of batch files [9]. | Co-simulation has been developed with Ardupilot SITL, which was itself interfaced with Matlab. There is a lack of data on direct Simulink interfacing, with very few exceptions as in [11]. |

Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |

© 2022 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Horri, N.; Pietraszko, M.
A Tutorial and Review on Flight Control Co-Simulation Using Matlab/Simulink and Flight Simulators. *Automation* **2022**, *3*, 486-510.
https://doi.org/10.3390/automation3030025

**AMA Style**

Horri N, Pietraszko M.
A Tutorial and Review on Flight Control Co-Simulation Using Matlab/Simulink and Flight Simulators. *Automation*. 2022; 3(3):486-510.
https://doi.org/10.3390/automation3030025

**Chicago/Turabian Style**

Horri, Nadjim, and Mikolaj Pietraszko.
2022. "A Tutorial and Review on Flight Control Co-Simulation Using Matlab/Simulink and Flight Simulators" *Automation* 3, no. 3: 486-510.
https://doi.org/10.3390/automation3030025