main content

create a flight animation from trajectory data -凯发k8网页登录

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 hl20 folder into the $flightgear/data/aircraft/ folder. the hl20 folder is located in the working folder of this example, or under the following folder:

fullfile(matlabroot, "toolbox", "aero", "animation")

load recorded flight trajectory data

the flight trajectory data for this example is stored in a comma separated value formatted file. use readmatrix to read the data from the file.

tdata = readmatrix('asthl20log.csv');

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.

ts = timeseries([convang(tdata(:,[3 2]),'deg','rad') ...
                 tdata(:,4) convang(tdata(:,5:7),'deg','rad')],tdata(:,1));

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.

h = aero.flightgearanimation;

set flightgearanimation object properties for timeseries.

h.timeseriessourcetype = 'timeseries';
h.timeseriessource = ts;

set flightgearanimation object properties about flightgear.

these properties include the path to the installation folder, the aircraft geometry model, and the network information for flightgear flight simulator.

h.flightgearbasedirectory = 'c:\program files\flightgear';
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. for windows® systems, you may encounter an error message while launching flightgear with this option enabled. for more information, see installing additional flightgear scenery.

h.installscenery = true;

disable flightgear shaders.

h.disableshaders = true;

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)
             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
               architecture: 'default'
                timescaling: 5
            framespersecond: 12
                     tstart: nan
                     tfinal: nan
           timeseriessource: [1x1 timeseries]
       timeseriessourcetype: 'timeseries'
          timeseriesreadfcn: @timeseriesread

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.

image(imread('astfganim01.png','png'));
axis off;
set(gca,'position',[ 0 0 1 1 ]);
set(gcf,'menubar','none');

figure contains an axes object. the axes object contains an object of type image.

see also

related topics

网站地图