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:
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.
get(h)
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: '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).
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:
get(h)
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:
GenerateRunScript(h)
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).
Note
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.
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). If you cannot view scenes, see Installing Additional FlightGear Scenery.
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:
play(h)
The following illustration shows a snapshot of flight data playback in tower view without yaw.