The flight trajectory data for this example is stored in a comma separated value formatted
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);
The time series object,
ts, is created from
the latitude, longitude, altitude, Euler angle data, and the time
tdata using the MATLAB®
Latitude, longitude, and Euler angles are also converted from degrees
to radians using the
ts = timeseries([convang(tdata(:,[3 2]),'deg','rad') ... tdata(:,4) convang(tdata(:,5:7),'deg','rad')],tdata(:,1));
This series of commands creates a FlightGearAnimation object:
Open a FlightGearAnimation object.
h = fganimation;
Set FlightGearAnimation object properties for the time series.
h.TimeseriesSourceType = 'Timeseries'; h.TimeseriesSource = ts;
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 = '127.0.0.1'; h.DestinationPort = '5502';
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;
Set the seconds of animation data per second of wall-clock time.
h.TimeScaling = 5;
Check the FlightGearAnimation object properties and their values.
The example stops running and returns the FlightGearAnimation
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: '127.0.0.1' 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).
Modify the FlightGearAnimation object properties as needed. If your FlightGear installation
folder is other than the one in the example (for example,
FlightGearBaseDirectory property by issuing the following
h.FlightGearBaseDirectory = 'C:\Program Files\FlightGear';
Similarly, if you want to use a particular file name for the
run script, modify the
Verify the FlightGearAnimation object properties:
You can now generate the run script (see 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 saves the
run script as a text file named
can specify a different name by modifying the
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).
must be composed of ASCII characters.
To start FlightGear from the MATLAB command prompt, use
system command to execute the run script.
Provide the name of the output file created by GenerateRunScript as
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.
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®
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.