|On this page…|
To visualize a dynamic system simulation, connect a Simulink® block diagram to a virtual world. The example in this section explains how to display a simulated virtual world on a host computer. This is the recommended way to view associated virtual worlds on the host computer.
Simulating a Simulink model generates signal data for a dynamic system. By connecting the Simulink model to a virtual world, you can use this data to control and animate the virtual world.
After you create a virtual world and a Simulink model, you can connect the two with Simulink 3D Animation™ blocks. The example in this procedure simulates a plane taking off and lets you view it in a virtual world.
A Simulink model opens without a Simulink 3D Animation block that connects the model to a virtual world.
Observe the results of the simulation in the scope windows.
The Simulink 3D Animation library opens.
From the Library window, drag and drop the VR Sink block to the Simulink diagram. The VR Sink block writes data from the Simulink model to the virtual world. You can then close the Library: vrlib window.
Now you are ready to select a virtual world for the visualization of your simulation. A simple virtual world with a runway and a plane is in the VRML file vrtkoff.wrl, located in the vrdemos folder.
The Parameters: VR Sink dialog box opens.
VR Plane taking off
Select the Open VRML Viewer automatically parameter.
A VRML tree appears on the right side, showing the structure of the associated virtual reality scene.
The Plane Transform tree expands. Now you can see what characteristics of the plane can be driven from the Simulink interface. This model computes the position and the pitch of the plane.
The selected fields are marked with checks. These fields represent the position (translation) and the pitch (rotation) of the plane.
In the Simulink diagram, the VR Sink block is updated with two inputs.
The first input is Plane rotation. The rotation is defined by a four-element vector. The first three numbers define the axis of rotation. In this example, it should be [1 0 0] for the x-axis (see the Pitch Axis of Rotation block in the model). The pitch of the plane is expressed by the rotation about the x-axis. The last number is the rotation angle around the x-axis, in radians.
The second input is Plane translation. This input describes the plane's position in the virtual world. This position consists of three coordinates, x, y, z. The connected vector must have three values. In this example, the runway is in the x-z plane (see the VR Signal Expander block). The y-axis defines the altitude of the plane.
After you connect the signals and remove the Scope blocks, your model should look similar to the figure shown.
A plane, moving right to left, starts down the runway and takes off into the air.
On occasion, you might want to associate a different virtual world with a Simulink model or connect different signals.
After you associate a virtual world with a Simulink model, you can select another virtual world or change signals connected to the virtual world. This procedure assumes that you have connected the vrtut2 Simulink model with a virtual world. See Add a Simulink 3D Animation Block.
A VRML tree appears on the right side. The Simulink software associates a new virtual world with the model.
The Plane Transform tree expands. Now you can see what characteristics of the plane you can drive from the Simulink interface. This model computes the position.
The VR Sink block is updated and changes to just one input, the Plane translation. The Virtual Reality block is ready to use with the new parameters defined.