Main Content

Projects Template for Flight Simulation Applications

Flight Simulation Applications

Use projects to help organize large flight simulation modeling projects and makes it easier to share projects with others. This template provides a framework for the collaborative development of a flight simulation application. You can customize this project structure for specific applications.


To successfully run this example, install a C/C++ compiler.

The Aerospace Blockset™ software supplies a projects template that you can use to create your own flight simulation application. This template uses variant subsystems, model variants, and referenced models to implement flight simulation application components such as:

  • An airframe that contains a 6DOF equation of motion environment model and actuator dynamics

  • An inertial measurement unit (IMU) sensor model

  • A visualization subsystem oriented for FlightGear

  • A model of the nonlinear dynamics of the airframe

  • A model of the linear dynamics of the airframe

Download the Flight Simulation Template

  1. From the Simulink® Start Page, select Flight Simulation.

  2. In the Create Project window, in Name, enter a project name, for example FlightSimProj.

  3. In Folder, enter a project folder or browse to the folder to contain the project, for example FlightSimFolder.

  4. Click OK.

    If the folder does not exist, the dialog prompts you to create it. Click Yes.

    The software compiles the project, populates the project folders, and opens the main model, flightSimulation. All models and supporting files are in place for you to customize for your flight simulation application.

Contents of the Project Template

The flight simulation project template contains these folders

  • mainModels

    Contains the top-level simulation model, flightSimulation. This model opens on startup. This file contains the top-level blocks for the flight simulation environment. Simulink uses the Variant Subsystem, Model Variants, and Model blocks at this level to adapt to the different simulation conditions.

    • The aircraft airframe can vary between a nonlinear an linear approach.

    • The commands to the aircraft can vary between a Signal Editor block, a joystick or a variable from the workspace.

    • Sensors can vary between models that include sensor dynamics or feedthrough (no associated dynamics).

    • Environment values can vary between state-dependent values (the values of temperature, pressure and so on depend on local position, latitude, etc.) or constant values that do not depend on state values.

    • The Visualization subsystem provides hooks that let you work with the states. For example, you can visualize the states using FlightGear or they can be recorded in a variable in the workspace for further analysis. States can also be visualized using the Simulation Data Inspector.

  • libraries

    Contains the libraries used by the models.

  • nonlinearAirframe

    Contains a model of the nonlinear dynamics of the airframe.

    • A specific subsystem (AC model) that contains a placeholder for the dynamics of your aircraft model. The characteristics of this subsystem are:

      • Actuators and environment inputs. Actuators refer to generic signals that may affect the behavior of the aircraft (for example an electric signal in voltage that will change the position of the hydraulic actuator connected to a control surface such as an aileron).

      • Forces and moments outputs. Effective in the center of gravity of the aircraft in body axis.

    • A 6DOF Body Quaternion block that solves the differential equations of forces and moments to obtain the aircraft states.

  • linearAirframe

    Contains the linear dynamics of the airframe and the model to obtain these linear dynamics. The example obtains these dynamics by linearizing the nonlinear model using the trimLinearizeOpPoint function and trimNonlinearAirframe model. This function uses Simulink Control Design software to perform the linearization. It performs linearization of the nonlinear model for a given set of known inputs and conditions. For further information regarding trim and linearization, see the Simulink Control Design™ documentation). The trimLinearizeOpPoint function stores the output in a MAT-file.

  • controller

    Contains the models for the Flight Control System (FCS) and its design. These models contain referenced models for different controller architectures needed for the design of aircraft simulation.

  • src

    Contains source code such as C code. For simulation, it also has two folders that contain S-functions for simulation. These S-functions map buses to vectors and vice versa for the linear airframe model. This mapping can be changed depending on the linearization scheme, and the set of inputs and outputs for the model. To edit the indices for the different signals, you can use the S-Function Builder block.

  • tasks

    Contains scripts to run the model. These scripts do not run continuously during the simulation process.

    The folder also contains the non-virtual bus definitions for the states, environment, and sensor buses. These definitions, set the signals and characteristics that different elements in the simulation environment use. This folder also contains the definitions for the variables used in the mask workspace for the Sensors, FlightGear, linearAirframe and nonlinearAirframe blocks. These utilities store parameter values in data structures. For example, if the nonlinear model uses a parameter for a Gain block, the stored variable in the structure is Vehicle.Nonlinear.Gain.gainValue, which points to the parameter.

  • tests

    Contains a sample test harness:

    • The linearTest file contains the actual test point. This file compares a subset of the outputs of the linearized airframe model to the outputs of the nonlinear airframe for the specific trim condition.

    • The runProjectTests file runs all the available files classified as "Tests" in the project.

  • utilities

    Contains project-specific maintenance task utilities, such as:

    • projectPaths - Lists the location of folders to be added to the MATLAB® path.

    • rebuildSFunction - Rebuilds S-functions for linearInputBus and linearOutputBus.

    • startVars - Defines the variables that the simulation environment requires to be in the base workspace. This utility also controls variants using the Variants structure. This structure lets the example switch between the nonlinear and linear airframe from the workspace by changing VSS_VEHICLE from 1 (for the nonlinear model) to 0 (for the linear model). For more information on subsystem variants see Model.

  • work

    Contains files generated from every run. These files derive from source files, such as the MEX-file that you build from S-function C code.

In Shortcuts, projects creates shortcuts for common tasks:

  • Initialize Variables — Runs the startVars script, which initializes the variables to the base workspace.

  • Rebuild S-functions —Rebuilds the S-functions in the src folder.

  • Run Project Tests —Runs the test points, labeled Tests, for test files in the project.

  • Top Level Simulation Model — Opens the flightSimulation model. It runs on project startup.

Template Labels

Provides file classification labels for automatic and componentization sorting. This utility adds template labels such as Tests, Airframe Design, Flight Controller Design, and Calibration Data.

Add Airframe Dynamics and Controller Algorithm to the Project

  1. To open the linearAirframe model, in flightSimulation double-click the Airframe subsystem.

  2. Double-click the Nonlinear subsystem.

  3. In the AC model, add your airframe dynamics.

  4. Save the model.

Add Controller Algorithm to the Project

  1. To open the flightControlSystem model, in flightSimulation, double-click the FCS subsystem.

  2. In the Controller subsystem, add your controller algorithm.

  3. Save the model.

Other things to try:

  • Simulate your model.

  • Explore the tests folder for sample tests for your application.

Related Examples

More About