Virtual Reality Toolbox | ![]() ![]() |
Simulink Interface Examples
For all the examples that have a Simulink model, use the following procedure to view a virtual world.
If you close the virtual world window, you can display it again by clicking the View button.
The following table lists the Simulink examples provided with the Virtual Reality Toolbox. Descriptions of the examples follow the table.
Example |
RTW Ready |
VR Source |
VR Sink |
Joystick |
SpaceMouse |
vrbounce |
X |
X |
|||
vrcrane |
X |
X |
|||
vrlights |
X |
||||
vrmaglev |
X |
X |
X |
||
vrmaglev_rtwin |
X |
X |
X |
||
vrmanipul |
X |
X |
|||
vrmemb1 |
X |
||||
vrpend |
X |
X |
X |
||
vrplanets |
X |
X |
|||
vrtkoff |
X |
Bouncing Ball Example (vrbounce)
The vrbounce
example represents a ball bouncing from a floor. The ball deforms as it hits the floor, keeping the volume of the ball constant. The deformation is achieved by modifying the scale field of the ball.
Tower Crane with Weight Example (vrcrane)
The vrcrane
example illustrates how to control a Simulink model from a virtual world. In the associated VRML file, the Joystick PROTO is defined. The VR Source block receives the X output from this PROTO to actuate the motor that drives the crane. The crane dynamics are modeled according to the following equations, using the differential equations editor.
The VR Sink block is used to output the position of the motor and the angle of the rope to the virtual world.
Lighting Example (vrlights)
vrlights
is an example with light sources. In the associated VRML file, several viewpoints are defined that allow you to observe the gradual changes in light from various perspectives.
Magnetic Levitation Model Example (vrmaglev)
vrmaglev
is an example showing the interaction between dynamic models in Simulink and virtual worlds. The Simulink model represents the HUMUSOFT CE 152 Magnetic Levitation educational / presentation scale model. The plant model is controlled by a PID controller with feed-forward to cope with the nonlinearity of the magnetic levitation system.
The position of the ball responds to the changing value of the set point. You can observe this change not only in the Scope window, but also with a VRML viewer displaying the virtual world. To display the virtual world, double-click the VR Sink block, then click the View button in the dialog box. After switching the input from the signal generator to the VR Source block, you can use your mouse to drag the ball to a new position. Note that the position of the ball represents the real dynamics of the system. If you switch the VRML viewer to the Camera 3 viewpoint, you can observe and control the ball more easily.
You achieve the dragging effect by using the VRML PlaneSensor attached to the ball geometry with its output restricted to <0,1> in the vertical coordinate and processed by the VR Source block.
Magnetic Levitation Model for Real-Time Windows Target Example (vrmaglev_rtwin)
In addition to the vrmaglev
example, the vrmaglev_rtwin
example works directly with the actual CE 152 scale model hardware in real time. The MathWorks created this model to work with Real Time Workshop, Real Time Windows Target, and the HUMUSOFT AD 512 data acquisition board. However, you can adapt this model for other targets and acquisition boards. A digital IIR filter, from the Signal Processing Toolbox, filters the physical system output. You can bypass the physical system by using the built-in plant model.
Running this model in real time is an example showing the capabilities of Simulink in control systems design and rapid prototyping. When you change the position of the virtual ball using your mouse, the real ball follows the position you set. When you push the real ball up or down against the coil force, the position of the virtual ball changes in the virtual world. If you remove the ball from the real system, the ball also disappears from the virtual world.
It is important to realize the power of this virtual reality operator control concept. Instead of saying, "I want the ball at the position of 0.4" you can say, "I want the object to be here," and it goes there.
Note that after enabling the remote view in the VR Sink block dialog box, you can control the Simulink model even from a client computer. This can be useful for distributing the computing power between a real-time Simulink model running on one machine and the rendering of a virtual reality world on another machine.
To work with this model, use as powerful a machine as possible or split the computing/rendering over two machines.
Manipulator with SpaceMouse Example (vrmanipul)
This example illustrates the use of the Virtual Reality Toolbox for virtual reality prototyping and testing the viability of designs before the implementation phase. Also, this example illustrates the use of the Magellan SpaceMouse for manipulating objects in a virtual world. Note that you must have the Magellan SpaceMouse in order to run this demo.
The VRML model represents a nuclear hot chamber manipulator. It is manipulated by a simple Simulink model containing the SpaceMouse Input block. This model uses all six degrees of freedom of the SpaceMouse for manipulating the mechanical arm, and this model uses mouse button 1 to close the grip of the manipulator jaws.
Magellan SpaceMouse is an input device with six degrees of freedom. It is useful for navigating and manipulating objects in a virtual world. SpaceMouse is also suitable as a general input device for Simulink models. This professional three-dimensional device greatly facilitates all the previously mentioned tasks. You can use the SpaceMouse for higher performance applications and user comfort. SpaceMouse is supported through the SpaceMouse Input block, which is included in the Virtual Reality Toolbox block library for Simulink.
The SpaceMouse Input block can operate in three modes to cover the most typical use of such a device in a three-dimensional context:
Rotating Membrane Example (vrmemb1)
The vrmemb1
example is similar to the vrmemb
example, but this time the associated virtual world is driven from a Simulink model.
Inverted Pendulum Example (vrpend)
The vrpend
example illustrates the various ways a dynamic model in Simulink can interact with a virtual reality scene. It is the model of a two-dimensional inverted pendulum controlled by a PID controller. What distinguishes this model from "common" inverted pendulum models are the methods for setting the set point. You visualize and interact with a virtual world by using a Trajectory Graph and VR Sink blocks. The Trajectory Graph block allows you to track the history of the pendulum position and change the set point in three ways:
When the pointing device in the VRML viewer moves over an active TouchSensor area, the cursor shape changes. The triggering logic in this model is set to apply the new set point value with a left mouse button click.
Notice the pseudoorthographic view defined in the associated VRML file. This effect is achieved by creating a Viewpoint that is located far from the object of interest with a very narrow view defined by the VRML FieldOfView parameter. An orthographic view is useful for eliminating the panoramic distortion that occurs when you are using a wide-angle lens. The disadvantage of this technique is that locating the viewpoint at a distance makes the standard viewer navigation tricky or difficult in some navigation modes, such as the Examine mode. If you want to navigate around the virtual pendulum bench, you should use some other viewpoint.
Solar System Example (vrplanets)
The vrplanets
example shows the dynamic representation of the first four planets of the Solar system, Moon orbiting around Earth, and Sun itself. The model uses the real properties of the celestial bodies. Only the relative planet sizes and the distance between the Earth and the Moon are adjusted, to provide an interesting view.
There are several viewpoints defined in the virtual scene, both static and attached to an observer on Earth. You can see that the planet bodies are not represented as perfect spheres. Using the VRML Sphere graphic primitive, which is rendered this way, simplified the model. If you want to make the planets more realistic, you could use the more complex IndexedFaceSet node type.
Mutual gravity accelerations of the bodies are computed using Simulink matrix-type data support.
Plane Takeoff Example (vrtkoff)
The vrtkoff
example represents a simplified aircraft taking off from a runway. There are several viewpoints defined in this model, both static and attached to the plane, allowing you to see the takeoff from various perspectives.
The model demonstrates the technique of combining several objects imported or obtained from different sources (CAD packages, general 3-D modelers, and so on) into a virtual reality scene. Usually it is necessary for you to wrap such imported objects with an additional VRML Transform node. This wrapper allows you to set appropriately the scaling, position, and orientation of the objects to fit in the scene. In this example, the aircraft model from the V-Realm Builder Object Library is incorporated into the scene. The file vrtkoff2.wrl
uses the same scene with a different type of aircraft.
![]() | Examples Using the Virtual Reality Toolbox | MATLAB Interface Examples | ![]() |