| Aerospace Blockset™ | ![]() |
| On this page… |
|---|
About Aircraft Geometry Models Working with Aircraft Geometry Models |
Use this section to learn how to use the FlightGear flight simulator and the Aerospace Blockset software to visualize your Simulink aircraft models. If you have not yet installed FlightGear, see Introducing the Flight Simulator Interface first.
Simulink Driven HL-20 Model in a Landing Flare at KSFC

Before you can visualize your aircraft's dynamics, you need to create or obtain an aircraft model file compatible with FlightGear. This section explains how to do this.
You have a competitive choice of over twelve 3-D geometry file formats supported by FlightGear.
Currently, the most popular 3-D geometry file format is the AC3D format, which has the suffix *.ac. AC3D is a low-cost geometry editor available from www.ac3d.org. Another popular 3-D editor for aircraft models is Flight Sim Design Studio, distributed by Abacus Publications at www.abacuspub.com.
Aircraft models are contained in the FlightGearRoot/data/Aircraft/ directory and subdirectories. A complete aircraft model must contain a directory linked through the required aircraft master file named model-set.xml.
All other model elements are optional. This is a partial list of the optional elements you can put in an aircraft data directory:
Vehicle objects and their shapes and colors
Vehicle objects' surface bitmaps
Variable geometry descriptions
Cockpit instrument 3-D models
Vehicle sounds to tie to events (e.g., engine, gear, wind noise)
Flight dynamics model
Simulator views
Submodels (independently movable items) associated with the vehicle
Model behavior reverts to defaults when these elements are not used. For example,
Default sound: no vehicle-related sounds are emitted.
Default instrument panel: no instruments are shown.
Models can contain some, all, or even none of the above elements. If you always run FlightGear from the cockpit view, the aircraft geometry is often secondary to the instrument geometries.
A how-to document for including optional elements is included in the FlightGear documentation at:
http://www.flightgear.org/Docs/fgfs-model-howto.html
The flight dynamics model (FDM) specification is a required element for an aircraft model. To set the Simulink software as the source of the flight dynamics model data stream for a given geometry model, you put this line in data/Aircraft/model/model-set.xml:
<flight-model>network</flight-model>
You can quickly build models from scratch by referencing instruments, sounds, and other optional elements from existing FlightGear models. Such models provide examples of geometry, dynamics, instruments, views, and sounds. It is simple to copy an aircraft directory to a new name, rename the model-set.xml file, modify it for network flight dynamics, and then run FlightGear with the –aircraft flag set to the name in model-set.xml.
Many existing 3-D aircraft geometry models are available for use with FlightGear. Visit the download area of www.flightgear.org to see some of the aircraft models available. Additional models can be obtained via Web search. Search key words such as "flight gear aircraft model" are a good starting point. Be sure to comply with copyrights when distributing these files.
When creating your own geometry files, keep in mind that your graphics card can efficiently render a limited number of surfaces. Some cards can efficiently render fewer than 1000 surfaces with bitmaps and specular reflections at the nominal rate of 30 frames per second. Other cards can easily render on the order of 10,000 surfaces.
If your performance slows while using a particular geometry, gauge the effect of geometric complexity on graphics performance by varying the number of aircraft model surfaces. An easy way to check this is to replace the full aircraft geometry file with a simple shape, such as a single triangle, then test FlightGear with this simpler geometry. If a geometry file is too complex for smooth display, use a 3-D geometry editor to simplify your model by reducing the number of surfaces in the geometry.
Once you have obtained, modified, or created an aircraft data file, you need to put it in the correct directory for FlightGear to access it.
To install a compatible model into FlightGear, use one of the following procedures. Choose the one appropriate for your platform. This section assumes that you have read Installing and Starting FlightGear.
If your platform is Windows:
Go to your installed FlightGear directory. Open the data directory, then the Aircraft directory: \FlightGear\data\Aircraft\.
Put model-set.xml in that subdirectory, plus any other files needed.
It is common practice to make subdirectories for the vehicle geometry files (\model\), instruments (\instruments\), and sounds (\sounds\).
If your platform is UNIX or Linux:
Go to your installed FlightGear directory. Open the data directory, then the Aircraft directory: $FlightGearBaseDirectory/data/Aircraft/.
Put model-set.xml in that subdirectory, plus any other files needed.
It is common practice to make subdirectories for the vehicle geometry files (/model/), instruments (/instruments/), and sounds (/sounds/).
If your platform is Mac:
Open a terminal.
Go to your installed FlightGear directory. Open the data directory, then the Aircraft directory:
$FlightGearBaseDirectory/FlightGear.app/Contents/Resources/data/Aircraft/
Put model-set.xml in that subdirectory, plus any other files needed.
It is common practice to make subdirectories for the vehicle geometry files (/model/), instruments (/instruments/), and sounds (/sounds/).
This example illustrates how to prepare hinge line definitions for animated elements such as vehicle control surfaces and landing gear. To enable animation, each element must be a named entity in a geometry file. The resulting code forms part of the HL20 lifting body model presented in Running the NASA HL-20 Demo with FlightGear.
The standard body coordinates used in FlightGear geometry models form a right-handed system, rotated from the standard body coordinate system in Y by -180 degrees:
X = positive toward the back of the vehicle
Y = positive toward the right of the vehicle
Z = positive is up, e.g., wheels typically have the lowest Z values.
See About Aerospace Coordinate Systems for more details.
Find two points that lie on the desired named-object hinge line in body coordinates and write them down as XYZ triplets or put them into a MATLAB calculation like this:
a = [2.98, 1.89, 0.53]; b = [3.54, 2.75, 1.46];
Calculate the difference between the points:
pdiff = b - a pdiff = 0.5600 0.8600 0.9300
The hinge point is either of the points in step 2 (or the midpoint as shown here):
mid = a + pdiff/2 mid = 3.2600 2.3200 0.9950
Put the hinge point into the animation scope in model-set.xml:
<center> <x-m>3.26</x-m> <y-m>2.32</y-m> <z-m>1.00</z-m> </center>
Use the difference from step 3 to define the relative motion vector in the animation axis:
<axis> <x>0.56</x> <y>0.86</y> <z>0.93</z> </axis>
Put these steps together to obtain the complete hinge line animation used in the HL20 demo model:
<animation> <type>rotate</type> <object-name>RightAileron</object-name> <property>/surface-positions/right-aileron-pos-norm</property> <factor>30</factor> <offset-deg>0</offset-deg> <center> <x-m>3.26</x-m> <y-m>2.32</y-m> <z-m>1.00</z-m> </center> <axis> <x>0.56</x> <y>0.86</y> <z>0.93</z> </axis> </animation>
To run a Simulink model of your aircraft and simultaneously animate it in FlightGear with an aircraft data file model-set.xml, you need to configure the aircraft data file and modify your Simulink model with some new blocks.
These are the main steps to connecting and using FlightGear with the Simulink software:
Setting the Flight Dynamics Model to Network in the Aircraft Data File explains how to create the network connection you need.
Obtaining the Destination IP Address starts by determining the IP address of the computer running FlightGear.
Adding and Connecting Interface Blocks shows how to add and connect interface and pace blocks to your Simulink model.
Creating a FlightGear Run Script shows how to write a FlightGear run script compatible with your Simulink model.
Starting FlightGear guides you through the final steps to making the Simulink software work with FlightGear.
Improving Performance helps you speed your model up.
Running FlightGear and Simulink Software on Different Computers explains how to connect a simulation from the Simulink software running on one computer to FlightGear running on another computer.
Be sure to
Remove any pre-existing flight dynamics model (FDM) data from the aircraft data file.
Indicate in the aircraft data file that its FDM is streaming from the network by adding this line:
<flight-model>network</flight-model>
You need the destination IP address for your Simulink model to stream its flight data to FlightGear.
If you know your computer's name, enter at the MATLAB command line:
java.net.InetAddress.getByName('www.mathworks.com')
If you are running FlightGear and the Simulink software on the same computer, get your computer's name by entering at the MATLAB command line:
java.net.InetAddress.getLocalHost
If you are working in Windows, get your computer's IP address by entering at the DOS prompt:
ipconfig /all
Examine the IP address entry in the resulting output. There is one entry per Ethernet device.
The easiest way to connect your model to FlightGear with the blockset is to use the FlightGear Preconfigured 6DoF Animation block:

