Documentation

Flight Simulation Project Template

This document describes how to use the Flight Simulation project template using Simulink® Projects. This template provides a framework for the collaborative development of a flight simulation application. You can customize this project structure for specific applications.

Note: To successfully run this example you will need to have a C/C++ compiler installed.

Open the Template

In Create a New Project Using Templates, follow the steps to open the "Flight Simulation Example" template.

Project Folder Distribution

The template for the project contains the following folders:

mainModels:

Contains the top-level simulation model file 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 Builder 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. This model has:

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

  1. 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).

  2. 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 refer to the Simulink Control Design documentation). The trimLinearizeOpPoint 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. It 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. The S-function Builder block can be used to edit the indices for the different signals.

tests:

Contains a sample test harness for the template.

  • 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.

tasks:

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

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.

utilities:

Contains project-specific maintenance task utilities, such as:

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

  • cleanUpProject - Closes the project top-level model and cleans up remaining variables in the workspace.

  • 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 airframefrom 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 Variants).

work:

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

Template Shortcuts

Contains shortcuts that execute common tasks and utilities:

Clean Up Project:

Executes on project shutdown. It runs after the project is closed. This shortcut closes the flightSimulation model and clears the simulation variables in the workspace.

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.

Set-Up Project:

Sets up the project paths and the root path. This shortcut runs whenever the project is opened.

Top Level Simulation Model:

Opens the flightSimulation model. It runs on project start-up.

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.

Was this topic helpful?