
Create a Flight Animation from Trajectory Data
by admin in Aerospace , Control Systems & Aerospace , MATLAB Family on April 3, 2019This code 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. All the down described equations and steps are exists in the Matlab files, that you will download after the checkout.
Contents
- Load Recorded Flight Trajectory Data
- Create a Time Series Object from Trajectory Data
- Use FlightGearAnimation Object to Initialize Flight Animation
- Create a Run Script to Launch FlightGear Flight Simulator
- Start FlightGear Flight Simulator
- Play the Flight Animation of Trajectory Data
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.
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.
You can create imported data from this data using other valid formats, such as ‘Array6DoF’, For example:
ts = [tdata(:,1) convang(tdata(:,[3 2]),’deg’,’rad’) tdata(:,4) … convang(tdata(:,5:7),’deg’,’rad’)];
and ‘Array3DoF’.
ts = [tdata(:,1) convang(tdata(:,3),’deg’,’rad’) tdata(:,4) … convang(tdata(:,6),’deg’,’rad’)];
Use FlightGearAnimation Object to Initialize Flight Animation
Open a FlightGearAnimation object.Then set FlightGearAnimation object properties for timeseries. Set FlightGearAnimation object properties about FlightGear
These properties include the path to the installation folder, the version number, the aircraft geometry model, and the network information for FlightGear flight simulator.
h.FlightGearBaseDirectory = 'C:\Program Files\FlightGear'; h.FlightGearVersion = '2018.1'; h.GeometryModelName = 'HL20'; h.DestinationIpAddress = '127.0.0.1'; h.DestinationPort = '5502';
Set the desired initial conditions (location and orientation) for FlightGear flight simulator.
h.AirportId = 'KSFO'; h.RunwayId = '10L'; h.InitialAltitude = 7224; h.InitialHeading = 113; h.OffsetDistance = 4.72; h.OffsetAzimuth = 0;
Enable ‘just in time’ scenery installation for FlightGear flight simulator. Required scenery will be downloaded while the simulator is running. Disable FlightGear Shaders. Set the seconds of animation data per second of wall-clock time.
h.TimeScaling = 5;
Use get(h) to check the FlightGearAnimation object properties and their values.
get(h)
TimeseriesSource: [1x1 timeseries] TimeseriesSourceType: 'Timeseries' TimeseriesReadFcn: @TimeseriesRead TimeScaling: 5 FramesPerSecond: 12 FlightGearVersion: '2018.1' OutputFileName: 'runfg.bat' FlightGearBaseDirectory: 'C:\Program Files\FlightGear' GeometryModelName: 'HL20' DestinationIpAddress: '127.0.0.1' DestinationPort: '5502' AirportId: 'KSFO' RunwayId: '10L' InitialAltitude: 7224 InitialHeading: 113 OffsetDistance: 4.7200 OffsetAzimuth: 0 InstallScenery: 1 DisableShaders: 1 TStart: NaN TFinal: NaN Architecture: 'Default'
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.
Share Now!