The FlightGear Preconfigured 6DoF Animation block is a subsystem containing the Pack net_fdm Packet for FlightGear and Send net_fdm Packet to FlightGear blocks:

These blocks transmit data to a FlightGear session. The blocks are separate for maximum flexibility and compatibility.
The Pack net_fdm Packet for FlightGear block formats a binary structure compatible with FlightGear from model inputs. In the default configuration, the block displays only the 6DoF ports, but you can configure the full FlightGear interface supporting more than 50 distinct signals from the block dialog box:

The Send net_fdm Packet to FlightGear block transmits this packet via UDP to the specified IP address and port where a FlightGear session awaits an incoming datastream. Use the IP address you found in Obtaining the Destination IP Address.
The Simulation Pace block, available in the Animation Support Utilities Sublibrary, slows the simulation so that its aggregate run rate is 1 second of simulation time per second of clock time. You can also use it to specify other ratios of simulation time to clock time.

To start FlightGear with the desired initial conditions (location, date, time, weather, operating modes), it is best to create a run script by Using the Generate Run Script Block or Using the Interface Provided with FlightGear.
If you make separate run scripts for each model you intend to link to FlightGear and place them in separate directories, run the appropriate script from the MATLAB interface just before starting your Simulink model.
Using the Generate Run Script Block. The easiest way to create a run script is by using the Generate Run Script block. Use the following procedure:
Open the Flight Simulator Interfaces Sublibrary.
Double-click the Generate Run Script block. Its dialog opens.

