Aero.FlightGearAnimation Objects

The Aerospace Toolbox interface to the FlightGear flight simulator enables you to visualize flight data in a three-dimensional environment. The third-party FlightGear simulator is an open source software package available through a GNU® General Public License (GPL). This section describes how to obtain and install the third-party FlightGear flight simulator. It also describes how to play back 3-D flight data by using a FlightGear example, provided with your Aerospace Toolbox software.

About the FlightGear Interface

The FlightGear flight simulator interface included with the Aerospace Toolbox product is a unidirectional transmission link from the MATLAB® software to FlightGear. It uses FlightGear's published net_fdm binary data exchange protocol. Data is transmitted via UDP network packets to a running instance of FlightGear. The toolbox supports multiple standard binary distributions of FlightGear. For interface details, see Flight Simulator Interface Example following.

FlightGear is a separate software entity that is not created, owned, or maintained by MathWorks.

  • To report bugs in or request enhancements to the Aerospace Toolbox FlightGear interface, contact MathWorks technical support at

  • To report bugs or request enhancements to FlightGear itself, go to and use the contact page.

Supported FlightGear Versions

The Aerospace Toolbox product supports the following FlightGear versions:

  • v2.0

  • v2.4

  • v2.6

  • v2.8

  • v2.10

  • v2.12

  • v3.0

  • v3.2

  • v3.4

Obtaining FlightGear Software

You can obtain FlightGear software from in the download area or by ordering CDs from FlightGear. The download area contains extensive documentation for installation and configuration. Because FlightGear is an open source project, source downloads are also available for customization and porting to custom environments.

Configuring Your Computer for FlightGear

You must have a high-performance graphics card with stable drivers to use FlightGear. For more information, see the FlightGear CD distribution or the hardware requirements and documentation areas of the FlightGear Web site,

MathWorks tests of FlightGear performance and stability indicate sensitivity to computer video cards, driver versions, and driver settings. You must have OpenGL® support with hardware acceleration activated. The OpenGL settings are particularly important. Without proper setup, performance can drop from about a 30 frames-per-second (fps) update rate to less than 1 fps.

Graphics Recommendations for Microsoft Windows

