Import Visual Representations of Robot Models
You can import into a virtual world in金宝app®3D Animation™robot and robot environment 3-D models that are defined using unified robot description format (.urdf
) or simulation description format (.sdf
). The URDF file format is an XML file format that defines various model (typically robot) properties. When you import from a URDF file, only the visual representation of the model is imported. This representation typically refers to model component shape files, defined as STL or DAE files. You can import visual properties of the objects present in the URDF or SDF files into corresponding hierarchical structure ofTransform
nodes containingIndexedFaceSet
objects with textures.
URDF and SDF files use Collada DAE and STL formats to define visual properties of scene objects.
To import visual representation of robots, in the 3D World Editor, selectNodes>Import From. Then selectSTL File,Physical Modeling XML File,URDF File,SDF File, orCOLLADA File. From the MATLAB®command line, you can use the
function to importvrimport
.urdf
,.dae
,.stl
, and.sdf
files into a virtual world.
Import a DAE File
的黑绿豆F and SDF import supports a subset of the Collada DAE 3D file format (objects that are typically present in URDF and SDF files: geometric shape objects with textures).
This example imports a Collada DAE file,fox.dae
, into a scene with predefined grid, gray background, and viewpoint. The fox head is a sphere with 1-m radius, placed at the origin and looking in the direction of VRML +z-axis.
Thefox.dae
is shipped with theSimulink 3D Animationsoftware. The path ismatlabroot/toolbox/sl3d/sl3ddemos/fox.dae
.
From the MATLAB Toolstrip, in theAppstab, in theSimulation Graphics and Reportingsection, click3D World Editor.
In the 3D World Editor, selectFile>New from Template.
In the file dialog box, select the
Grids
folder and then select theXZGrid.wrl
virtual world file.Save the virtual world in the current folder. SelectFile>Save asand name the virtual world file
fox_dae.wrl
.Import the DAE model. SelectNodes>Import From>COLLADA File. Select the
fox.dae
文件。Open the
COLLADA_fox_Transform
node and set thescale
field to 3 for each dimension.
Import a URDF File
In this example, thefox.urdf
file refers tofox.dae
文件。的黑绿豆F file transforms the original DAE model so that the fox is translated to the position [4 1 0] and rotated so that it points to the VRML +x-axis direction.
Thefox.urdf
is shipped with theSimulink 3D Animationsoftware. The path ismatlabroot/toolbox/sl3d/sl3ddemos/fox.urdf
.
From the MATLAB Toolstrip, in theAppstab, in theSimulation Graphics and Reportingsection, click3D World Editor.
In the 3D World Editor, selectFile>New from Template.
In the file dialog box, select the
Grids
folder and then select theXZGrid.wrl
virtual world file.Save the virtual world in the current folder. SelectFile>Save asand name the virtual world file
fox_urdf.wrl
.Import the URDF model. SelectNodes>Import From>URDF File. Select the
fox.urdf
文件。Open the
URDF_visual_Transform
node and set thescale
field to 3 for each dimension.
导入一个自卫队文件
SDF is an XML format that describes objects and environments for robot simulators, visualization, and control, originally developed as part of the Gazebo robot simulator. The folder in which themodel.sdf
file is located defines the SDF model name. This example shows how to import a simple arm link mechanism.
The example assumes that you have
Download the
simple_arm
model folder (including all its contents) from this Gazebo model site:http://models.gazebosim.org/simple_arm/. To download all the folder contents, download and unpack themodel.tar.gz
文件。From the MATLAB Toolstrip, in theAppstab, in theSimulation Graphics and Reportingsection, click3D World Editor.
In the 3D World Editor, selectFile>New from Template.
In the file dialog box, select the
Grids
folder and then select theXZGrid.wrl
virtual world file.Save the virtual world in the current folder. SelectFile>Save asand name the virtual world file
simple_arm.wrl
.Import the SDF model. SelectNodes>Import From>SDF File. In the
simple_arm
folder, select themodel.sdf
文件。Open the
SDF_simple_arm_Transform
node and set thescale
field to 3 for each dimension.The import process creates in the model hierarchy some special
Transform
nodes that make it easier to manipulate models. Each rotational joint in the SDF model is represented with aTransform
node with the name starting withaxis_
. These nodes have rotation axes defined so that the model elements move consistently if you set the rotation angle to a different value.Change the rotation angle of a rotational joint node. For example, expand the
children
node, then thejoint_arm_shoulder_pan_joint
node, then thechildren
, and finally, theaxis_arm_shoulder_pan_joint
. For therotation
field, set the fourth element to 1.Tip
If you associate this virtual world with aVR Sinkblock in a Simulink model, you can use theVR Signal Expanderblock to set only the rotation angle (the fourth element of the rotation vector) of the
axis_xxx
Transform
node rotation. Leave the first three elements of the vector unchanged. This approach preserves robot consistency with the way model authors defined movement of robot parts.
Define Viewpoint to Make Imported Model Visible
When you import a model, often it does not appear in the initial view of the virtual world. If necessary, create a viewpoint to make the imported model visible when the virtual world opens. If the imported model is not visible:
In the 3D World Editor, select the
ROOT
node.SelectNodes>Add>Bindable>Viewpoint.
To observe the imported model, navigate to a suitable location in the scene.
Populate viewpoint properties with current camera settings. In the tree hierarchy pane, right-click the viewpoint and selectCopy values from current camera.
Save the virtual world.
Limitations
URDF import transforms robot hierarchy of links and joints into a VRML or X3D hierarchy of transforms. It imports only visualization properties from each link. Joints are represented by transforms that preserve rotation axes of the original revolute joints and axis alignment of prismatic joints.
SDF import transforms the hierarchy of SDF model objects into VRML or X3D hierarchy of transforms the same way as URDF import. It supports a subset of SDF format objects and is limited to visual objects under theModel
element hierarchy. SupportedGeometry
elements are geometric primitives and meshes.