Link to Simulink and Simscape Multibody Models

To establish a live data connection between the model and the virtual world, create associations between dynamic model object quantities and corresponding virtual world object properties. For example, create associations with virtual world object properties such as position and rotations.

Although Simscape™ Multibody™ and Simulink® are common platform for modeling mechanical systems, also you can use the Simulink 3D Animation™ product for the visualization of models implemented in MATLAB®.

Link the Virtual World to a Simulink Model

You associate Simulink model signals to virtual world object properties through the VR Sink block from the Simulink 3D Animation block library, vrlib.

To associate a Simulink signal to a virtual object property:

  1. From the vrlib library, insert a VR Sink block into your Simulink model.

  2. To define the virtual world, use the VR Sink block parameters dialog box. Enter the name of the virtual world 3D file in Source file, or click Browse to select the file interactively. To load the selected virtual reality scene, click Apply.

  3. For smooth visualization of the movement, you can change the block Sample time. For example, to update the virtual world 25 times per simulation second, set the Sample time to 0.04. Be careful when using the inherited sample time for the VR Sink block. Depending on the solver used, using inherited sample time can result in nonequidistant (in simulation time) updating of the virtual world. Nonequidistant updating gives a false impression of system dynamics to the person viewing the virtual world.

  4. In Virtual World Tree, expand the main object Transform branch. In the scene object hierarchy, locate all parts you want to control from Simulink according to their names as given in Add DEF Names. Named Transform nodes represent each part. Select the check box next to the rotation and position fields of the Transform node. You can select other properties of virtual world objects, such as color, but rotations and positions are the ones most frequently controlled.

  5. Click OK. For each selected field, the VR Sink block creates an input port. Increase the VR Sink block size as appropriate to accommodate the number of input ports.

After you associate the VR Sink block with a virtual world, you can double-click it to open the Simulink 3D Animation viewer. Block parameters are available through the menu Simulation > Block Properties in the viewer.

VR Sink inputs take signals of the type corresponding to their virtual world representation. Position inputs are of type SFVec3f, which is the position represented in [x y z] coordinates. Rotation inputs are of type SFRotation, the four-element vector defining rotation as [axis angle], using the coordinate system described in Coordinate System Used, where the angle value is in radians.

Match the coordinate system used by the Simulink model to that of the virtual world. If the two coordinate systems are not identical, transform an axis.

Usually, object positions are available in the form required by virtual world (Cartesian coordinates). Often, object rotations are defined using the rotation matrix representation. To convert such rotations into the VRML format, use the Rotation Matrix to VRML Rotation block.

Object positions and rotations are treated differently depending on the virtual world hierarchy:

  • To define all parts in a Simulink model in global coordinates, when the virtual world has a flat structure of independent objects, use these positions and rotations.

    Object positionsSend to VR Sink all positions in global coordinates.
    Object rotationsSend to VR Sink all rotations in global coordinates, with the center of rotation defined as the coordinate system origin. If the default center of rotation of Transform objects is [0 0 0], you do not need to define the center for each part in the virtual world 3D file.
  • When all parts in Simulink model follow hierarchical relations, and the virtual world has a nested structure, use these positions and rotations.

    Object positionsSend to VR Sink all positions in local coordinates relative to their parents or predecessors in the object hierarchy. For example, send the robot tool position relative to the robot hand.
    Object rotations

    Send to VR Sink all rotations in local coordinates relative to their parents or predecessors in the object hierarchy. For example, send the robot tool rotation relative to the robot hand.

    Match the positions of joints between objects visually by coinciding the centers of rotation in the virtual world and in the Simulink model. Coincide the center of rotation because when joints between parts are not positioned in the origin ([0 0 0]) of the coordinate system of the parent.

    To define a center of rotation different from the default value, [0 0 0], define the center field of the child Transform node in the virtual world 3D file. For example, define the robot tool center of rotation to coincide with the joint connecting the hand and the tool in the hand local coordinates.

In a hierarchical scene structure, when the parts are connected by revolving joints, it is easy to define the relative rotations between parts. The joint axis directly defines the virtual world rotation axis, so you can construct the [axis angle] four-element rotation vector.

Initial Conditions

A Simulink model initial conditions must correspond to the initial object positions and rotations defined in the virtual world. Otherwise, the object controlled from Simulink jumps from the position defined in the VRML file to the position dictated by Simulink for the simulation. To compensate for this offset, use one of these approaches:

  • In the virtual world 3D file, define another level of nested Transform around the controlled object.

  • In the Simulink mode, add the object initial position to the model calculations before sending to the VR Sink block.

