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

 

Newsletters - MATLAB News & Notes

Virtual Reality Toolbox 2 for MATLAB and Simulink

A new level of interaction with simulation models

by Jan Danek and Valerie Lyons

Taking a car out on the highway for a test run is a lot easier than it used to be, at least in a virtual world. This article uses a familiar car on the highway example to show the basic steps of how to incorporate virtual reality into your design process.

The Virtual Reality Toolbox creates a truly bi-directional connection between the virtual scene and its computational environment: users can not only monitor the visualized process, but also control it. The Toolbox is designed for both single-computer and network operation. It is built upon an ISO standard for 3D scene description, VRML97 (the Virtual Reality Modeling Language, version 2). The VRML format is supported by most 3D authoring tools and CAD packages, and there is a wealth of preconstructed objects and scenes available throughout the Internet.

How Does the Virtual Reality Toolbox Work?

The core of the Virtual Reality Toolbox's functionality lies in its Server, which plugs directly into MATLAB. The Server reads a virtual scene from a VRML file and makes it accessible to MATLAB or Simulink and to the clients - the VRML viewers. The virtual scene comes from MATLAB as an object that can be controlled with simple MATLAB commands. In Simulink, the virtual world is accessible via VR Source and VR Sink blocks, which can be inserted into any model and associated with the desired virtual scene.

Virtual Reality Toolbox diagram

Building a Scene

This example shows how 3D visualization can substantially increase understandability of the model.

3D scene of a car on a road
We create a 3D scene
of a car on a road by
choosing a pre-built highway scene (available freely on the Web) and combining it with a model of a Skoda Octavia car.

Scenes in VRML format are plain text files, and thus can be created or modified in any text editor (the process is very similar to handwriting HTML pages). There are also native VRML modeling tools and many 3D tools that can export to VRML format, and the Virtual Reality Toolbox comes packaged with a native VRML Scene editor, V-Realm Builder, which includes a large library of ready-to-use 3D objects.

Complex scenes are often built using numerous tools and 3D models and combining the results. Our scene, as well as most of the demo scenes in the Virtual Reality Toolbox installation, was designed in V-Realm Builder, with minor edits made with a text editor. The final scene, a desert landscape with a highway and the Skoda Octavia model, was composed using the V-Realm Builder.

Adding Virtual Reality Blocks to a Simulink Model

We feed the automobile position signal into the Virtual Reality Sink block (that represents the virtual scene) through some simple transformations to ensure proper scaling and input vector dimensions.

Because we set an object's position, the Sink expects a vector of three coordinates. Only the X coordinate needs to be changed.

A Simulink model with a Virtual Reality Sink Block
A Simulink model with a Virtual Reality Sink block.

Controlling Virtual Reality Objects from Simulink

V-Realm, the virtual scene editor
V-Realm, the virtual scene editor.

Objects in VRML have hierarchical structure. Every complex object is built from basic construction parts (nodes), which are progressively grouped and encapsulated into more and more complex units. The entire automobile model is then represented by a single VRML node that users can manipulate as a whole, even though it actually consists of hundreds of parts.

Every VRML node has specific properties that determine its geometric characteristics. By connecting the position signal from the Simulink model to the translation property of the top-level node of the automobile model (named Octavia), we can control the car position.

The structure of the VRML world can be seen when the VRML file is open in a plain text editor. For example, this fragment of code defines the top-level properties of the Octavia node:

DEF Octavia Transform {
children DEF Octavia_body Transform {
translation 50 -0.5 3.9
rotation 0 1 0 0
scale 0.4 0.4 0.4
center 2.52205 0.893847 -2.90125
children [
Transform {
translation 0.645419 0.277304 -2.40125
scale 5.0979 1.8003 2.2025
center 0.1575 0.3465 -0.5
children Shape {
appearance Appearance {

After the scene file is loaded into the VR Sink block, the same structure appears in its configuration dialog, allowing us to specify which properties of the scene nodes we want to control. The VR Sink block, which initially has no ports, will then "grow" the appropriate number of input ports assigned to the respective properties.

In this example we need only one property: the translation property of the Octavia node. After specifying this in the dialog, the VR Sink block is ready to be connected to the source signal - the vehicle dynamics.

VR block configuration dialog window
VR block configuration dialog window (with a part of the scene structure).

Controlling Virtual Reality Objects from MATLAB

Generally, the same operations that were done from Simulink could be accomplished using pure MATLAB commands.

The following code will load the scene from the blossom_skoda.wrl file and show it in the local viewer:

w = vrworld('blossom_skoda.wrl');
open(w);
view(w);
We can access the Octavia node and look at the current values of its properties:

n = vrnode(w, 'Octavia');
get(n)

Using the MATLAB get-set paradigm, we can change the property values as well:

set(n, 'translation', [3 0 0]);

This will cause the automobile to move by 3 units in the x-direction, which in this case means moving it forward on the highway.

When the world is open in MATLAB, you must use the appropriate commands to close it when the task is finished (Simulink performs opening and closing automatically).

close(w);
delete(w);

Sharing the Scene Between MATLAB and Simulink

It is very simple to share the same scene among multiple Simulink models and MATLAB functions, as every VRML file is loaded into memory only once. When the same VRML file is opened again, the existing scene is accessed. So, if more Simulink models (or MATLAB functions) that access the same VRML file are open, they all share the same scene. Users can interact independently with the same scene through their individual VRML viewers. This enables a true collaborative environment via a unified and consistent view of the world.

VRML model of SKODA Octavia courtesy of Ismar VR and SkodaAuto, Czech Republic. VRML model of 3D highway courtesy of Kostas Terzidis at UCLA - Los Angeles (www.ucla.edu).


Next Article

Contact sales
E-mail this page
Print this page
Subscribe to newsletters