In the Output file name field, type the name of the output file. This name should be the name of the command, with the .bat extension, you want to use to start FlightGear with these initial parameters.
For example, if your filename is runfg.bat, use the runfg command to execute the run script and start FlightGear.
In the FlightGear base directory field, specify the name of your FlightGear installation directory.
In the FlightGear geometry model name field, specify the name of the subdirectory, in the FlightGear/data/Aircraft directory, containing the desired model geometry.
Click the Generate Script button at the top of the Parameters area.
The Aerospace Blockset software generates the run script, and saves it in your MATLAB working directory under the filename that you specified in the Output file name field.
Repeat steps 5 through 9 to generate other run scripts, if needed.
Click OK to close the dialog box. You do not need to save the Generate Run Script block with the Simulink model.
The Generate Run Script block saves the run script as a text file in your working directory. This is an example of the contents of a run script file:
>> cd D:\Applications\FlightGear-1.0 >> SET FG_ROOT=D:\Applications\FlightGear-1.0\data >> cd \bin\Win32\ >> fgfs --aircraft=HL20 --fdm=network,localhost,5501,5502,5503 --fog-fastest --disable-clouds --start-date-lat=2004:06:01:09:00:00 --disable-sound --in-air --enable-freeze --airport-id=KSFO --runway=10L --altitude=7224 --heading=113 --offset-distance=4.72 --offset-azimuth=0
Using the Interface Provided with FlightGear. The FlightGear launcher GUI (part of FlightGear, not the Aerospace Blockset product) lets you build simple and advanced options into a visible FlightGear run command.
If your computer has enough computational power to run both the Simulink software and FlightGear at the same time, a simple way to start FlightGear on a Windows system is to create a MATLAB desktop button containing the following command to execute a run script like the one created above:
system('runfg &')
To create a desktop button:
From the Start button on your MATLAB desktop, click Shortcuts > New Shortcut. The Shortcut Editor dialog opens.
Set the Label, Callback, Category, and Icon fields as shown in the following figure.

The FlightGear toolbar button appears in your MATLAB desktop. If you click it, the runfg.bat file runs in the current directory.

