Main Content

urdfExporter

Create URDF exporter object from rigid body tree robot model

Since R2023b

Description

Use urdfExporter object to generate a unified robot description format (URDF) file from the rigidBodyTree object. You can modify the details in the generated URDF file with supported functionalities.

Creation

Description

example

exporter = urdfExporter(robot) creates a urdfExporter object for the rigidBodyTree robot model robot.

Properties

expand all

Name of the generated URDF file, specified as a string scalar or character vector. You can specify this property as a filename or a pathname.

Data Types: char | string

Robot name attribute corresponding to the robot name tag in the generated URDF file, specified as a string scalar or character vector. It returns as a valid robot model name such as "abbIrb120", "abbIrb120T", "abbIrb1600".

Data Types: char | string

Visual mesh files location corresponding to the filename attribute under the mesh tag of the visual tag in the generated URDF file, specified as a string scalar or character vector.

The default location corresponds to the path you specify in the rigidBodyTree object. You can also modify the visual mesh path from generated URDF file to a location of your preference.

Example: "C:/URDF/abb_irb120_support/meshes/"

Data Types: char | string

Collision mesh files location corresponding to the filename attribute under the mesh tag of the collision tag in the generated URDF file, specified as a string scalar or character vector.

The default location corresponds to the path you specify in the rigidBodyTree object. You can also modify the collision mesh path from generated URDF file to a location of your preference.

Example: "C:/URDF/abb_irb120_support/meshes/"

Data Types: char | string

Option to enable mesh file export, specified as a numeric or logical value of 0 (false) or 1 (true). The generated ZIP package contains the output URDF files and mesh files.

Data Types: logical | numeric

Maximum permissible difference in the values under tags in exported URDF, specified as a positive scalar. The default value is sqrt(eps), where eps returns the distance from 1.0 to the next largest double-precision number, which is equal to 2-52. For more information, see eps.

Data Types: single | double

Object Functions

writefileGenerate URDF file for rigid body tree robot model
writenodeGenerate XML DOM node for rigid body tree robot model

Examples

collapse all

This example shows how to load a robot as a rigidBodyTree model and export the robot details as a URDF file.

Load a rigidBodyTree robot model. The rigidBodyTree object contains kinematic and dynamic constraints and visual meshes for the specified robot geometry.

robotRBT = loadrobot("abbIrb120");

Create a rigidBody object with a unique name.

body1 = rigidBody("link1");

By default, the rigidBody object comes with a fixed joint. Replace the joint by assigning a new rigidBodyJoint object to the body1.Joint property.

body1.Joint = rigidBodyJoint(jnt1="revolute");

Add the rigidBody object to the rigidBodyTree robot model. Specify the body name to which you are attaching the rigid body. Use the base name of the tree for the first body.

basename = robotRBT.BaseName;
addBody(robotRBT,body1,basename);

Confirm that the rigid body and joint are correct by using showdetails.

showdetails(robotRBT)
--------------------
Robot: (9 bodies)

 Idx     Body Name            Joint Name            Joint Type     Parent Name(Idx)   Children Name(s)
 ---     ---------            ----------            ----------     ----------------   ----------------
   1          base        base_link-base                 fixed         base_link(0)   
   2        link_1               joint_1              revolute         base_link(0)   link_2(3)  
   3        link_2               joint_2              revolute            link_1(2)   link_3(4)  
   4        link_3               joint_3              revolute            link_2(3)   link_4(5)  
   5        link_4               joint_4              revolute            link_3(4)   link_5(6)  
   6        link_5               joint_5              revolute            link_4(5)   link_6(7)  
   7        link_6               joint_6              revolute            link_5(6)   tool0(8)  
   8         tool0          joint6-tool0                 fixed            link_6(7)   
   9         link1                  jnt1              revolute         base_link(0)   
--------------------

Visualize the robot model.

show(robotRBT)

ans = 
  Axes (Primary) with properties:

             XLim: [-1 1]
             YLim: [-1 1]
           XScale: 'linear'
           YScale: 'linear'
    GridLineStyle: '-'
         Position: [0.1300 0.1100 0.7750 0.8150]
            Units: 'normalized'

  Show all properties

Add visuals to the robot model.

body9 = robotRBT.Bodies{9};
addVisual(body9,box=[0.1 0.1 0.1]);

Visualize the robot model with the added visuals.

show(robotRBT)

ans = 
  Axes (Primary) with properties:

             XLim: [-1 1]
             YLim: [-1 1]
           XScale: 'linear'
           YScale: 'linear'
    GridLineStyle: '-'
         Position: [0.1300 0.1100 0.7750 0.8150]
            Units: 'normalized'

  Show all properties

Create a URDF exporter object. Package the mesh and URDF details in one folder.

exporter = urdfExporter(robotRBT);
exporter.ExportMesh = true;

Write the packaged mesh and URDF details into the specified file.

writefile(exporter,OutputfileName="abbIrb120.urdf")

This example shows how to load a robot as rigidBodyTree model and generate XML DOM node from it. You also modify the robot details in the XML DOM node and write the modified details in the URDF file.

Load a rigidBodyTree robot model. The rigidBodyTree contains kinematic and dynamic constraints and visual meshes for the specified robot geometry.

robotRBT = importrobot("iiwa7.urdf");

Create a URDF exporter object.

exporter = urdfExporter(robotRBT);

Get robot details in the XML DOM node.

node = exporter.writenode();

Get specific joint element from the robot element.

jn0 = node.getElementsByTagName(... 
            "robot").item(0).getElementsByTagName(... 
             "joint").item(0);

Modify the joint type to "fixed" of the specified joint element.

jn0.setAttribute("type","fixed");

Write the modified details in URDF file format.

writer = matlab.io.xml.dom.DOMWriter;
writeToFile(writer,node,"iiwa7.urdf")

Version History

Introduced in R2023b

See Also

Objects

Functions