main content

overlaying simulated and actual flight data -凯发k8网页登录

this example shows how to visualize simulated versus actual flight trajectories with the animation object (aero.animation) while showing some of the animation object functionality. in this example, you can use the aero.animation object to create and configure an animation object, then use that object to create, visualize, and manipulate bodies for the flight trajectories.

create the animation object

create an instance of the aero.animation object.

h = aero.animation;

set the animation object properties

set the number of frames per second. this controls the rate at which frames are displayed in the figure window.

h.framespersecond = 10;

set the seconds of animation data per second time scaling. this property and the 'framespersecond' property determine the time step of the simulation. the settings in this example result in a time step of approximately 0.5s. the equation is (1/framespersecond)*timescaling along with some extra terms to handle for subsecond precision.

h.timescaling = 5;

create and load bodies

load the bodies using createbody for the animation object, h. this example uses these bodies to work with and display the simulated and actual flight trajectories. the first body is orange and represents simulated data. the second body is blue and represents the actual flight data.

idx1 = h.createbody('pa24-250_orange.ac','ac3d');
idx2 = h.createbody('pa24-250_blue.ac','ac3d');

load recorded data for flight trajectories

using the bodies from the previous code, this code provides simulated and actual recorded data for flight trajectories in the following files:

  • the simdata file contains logged simulated data. simdata is set up as a 6dof array, which is one of the default data formats.

  • the fltdata file contains actual flight test data. in this example, fltdata is set up in a custom format. the example must create a custom read function and set the 'timeseriessourcetype' parameter to 'custom'.

to load the simdata and fltdata files:

load('simdata.mat','simdata')
load('fltdata.mat','fltdata')

to work with the custom flight test data, this code sets the second body 'timeseriesreadfcn'. the custom read function is located here:

h.bodies{2}.timeseriesreadfcn = @customreadbodytsdata;

set the bodies' timeseries data.

h.bodies{1}.timeseriessource = simdata;
h.bodies{2}.timeseriessource = fltdata;
h.bodies{2}.timeseriessourcetype = 'custom';

camera manipulation

this code illustrates how you can manipulate the camera for the two bodies.

the 'positionfcn' property of a camera object controls the camera position relative to the bodies in the animation. the default camera 'positionfcn' follows the path of a first order chase vehicle. therefore, it takes a few steps for the camera to position itself correctly in the chase plane position. the default 'positionfcn' is located here:

set 'positionfcn'.

h.camera.positionfcn = @dofirstorderchasecameradynamics;

display body geometries in figure

use the show method to create the figure graphics object for the animation object.

h.show();

use the animation object to play back flight trajectories

use the play method to animate bodies for the duration of the timeseries data. using this method illustrates the slight differences between the simulated and flight data.

h.play();
h.updatecamera(5);

wait

wait for the animation to finish before editing the object properties.

h.wait();

the code can also use a custom, simplified 'positionfcn' that is a static position based on the position of the bodies (i.e., no dynamics). the simplified 'positionfcn' is located here:

set the new 'positionfcn'.

h.camera.positionfcn = @staticcameraposition;

run the animation with new 'positionfcn'.

h.play();

wait

wait for the animation to finish before editing the object properties.

h.wait();

move bodies

move the bodies to the starting position (based on timeseries data) and update the camera position according to the new 'positionfcn'. this code uses updatebodies and updatecamera.

t = 0;
h.updatebodies(t);
h.updatecamera(t);

reposition bodies

reposition the bodies by first getting the current body position and then separating the bodies.

get current body positions and rotations from the body objects.

pos1 = h.bodies{1}.position;
rot1 = h.bodies{1}.rotation;
pos2 = h.bodies{2}.position;
rot2 = h.bodies{2}.rotation;

separate bodies using movebody. this code separates and repositions the two bodies.

h.movebody(1,pos1   [0 0 -3],rot1);
h.movebody(2,pos1   [0 0  0],rot2);

create transparency in the first body

create transparency in the first body. the code does this by changing the body patch properties via 'patchhandles'. (for more information on patches in matlab®, see the section in the matlab documentation.)

note: on some platforms utilizing software opengl® rendering, the transparency may cause a decrease in animation speed.

see the opengl documentation for more information on opengl in matlab.

to create a transparency, the code gets the patch handles for the first body.

patchhandles2 = h.bodies{1}.patchhandles;

set desired face and edge alpha values.

desiredfacetransparency = .3;
desirededgetransparency = 1;

get the current face and edge alpha data and changes all values to desired alpha values. in the figure, notice the first body now has a transparency.

for k = 1:size(patchhandles2,1)
    tempfacealpha = get(patchhandles2(k),'facevertexalphadata');
    tempedgealpha = get(patchhandles2(k),'edgealpha');
	set(patchhandles2(k),...
        'facevertexalphadata',repmat(desiredfacetransparency,size(tempfacealpha)));
    set(patchhandles2(k),...
        'edgealpha',repmat(desirededgetransparency,size(tempedgealpha)));  
end

change color of the second body

change the body color of the second body. the code does this by changing the body patch properties via 'patchhandles'.

patchhandles3 = h.bodies{2}.patchhandles;

set the desired patch color (red).

desiredcolor = [1 0 0];

the code can now get the current face color data and change all values to desired color values. note the following points on the code:

  • the if condition keeps the windows from being colored.

  • the name property is stored in the geometry data of the body (h.bodies{2}.geometry.facevertexcolordata(k).name).

  • the code only changes the indices in patchhandles3 with non-window counterparts in the body geometry data.

the name property might not always be available to determine various parts of the vehicle. in these cases, use an alternative approach to selective coloring.

for k = 1:size(patchhandles3,1)
    tempfacecolor = get(patchhandles3(k),'facevertexcdata');
    tempname = h.bodies{2}.geometry.facevertexcolordata(k).name;
    if ~contains(tempname,'windshield') &&...
       ~contains(tempname,'front-windows') &&...
       ~contains(tempname,'rear-windows')
    set(patchhandles3(k),...
        'facevertexcdata',repmat(desiredcolor,[size(tempfacecolor,1),1]));
    end
end

turn off landing gear on second body

turn off the landing gear for the second body. to do this, the code turns off the visibility of all vehicle parts associated with the landing gear. note the indices into the patchhandles3 vector were determined from the name property in the geometry data. other data sources might not have this information available. in these cases, you will need to know which indices correspond to particular parts of the geometry.

for k = [1:8,11:14,52:57]
    set(patchhandles3(k),'visible','off')
end

close and delete animation object

close and delete.

h.delete();
%#ok<*repmat>

see also

| |

related topics

    网站地图