Once you have completed the setup, start FlightGear and run your model:
Make sure your model is in a writable directory. Open the model, and update the diagram. This step ensures that any referenced block code is compiled and that the block diagram is compiled before running. Once you start FlightGear, it uses all available processor power while it is running.
Click the FlightGear button or run the FlightGear run script manually.
When FlightGear starts, it displays the initial view at the initial coordinates specified in the run script. If you are running the Simulink software and FlightGear on different computers, arrange to view the two displays at the same time.
Now begin the simulation and view the animation in FlightGear.
If your Simulink model is complex and cannot run at the aggregate rate needed for the visualization, you might need to
Use the Accelerator mode in Simulink (Accelerating Models in Simulink User's Guide) to speed up your model execution.
Free up processor power by running the Simulink model on one computer and FlightGear on another computer. Use the Destination IP Address parameter of the Send net_fdm Packet to FlightGear block to specify the network address of the computer where FlightGear is running.
Simulate the Simulink model first, then save the resulting translations (x-axis, y-axis, z-axis) and positions (latitude, longitude, altitude), and use the FlightGear Animation object in Aerospace Toolbox to visualize this data.
It is possible to simulate an aerospace system in the Simulink environment on one computer (the source) and use its simulation output to animate FlightGear on another computer (the target). The steps are similar to those already explained, with certain modifications.
Obtain the IP address of the computer running FlightGear. See Obtaining the Destination IP Address preceding.
Enter this target computer's IP address in the Send net_fdm Packet to FlightGear block. See Adding and Connecting Interface Blocks preceding.
Update the Generate Run Script block in your model with the target computer's FlightGear base directory. Regenerate the run script to reflect the target computer's separate identity.
See Creating a FlightGear Run Script preceding.
Copy the generated run script to the target computer. Start FlightGear there. See Starting FlightGear preceding.
Start your Simulink model on the source computer. FlightGear running on the target displays the simulation motion.
The Aerospace Blockset software contains a demo model of the NASA HL-20 lifting body that uses the FlightGear interface.
You need to have FlightGear installed and configured before attempting to simulate this model. See Introducing the Flight Simulator Interface. This section assumes that you have read Installing and Starting FlightGear. Before you start, perform the following, depending on your platform.
Copy the HL20 folder from matlabroot\toolbox\aeroblks\aerodemos\ directory to FlightGear\data\Aircraft\ directory. This folder contains the preconfigured geometries for the HL-20 simulation and HL20-set.xml. The file matlabroot\toolbox\aeroblks\aerodemos\HL20\models\HL20.xml defines the geometry.
For more about this step, see Importing Aircraft Models into FlightGear.
Copy the HL20 directory from matlabroot/toolbox/aeroblks/aerodemos/ directory to $FlightGearBaseDirectory/data/Aircraft/ directory. This directory contains the preconfigured geometries for the HL-20 simulation and HL20-set.xml. The file matlabroot/toolbox/aeroblks/aerodemos/HL20/models/HL20.xml defines the geometry.
For more about this step, see Importing Aircraft Models into FlightGear.
Copy the HL20 directory from matlabroot/toolbox/aeroblks/aerodemos/ directory to $FlightGearBaseDirectory/FlightGear.app/Contents/Resources/data/Aircraft/ directory. This directory contains the preconfigured geometries for the HL-20 simulation and HL20-set.xml. The file matlabroot\toolbox\aeroblks\aerodemos\HL20\models\HL20.xml defines the geometry.
For more about this step, see Importing Aircraft Models into FlightGear.
Start the MATLAB interface. Open the demo either by entering asbhl20 in the MATLAB Command Window or by finding the demo entry (NASA HL-20 with FlightGear Interface) in the Demos browser and clicking Open this model on its demo page. The model opens.

If this is your first time running FlightGear for this model, double-click the Generate Run Script block to create a run script. Make sure to specify your FlightGear installation directory in the FlightGear base directory field. For more information, see Creating a FlightGear Run Script.
Execute the script you just created manually by entering the following at the MATLAB command line:
dos('runfg &')
If you created a FlightGear desktop button, you can click it instead to start the run script and start FlightGear. For more information, see Starting FlightGear.
Now start the simulation and view the animation in FlightGear.
Note With the FlightGear window in focus, press the V key to alternate between the different aircraft views: cockpit view, helicopter view, chase view, and so on. |
![]() | Introducing the Flight Simulator Interface | Case Studies | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |