Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

 

Aerospace Toolbox 2.4

Visualizing Aircraft Takeoff Using Simulink 3D Animation

Aerospace Toolbox provides several options for flight data visualization. One of these options is an interface to Virtual Reality Toolbox. This interface lets you use flight data to control flight vehicle position and attitude in your virtual reality scene. The virtual reality scene can be customized to provide the desired level of detail. For example, you can add other flight vehicles to your virtual reality scene. In this demo we show how you can visualize aircraft takeoff and a chase helicopter with the virtual reality animation object. The demo illustrates how you can use the Aero.VirtualRealityAnimation object to set up a virtual reality animation based on the vrtkoff.wrl file. The scene simulates an aircraft takeoff. The demo adds a chase vehicle to the simulation and a chase viewpoint associated with the new vehicle.

Contents

Motivation

Simulink 3D Animation provides functions for updating the virtual reality scene with MATLAB data. However, to play time history data, such as flight data, through a virtual reality scene using Simulink 3D Animation functions you would have to write a loop in MATLAB. For each iteration of this loop you would update a virtual scene with flight data at a specific time instance. Aerospace Toolbox provides a much more convenient way of playing your flight data through the virtual scene, where instead of writing a loop, you can simply use the h.play() command. This demo shows how to do this.

Create the Animation Object

This code creates an instance of the Aero.VirtualRealityAnimation object. See online documentation for Aerospace Toolbox for more information on Aero.VirtualRealityAnimation object and all the methods for working with this object.

h = Aero.VirtualRealityAnimation;

Set the Animation Object Properties

This code sets the number of frames per second and the seconds of animation data per second time scaling. 'FramesPerSecond' controls the rate at which frames are displayed in the figure window. 'TimeScaling' is the seconds of animation data per second time scaling.

The 'TimeScaling' and 'FramesPerSecond' properties determine the time step of the animation data. The settings in this demo result in a time step of approximately 0.5s. The equation is:

(1/FramesPerSecond)*TimeScaling + extra terms to handle for sub-second precision.

h.FramesPerSecond = 10;
h.TimeScaling = 5;

This code sets the .wrl file to be used in the virtual reality animation.

h.VRWorldFilename = './vrtkoff.wrl';

Initialize the Virtual Reality Animation Object

The initialize method loads the animation world described in the 'VRWorldFilename' field of the animation object. When parsing the world, node objects are created for existing nodes with DEF names. The initialize method also opens the Simulink 3D Animation Viewer.

h.initialize();

Initial Scene

To view the initial scene:

takeVRCapture(h.VRFigure);

Set Additional Node Information

This code sets animation timeseries data. takeoffData.mat contains logged flight data. takeoffData is set up as a 'StructureWithTime', which is one of the default data formats.

load takeoffData
h.Nodes{7}.TimeseriesSource = takeoffData;
h.Nodes{7}.TimeseriesSourceType = 'StructureWithTime';

Set the Coordinate Transform Function

The virtual reality animation object expects positions and rotations in aerospace body coordinates. If the input data is different, you must create a coordinate transformation function in order to correctly line up the position and rotation data with the surrounding objects in the virtual world. This code sets the coordinate transformation function for the virtual reality animation.

In this particular case, if the input translation coordinates are [x1,y1,z1], they must be adjusted as follows: [X,Y,Z] = -[y1,x1,z1]. You use the custom transform function vranimCustomTransform.m to perform this coordinate transformation.

h.Nodes{7}.CoordTransformFcn = @vranimCustomTransform;

Add a Chase Helicopter

This code shows how to add a chase helicopter to the animation object.

You can view all the nodes currently in the virtual reality animation object by using the nodeInfo method. When called with no output argument, this method prints the node information to the command window. With an output argument, the method sets node information to that argument.

h.nodeInfo;
Node Information
1	_v1
2	Lighthouse
3	_v3
4	Terminal
5	Block
6	_V2
7	Plane
8	Camera1

Use the addNode method to add another node to the object. By default, each time you add or remove a node or route, or when you call the save method, Aerospace Toolbox displays a warning about the current .wrl file location. To disable this warning, set the 'ShowSaveWarning' property in the VirtualRealityAnimation object.

h.ShowSaveWarning = false;
h.addNode('Lynx',[matlabroot,'/toolbox/aero/astdemos/chaseHelicopter.wrl']);