For Windows® users, use the following graphics recommendations:

  • A graphics card with acceptable OpenGL performance (as outlined at the FlightGear Web site,

  • The latest tested and stable driver release for your video card. Test the driver thoroughly on a few computers before deploying to others.

    For Microsoft® Windows XP systems running on x86 (32-bit) or AMD-64/EM64T chip architectures, the graphics card operates in the unprotected kernel space known as Ring Zero. Problems in the driver can cause the Windows operating system to lock or crash. Before buying a large number of computers for 3-D applications, with your vendor, test one or two computers to find a combination of hardware, operating system, drivers, and settings that are stable for your applications.

For more information, see FlightGear Hardware Recommendations.

Setting Up OpenGL Graphics on Windows

For complete information on Silicon Graphics OpenGL settings, refer to the documentation at the OpenGL Web site,

Follow these steps to optimize your video card settings. Your driver's panes might look different.

  1. Ensure that you have activated the OpenGL hardware acceleration on your video card. On Windows, access this configuration through Start > Settings > Control Panel > Display, which opens the following dialog box. Select the Settings tab.

  2. In the lower right of the dialog box, click the Advanced button, which opens the graphics card custom configuration dialog box. Go to the OpenGL tab. For an ATI Mobility Radeon 9000 video card, the OpenGL pane looks like the following graphic.

  3. For best performance, near the top of the dialog box, move the Main Settings slider to the Performance end of the slider.

  4. If stability is a problem, try other screen resolutions, other color depths in the Displays pane, and other OpenGL acceleration modes.

Many cards perform much better at 16 bits-per-pixel color depth (also known as 65536 color mode, 16-bit color). For example, on an ATI Mobility Radeon 9000 running a given model, 30 fps are achieved in 16-bit color mode, while 2 fps are achieved in 32-bit color mode.

Setup on Linux, Mac OS X, and Other Platforms

FlightGear distributions are available for Linux®, Mac OS X, and other UNIX® platforms from the FlightGear Web site, Installation on these platforms, like Windows, requires careful configuration of graphics cards and drivers. Consult the documentation and hardware requirements sections at the FlightGear Web site.

Install and Start FlightGear

The extensive FlightGear documentation guides you through the installation. For complete installation instructions, consult the documentation section of the FlightGear Web site


  • Generous central processor speed, system and video RAM, and virtual memory are essential for good flight simulator performance.

    Have a minimum of 512 megabytes of system RAM and 128 megabytes of video RAM for reasonable performance.

  • Have sufficient disk space for the FlightGear download and installation.

  • Before you install FlightGear, configure your computer graphics card. See the preceding section, Configuring Your Computer for FlightGear.

  • Before installing FlightGear, shut down all running applications (including the MATLAB software).

  • Install FlightGear in a folder path name composed of ASCII characters.

  • The operational stability of FlightGear is especially sensitive during startup. It is best to not move, resize, mouse over, overlap, or cover up the FlightGear window until the initial simulation scene appears after the startup splash screen fades out.

  • The current releases of FlightGear are optimized for flight visualization at altitudes below 100,000 feet. FlightGear does not work well or at all with very high altitude and orbital views.

The Aerospace Toolbox product supports FlightGear on a number of platforms ( The following table lists the properties to be aware of before you start using FlightGear.

FlightGear PropertyFolder DescriptionPlatformsTypical Location


FlightGear installation folder.


C:\Program Files\FlightGear


Directory into which you installed FlightGear


(folder into which you dragged the FlightGear icon)


Model geometry folder


C:\Program Files\FlightGear\data\Aircraft\HL20





Flight Simulator Interface Example

The Aerospace Toolbox product provides an example named Displaying Flight Trajectory Data. This example shows you how you can visualize flight trajectories with FlightGear Animation object. The example is intended to be modified depending on the particulars of your FlightGear installation. Use this example to play back your own 3-D flight data with FlightGear.

Before attempting to simulate this model, you must have FlightGear installed and configured. See About the FlightGear Interface.

To run the example:

  • Import the aircraft geometry into FlightGear.

  • Run the example. The example performs the following steps:

    • Loads recorded trajectory data.

    • Creates a time series object from trajectory data.

    • Creates a FlightGearAnimation object.

  • Modify the animation object properties, if needed.

  • Create a run script for launching the FlightGear flight simulator.

  • Start the FlightGear flight simulator.

  • Play back the flight trajectory.

Import the Aircraft Geometry into FlightGear

Before running the example, copy the aircraft geometry model into FlightGear. From the following procedures, choose the one appropriate for your platform. This section assumes that you have read Install and Start FlightGear.

If your platform is Windows:

  1. Go to your installed FlightGear folder. Open the data folder, and then the Aircraft folder: FlightGear\data\Aircraft\.

  2. If you have previously run the Aerospace Blockset™ NASA HL-20 with FlightGear Interface example, you might already have an HL20 subfolder there.

    Otherwise, copy the HL20 folder from the matlabroot\toolbox\aero\aerodemos\ folder to the FlightGear\data\Aircraft\ folder. This folder contains the preconfigured geometries for the HL-20 simulation and HL20-set.xml. The file matlabroot\toolbox\aero\aerodemos\HL20\models\HL20.xml defines the geometry.

If your platform is Linux:

  1. Go to your installed FlightGear folder. Open the data folder, then the Aircraft folder: $FlightGearBaseDirectory/data/Aircraft/.

  2. If you have previously run the Aerospace Blockset NASA HL-20 with FlightGear Interface example, you might already have an HL20 subfolder there. If that is the case, you do not have to do anything, because you can use the existing geometry model.

    Otherwise, copy the HL20 folder from the matlabroot/toolbox/aero/aerodemos/ folder to the $FlightGearBaseDirectory/data/Aircraft/ folder. This folder contains the preconfigured geometries for the HL-20 simulation and HL20-set.xml. The file matlabroot/toolbox/aero/aerodemos/HL20/models/HL20.xml defines the geometry.

If your platform is Mac:

  1. Open a terminal.

  2. List the contents of the Aircraft folder. For example, type:

    ls $FlightGearBaseDirectory/data/Aircraft/
  3. If you have previously run the Aerospace Blockset NASA HL-20 with FlightGear Interface example, you might already have an HL20 subfolder there. In this case, you do not have to do anything, because you can use the existing geometry model. Continue to Running the Example.

    Otherwise, copy the HL20 folder from the

    folder to the
    folder. This folder contains the preconfigured geometries for the HL-20 simulation and HL20-set.xml. The file matlabroot/toolbox/aero/aerodemos/HL20/models/HL20.xml defines the geometry.

Running the Example

  1. Start the MATLAB software.

  2. Enter astfganim in the MATLAB Command Window.

    While running, the example performs several steps by issuing a series of commands.

Flight Trajectory Data

Loading Recorded Flight Trajectory Data

The flight trajectory data for this example is stored in a comma separated value formatted file. Using dlmread, the data is read from the file starting at row 1 and column 0, which omits the header information.

tdata = dlmread('asthl20log.csv',',',1,0);

Creating a Time Series Object from Trajectory Data

The time series object, ts, is created from the latitude, longitude, altitude, Euler angle data, and the time array in tdata using the MATLAB timeseries command. Latitude, longitude, and Euler angles are also converted from degrees to radians using the convang function.

ts = timeseries([convang(tdata(:,[3 2]),'deg','rad') ...
        tdata(:,4) convang(tdata(:,5:7),'deg','rad')],tdata(:,1));

Creating a FlightGearAnimation Object

This series of commands creates a FlightGearAnimation object:

  1. Open a FlightGearAnimation object.

    h = fganimation;
  2. Set FlightGearAnimation object properties for the time series.

    h.TimeseriesSourceType = 'Timeseries';
    h.TimeseriesSource = ts;
  3. Set FlightGearAnimation object properties relating to FlightGear. These properties include the path to the installation folder, the version number, the aircraft geometry model, and the network information for the FlightGear flight simulator.

    h.FlightGearBaseDirectory = 'C:\Program Files\FlightGear34';
    h.FlightGearVersion = '3.4';
    h.GeometryModelName = 'HL20';
    h.DestinationIpAddress = '';
    h.DestinationPort = '5502';
  4. Set the initial conditions (location and orientation) for the FlightGear flight simulator.

    h.AirportId = 'KSFO';
    h.RunwayId = '10L';
    h.InitialAltitude = 7224;
    h.InitialHeading = 113;
    h.OffsetDistance = 4.72;
    h.OffsetAzimuth = 0;
  5. Set the seconds of animation data per second of wall-clock time.

    h.TimeScaling = 5;
  6. Check the FlightGearAnimation object properties and their values.


The example stops running and returns the FlightGearAnimation object, h:

           TimeseriesSource: [1x1 timeseries]
       TimeseriesSourceType: 'Timeseries'
          TimeseriesReadFcn: @TimeseriesRead
                TimeScaling: 5
            FramesPerSecond: 12
          FlightGearVersion: '3.4'
             OutputFileName: 'runfg.bat'
    FlightGearBaseDirectory: 'C:\Program Files\FlightGear34'
          GeometryModelName: 'HL20'
       DestinationIpAddress: ''
            DestinationPort: '5502'
                  AirportId: 'KSFO'
                   RunwayId: '10L'
            InitialAltitude: 7224
             InitialHeading: 113
             OffsetDistance: 4.7200
              OffsetAzimuth: 0
                     TStart: NaN
                     TFinal: NaN
               Architecture: 'Default'

You can now set the object properties for data playback (see Modifying the FlightGearAnimation Object Properties).

Modifying the FlightGearAnimation Object Properties

Modify the FlightGearAnimation object properties as needed. If your FlightGear installation folder is other than that in the example (for example, FlightGear), modify the FlightGearBaseDirectory property by issuing the following command:

h.FlightGearBaseDirectory = 'C:\Program Files\FlightGear';

Similarly, if you want to use a particular file name for the run script, modify the OutputFileName property.

Verify the FlightGearAnimation object properties:


You can now generate the run script (see Generating the Run Script).

Generating the Run Script

To start FlightGear with the initial conditions (location, date, time, weather, operating modes) that you want, it is best to create a run script by using the GenerateRunScript command:


By default, GenerateRunScript saves the run script as a text file named runfg.bat. You can specify a different name by modifying the OutputFileName property of the FlightGearAnimation object, as described in the previous step.

This file does not need to be generated each time the data is viewed, only when the initial conditions or FlightGear information changes.

You are now ready to start FlightGear (see Starting the FlightGear Flight Simulator).

    Note:   The FlightGearBaseDirectory and OutputFileName properties must be composed of ASCII characters.

Installing Additional FlightGear Scenery

When you install the FlightGear software, the installation provides a basic level of scenery files. The FlightGear documentation guides you through installing scenery as part the general FlightGear installation.

If you need to install more FlightGear scenery files, see the instructions at Those instructions describe how to install the additional scenery in a default location.

If you must install additional scenery in a non-standard location, try setting the FG_SCENERY environment variable in the script output from the GenerateRunScript function. For a description of the FG_SCENERY variable, see the documentation at

    Note:   Each time that you run the GenerateRunScript function, it creates a new script. It overwrites any edits that you have added.

Starting the FlightGear Flight Simulator

To start FlightGear from the MATLAB command prompt, use the system command to execute the run script. Provide the name of the output file created by GenerateRunScript as the argument:

system('runfg.bat &');

FlightGear starts in a separate window.

    Tip   With the FlightGear window in focus, press the V key to alternate between the different aircraft views: cockpit, helicopter, chase, and so on.

You are now ready to play back data (see Playing Back the Flight Trajectory).

    Tip   If FlightGear uses more computer resources than you want, you can change its scheduling priority to a lesser one. For example, see commands like Windows start and Linux nice or their equivalents.

Playing Back the Flight Trajectory

Once FlightGear is running, the FlightGearAnimation object can start to communicate with FlightGear. To animate the flight trajectory data, use the play command:


The following illustration shows a snapshot of flight data playback in tower view without yaw.

Was this topic helpful?