Align the Simulink model initial conditions with the virtual world object positions, Maintain the correct position of the object relative to the surrounding scene. You can adjust the position of the surroundings of the object. For example, move the road position so that the car at position [0 0 0] stays on the road, without the wheels sinking or floating above the road.

VR Placeholder and VR Signal Expander Blocks

The VR Sink block accepts only inputs that define fully qualified field values. Dynamic models that describe the system behavior in only one dimension still require full 3D positions for all controlled objects for their virtual reality visualization.

To simplify the modeling in such cases, you can use the VR Placeholder and VR Expander blocks of the Simulink 3D Animation library.

The VR Placeholder block sends out a special value that is interpreted as unspecified by the VR Sink block. When this placeholder value appears on a VR Sink input, as a single value or as vector element, the appropriate value in the virtual world remains unchanged.

The VR Signal Expander block creates a vector of predefined length, using some values from the input ports and filling the rest with placeholder signal values.

To control the position of a virtual object in a one-dimensional dynamic model, use the VR Signal Expander block with the controlled dimension as its input. For its output, use a three-component vector in the VR Sink block. The remaining vector elements are filled with placeholder signals.

Use of the VR Signal Expander block is also a possibility when defining rotations. When the axis of rotation is defined in the virtual world 3D file, you can send to the VR Sink block a virtual world rotation value. Use a value consisting of three placeholder signals and the computed angle. This rotation value forms a valid four-element [axis angle] vector.

Link to Simscape Multibody Models

You can use the Simulink 3D Animation product to view the behavior of a model created with the Simscape Multibody software.

  1. Build a model of a machine in the Simulink interface using Simscape Multibody blocks.

  2. Create a detailed visual representation of your machine in a virtual world.

  3. Connect the virtual world to the Simscape Multibody body sensor outputs.

  4. View the behavior of the bodies in a virtual world viewer.

You can use the Simscape Multibody software for 3D visualizations using the Simulink 3D Animation product. In addition to the features that Simscape Multibody product offers for modeling mechanical assemblies, the following features simplify the visualization of Simscape Multibody models in virtual reality:

  • Simscape Multibody and virtual world coordinate systems are identical.

  • In the Simscape Multibody software, you can work with both global and local object coordinates. This flexibility makes it easy to adapt the model to the structure of the virtual world exported from the CAD tool.

The Simscape Multibody product also offers a convenient way of importing CAD assembly designs into Simscape Multibody machines through the Simscape Multibody Link interface. Alternatively, when you export a CAD assembly to the virtual world format, you can add virtual reality visualization to such assemblies.

The Simulink 3D Animation software includes the following functions for working with Simscape Multibody files: vrcadcleanup, vrphysmod, and stl2vrml.

Depending on the virtual world hierarchy, you can use one of two approaches to help visualize Simscape Multibody machines:

  • When the virtual world has a flat structure of independent objects, you can obtain the positions and rotations of machine parts using Body Sensor blocks. Connect the Body Sensor block to appropriate coordinate systems attached to the bodies. Define positions and rotations using global coordinates. Usually, you can connect the sensor to a body coordinate system with origin at [0 0 0] and with an initial rotation matrix defined as the identity matrix, [1 0 0; 0 1 0, 0 0 1], in the global coordinates.

  • When the virtual world has a hierarchical structure of nested objects, you can obtain the body positions and rotations. Use a Body Sensor block with its output set to use local body coordinates. In special cases, such as when two bodies are connected through a revolving joint, you can get the angle between the objects using a Joint Sensor block.

Link to a MATLAB Model

To help you to interact with virtual worlds, the Simulink 3D Animation product offers a set of MATLAB functions and constructs referred to collectively as its “MATLAB interface.” Circumstances when this MATLAB functionality is appropriate for use with CAD-based designs include:

  • Using customized GUIs to visualize static objects and their relations in a virtual environment, such as in interactive machine assembly instructions.

  • Visualizing 3D information based on an independent quantity (not necessarily time).

  • Using MATLAB interface functions in Simulink model callbacks.

  • Visualizing systems whose dynamic models are available as MATLAB code.

  • Visualizing systems where massive object changes, such as deformations, take place. In this case, send dynamically sized matrix-type data from the dynamic models to virtual worlds, which is not possible using just Simulink signals.

For information on setting object properties using the MATLAB interface, see Interact with Virtual Reality Worlds.

Related Topics

Was this topic helpful?