Import a multibody model from a URDF or Simscape Multibody XML file
[H,dataFileName]
= smimport(multibodyDescriptionFile)
[H,dataFileName]
= smimport(multibodyDescriptionFile,Name,Value)
[
generates
a Simscape™
Multibody™ model from a multibody description file conforming
to the URDF XML specification or to the Simscape
Multibody XML
schema. Models generated from Simscape
Multibody XML files are
accompanied by data files that provide the block parameter values. H
,dataFileName
]
= smimport(multibodyDescriptionFile
)
H
is the model handle and dataFileName
is
the name of the supporting data file. By default, the model and data
file are named after the URDF or XML multibody description file. If
the name of the multibody description file does not conform to MATLAB® naming
rules, a modified version of the file name is used in its place.
multibodyDescriptionFile
is the name of
the multibody description file. The file path can be absolute or relative.
If no path is given, the function searches for the file on the MATLAB path.
The file extension is optional. In the absence of an extension, the
function treats the file as a Simscape
Multibody XML file.
The multibody description file details the structure and properties of the model to import. The file can be in URDF or Simscape Multibody XML formats. URDF files must conform to the URDF XML specification. Simscape Multibody XML files must conform to the Simscape Multibody XML schema.
You can use the Simscape Multibody Link CAD plug-in to generate a valid Simscape Multibody XML file from the following CAD applications:
Autodesk Inventor®
PTC® Creo™
SolidWorks®
The plug-in exports assemblies in two XML formats, one specific
to Simscape
Multibody models, the other to Simscape
Multibody First
Generation models. The smimport
function accepts
only XML files generated for Simscape
Multibody models. For Simscape
Multibody First
Generation models, use mech_import
instead.
The data file, which accompanies models generated from Simscape Multibody XML files, provides the numerical values of the block parameters in the form of a MATLAB data structure. Blocks in the imported model reference the MATLAB structure fields through the model workspace. The default structure name is smiData.
[
adds options for specifying a CAD import mode, a CAD model simplification mode, and
various file names. Set H
,dataFileName
]
= smimport(multibodyDescriptionFile
,Name,Value
)ImportMode
to
dataFile
in order to generate a new data file for a
previously imported CAD assembly model. Specify PriorDataFile
to catch unexpected changes to the XML multibody description file, such as part name
changes or the addition and deletion of parts. Only the
ModelName
argument applies if importing from a URDF
multibody description file.
Import a model of a robotic arm from an XML
multibody description file named sm_robot.xml
.
The XML file is part of your Simscape
Multibody installation.
Import the model and store it in memory as Untitled
.
You can later save the model with your name of choice.
smimport('sm_robot');
Update the diagram to assemble the model and visualize it in Mechanics Explorer. You can update the diagram from the Simulink® menu bar by selecting Simulation > Update Diagram.
The view convention of the source CAD platform differs from that of Simscape Multibody software, causing the model to appear on its side.
In the Mechanics Explorer tool strip, set the View convention parameter to Y up (XY Front) and select a standard viewpoint, such as the isometric view shown below.
Selecting a standard view activates the new view convention. The visualization rotates to show the robot arm in the proper orientation.
Simulate the model. The robot arm lacks a control system and swings around under the influence of gravity.
Build on the model by adding control subsystems to simulate useful tasks. Add internal mechanics and state targets at joints to dampen motion and configure the starting pose of the arm.
Generate a CAD robotic arm model from the sm_robot.xml
multibody
description file included in your Simscape
Multibody installation.
Specify the model name as robotto
and the data
file name as robottos_data_file
. At the MATLAB command
prompt, enter the following code.
smimport('sm_robot','ModelName','robotto',... 'DataFileName','robottos_data_file');
Regenerate the data file for the previously
imported CAD robotic arm model. Specify the data file name as robottos_new_data_file
to
avoid overwriting the original data file. At the MATLAB command
prompt, enter the following code.
smimport('sm_robot','ImportMode','dataFile','DataFileName',... 'robottos_new_data_file','PriorDataFile','robottos_data_file');
Point the previously generated model to the new data file and reinitialize the model workspace using the following MATLAB code.
hws = get_param(bdroot,'modelworkspace'); hws.DataSource = 'MATLAB File'; hws.FileName = 'robotFileData'; hws.reload;
You can perform the same task using Model Explorer. In the Model Workspace pane for the imported model, enter the updated File Name parameter. Then, click the Reinitialize from Source button.
Import a URDF model of a humanoid robot from
the URDF model file sm_humanoid.urdf
. The URDF
file is part of the Simscape
Multibody installation.
Import the model and store it in memory as Untitled
.
You can later save the model with your name of choice. The file extension
is optional when importing XML files but required when importing URDF
files.
smimport('sm_humanoid.urdf');
Update the diagram to assemble the model and visualize it in Mechanics Explorer. You can update the diagram from the Simulink menu bar by selecting Simulation > Update Diagram.
Simulate the model. The robot arm lacks a control system and swings around under the influence of gravity. The shoulder line is the root body in the URDF model and it is fixed to the world frame in the imported model.
Try modifying the model—for example, by removing the
rigid connection between the shoulder line and the world frame and
by adding control subsystems at the various joints. See the Humanoid Robot featured
example for a version of the model with basic motion controls. You
can open the example by entering sm_import_humanoid_urdf
at
the MATLAB command prompt.