Create a Flight Animation from Trajectory Data

This example shows how to create a flight animation for a trajectory using a FlightGear Animation object.

Note: When running this example within the product, you must customize the example with your FlightGear installation and uncomment the GenerateRunScript, system and play commands. You must also copy the $MATLAB/toolbox/aero/astdemos/HL20 folder into the $FLIGHTGEAR/data/Aircraft/ folder.

Load Recorded Flight Trajectory Data

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

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

Create a Time Series Object from Trajectory Data

Use the MATLAB® timeseries command to create the time series object, ts, from the latitude, longitude, altitude, and Euler angle data along with the time array in tdata. To convert the latitude, longitude, and Euler angles from degrees to radians use the convang function.

Create a Run Script to Launch FlightGear Flight Simulator

To start FlightGear with the desired initial conditions (location, date, time, weather, and operating modes), create a run script with the GenerateRunScript command. By default, GenerateRunScript saves the run script as a text file named 'runfg.bat'.

GenerateRunScript(h)

You do not need to generate this file each time the data is viewed. Generate it only when the desired initial conditions or FlightGear information changes.

Start FlightGear Flight Simulator

To start FlightGear from the MATLAB command prompt, type the system command to execute the run script created by GenerateRunScript.

system('runfg.bat &');

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

Play the Flight Animation of Trajectory Data

Once FlightGear is up and running, the FlightGearAnimation object can start to communicate with FlightGear. To display the flight animation with FlightGear, use the play command.

play(h)

To display a screenshot of the flight animation, use the MATLAB image command.

MATLAB and Simulink are registered trademarks of The MathWorks, Inc. Please see www.mathworks.com/trademarks for a list of other trademarks owned by The MathWorks, Inc. Other product or brand names are trademarks or registered trademarks of their respective owners.