This code moves the camera angle of the virtual reality figure to view the aircraft and newly added helicopter. Another call to nodeInfo shows the newly added Node objects.

set(h.VRFigure,'CameraDirection',[0.45 0 -1]);
h.nodeInfo
Node Information
1	Lynx_Inline
2	Lynx
3	_v1
4	Lighthouse
5	_v3
6	Terminal
7	Block
8	_V2
9	Plane
10	Camera1

Scene with Chase Helicopter Added

To view the scene with the chase helicopter:

takeVRCapture(h.VRFigure);

This code sets data properties for the chase helicopter. The 'TimeseriesSourceType' is the default 'Array6DoF', so no additional property changes are needed. The same coordinate transform function (vranimCustomTransform) is used for this node as the preceding node. The previous call to nodeInfo returned the node index (2).

load chaseData
h.Nodes{2}.TimeseriesSource = chaseData;
h.Nodes{2}.CoordTransformFcn = @vranimCustomTransform;

Play Animation

The play method runs the animation for the specified timeseries data.

h.play();

Watch the video with the animation recording. (10 seconds)

Create a New Viewpoint

This code uses the addViewpoint method to create a new viewpoint named 'chaseView'. The new viewpoint will appear in the viewpoint pulldown menu in the virtual reality window as "View From Helicopter". Another call to nodeInfo shows the newly added node objects. The node is created as a child of the chase helicopter.

h.addViewpoint(h.Nodes{2}.VRNode,'children','chaseView','View From Helicopter');

Scene from Helicopter Viewpoint

This code sets the orientation of the viewpoint via the vrnode object associated with the node object for the viewpoint. In this case, it will change the viewpoint to look out the right side of the helicopter at the plane.

setfield(h.Nodes{1}.VRNode,'orientation',[0 1 0 convang(160,'deg','rad')]);
%#ok<SFLD,STFLD> set(h.VRFigure,'Viewpoint','View From Helicopter');

To view the scene from the helicopter viewpoint:

takeVRCapture(h.VRFigure);

Play Animation from Helicopter Viewpoint

This code plays the animation.

h.play();
% This code plays the animation again.
play(h);

Watch the video with the animation recording. (13 seconds)

Add ROUTE

This code calls the addRoute method to add a ROUTE command to connect the plane position to the Camera1 node. This will allow for the "Ride on the Plane" viewpoint to function as intended.

h.addRoute('Plane','translation','Camera1','translation');

Add Another Body

This code adds another helicopter to the scene. It also changes to another viewpoint to view all three bodies in the scene at once.

h.addNode('Lynx1',[matlabroot,'/toolbox/aero/astdemos/chaseHelicopter.wrl']);
set(h.VRFigure,'Viewpoint','See Whole Trajectory');
h.nodeInfo
Node Information
1	Lynx1_Inline
2	Lynx1
3	chaseView
4	Lynx_Inline
5	Lynx
6	_v1
7	Lighthouse
8	_v3
9	Terminal
10	Block
11	_V2
12	Plane
13	Camera1

Scene Viewing Whole Trajectory with All Bodies

To view the whole trajectory with all bodies:

takeVRCapture(h.VRFigure);

Remove Body

This code uses the removeNode method to remove the second helicopter. removeNode takes either the node name or node index (as obtained from nodeInfo). The associated inline node is removed as well.

h.removeNode('Lynx1');
set(h.VRFigure,'Viewpoint','See Whole Trajectory');
h.nodeInfo
Node Information
1	chaseView
2	Lynx_Inline
3	Lynx
4	_v1
5	Lighthouse
6	_v3
7	Terminal
8	Block
9	_V2
10	Plane
11	Camera1

Scene Viewing Whole Trajectory with Third Body Removed

To view the whole trajectory with the third body removed:

takeVRCapture(h.VRFigure);

Revert to Original World

The original filename is stored in the 'VRWorldOldFilename' property of the animation object. To bring up the original world, set 'VRWorldFilename' to the original name and reinitializing it.

h.VRWorldFilename = h.VRWorldOldFilename{1};
h.initialize();

Close and Delete World

To close and delete the world, use the delete method.

h.delete();
Contact sales
Free technical kit
Trial software
E-mail this page

Get Pricing and
Licensing Options