Main Content

Flight Trajectory Data

Loading Recorded Flight Trajectory Data

The flight trajectory data for this example is stored in a comma separated value formatted file. To read this data, use readmatrix.

tdata = readmatrix('asthl20log.csv');

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\FlightGear<your_FlightGear_version>';
    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: '2018.1'
             OutputFileName: 'runfg.bat'
    FlightGearBaseDirectory: 'C:\Program Files\FlightGear<your_FlightGear_version>'
          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 the one 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, 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.

You do not need to generate the file 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).


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

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.


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). If you cannot view scenes, see Installing Additional FlightGear Scenery.


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.

See Also

Related Topics