Main Content

Link to万博1manbetxandSimscapeMultibodyModels

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.

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

Link the Virtual World to a万博1manbetxModel

You associate Simulink model signals to virtual world object properties through theVR Sinkblock from theSimulink 3D Animationblock library,vrlib.

To associate a Simulink signal to a virtual object property:

  1. From thevrliblibrary, insert aVR Sinkblock into your Simulink model.

  2. To define the virtual world, use theVR Sink块参数对话框。输入的名称virtual world 3D file in源文件, or clickBrowseto select the file interactively. To load the selected virtual reality scene, clickApply.

  3. For smooth visualization of the movement, you can change the blockSample time. For example, to update the virtual world 25 times per simulation second, set theSample timeto0.04. Be careful when using the inherited sample time for theVR Sinkblock. 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. InVirtual World Tree, expand the main objectTransformbranch. In the scene object hierarchy, locate all parts you want to control from Simulink according to their names as given inAdd DEF Names. NamedTransformnodes represent each part. Select the check box next to the rotation and position fields of theTransformnode. You can select other properties of virtual world objects, such as color, but rotations and positions are the ones most frequently controlled.

  5. ClickOK. For each selected field, theVR Sinkblock creates an input port. Increase theVR Sinkblock size as appropriate to accommodate the number of input ports.

After you associate theVR Sinkblock with a virtual world, you can double-click it to open theSimulink 3D Animationviewer. To access the block parameters, in the viewer, selectSimulation>Block Properties.

VR Sinkinputs take signals of the type corresponding to their virtual world representation. Position inputs are of typeSFVec3f, which is the position represented in[x y z]coordinates. Rotation inputs are of typeSFRotation, the four-element vector defining rotation as[axis angle], using the coordinate system described inCoordinate 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.

通常,对象位置都是可用的m 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 theRotation Matrix to VRML Rotationblock.

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 positions Send toVR Sinkall positions in global coordinates.
    对象rotations Send toVR Sinkall rotations in global coordinates, with the center of rotation defined as the coordinate system origin. If the default center of rotation ofTransformobjects 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 positions Send toVR Sinkall 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.
    对象rotations

    Send toVR Sinkall 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 thecenterfield of the childTransformnode 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 nestedTransform在控制对象。

  • In the Simulink mode, add the object initial position to the model calculations before sending to theVR Sinkblock.

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

TheVR Sinkblock 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 theVR PlaceholderandVR Expanderblocks of theSimulink 3D Animationlibrary.

TheVR Placeholderblock sends out a special value that is interpreted as unspecified by theVR Sinkblock. When this placeholder value appears on aVR Sinkinput, as a single value or as vector element, the appropriate value in the virtual world remains unchanged.

TheVR Signal Expanderblock 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 theVR Signal Expanderblock with the controlled dimension as its input. For its output, use a three-component vector in theVR Sinkblock. The remaining vector elements are filled with placeholder signals.

Use of theVR Signal Expanderblock is also a possibility when defining rotations. When the axis of rotation is defined in the virtual world 3D file, you can send to theVR Sinkblock 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 toSimscapeMultibodyModels

You can use theSimulink 3D Animationproduct to view the behavior of a model created with theSimscape Multibodysoftware.

  1. Build a model of a machine in the Simulink interface usingSimscape Multibodyblocks.

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

  3. Connect the virtual world to theSimscape Multibodybody sensor outputs.

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

You can use theSimscape Multibodysoftware for 3D visualizations using theSimulink 3D Animationproduct. In addition to the features thatSimscape Multibodyproduct offers for modeling mechanical assemblies, the following features simplify the visualization ofSimscape Multibodymodels in virtual reality:

  • Simscape Multibodyand virtual world coordinate systems are identical.

  • In theSimscape Multibodysoftware, 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.

TheSimscape Multibodyproduct also offers a convenient way of importing CAD assembly designs intoSimscape Multibodymachines through theSimscape Multibody Linkinterface. Alternatively, when you export a CAD assembly to the virtual world format, you can add virtual reality visualization to such assemblies.

TheSimulink 3D Animationsoftware includes the following functions for working withSimscape Multibodyfiles:vrcadcleanup, andvrphysmod.

Depending on the virtual world hierarchy, you can use one of two approaches to help visualizeSimscape Multibodymachines:

  • When the virtual world has a flat structure of independent objects, you can obtain the positions and rotations of machine parts usingBody Sensorblocks. Connect theBody Sensorblock 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 aBody Sensorblock 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 aJoint Sensorblock.

Link to aMATLABModel

To help you to interact with virtual worlds, theSimulink 3D Animationproduct 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, seeInteract with Virtual Reality Worlds.

Related Topics