Drake
Drake C++ Documentation
Parser Class Referencefinal

Detailed Description

Parses SDF and URDF input files into a MultibodyPlant and (optionally) a SceneGraph.

For documentation of Drake-specific extensions and limitations, see Parsing Models for Multibody Dynamics.

When parsing literal quantities, Parser assumes SI units and radians in the absence of units specified by the format itself. This includes the literals in the explicitly specified files as well as referenced files such as OBJ or other data file formats.

#include <drake/multibody/parsing/parser.h>

Public Member Functions

 Parser (MultibodyPlant< double > *plant, geometry::SceneGraph< double > *scene_graph=nullptr)
 Creates a Parser that adds models to the given plant and (optionally) scene_graph. More...
 
MultibodyPlant< double > & plant ()
 Gets a mutable reference to the plant that will be modified by this parser. More...
 
PackageMappackage_map ()
 Gets a mutable reference to the PackageMap used by this parser. More...
 
void SetStrictParsing ()
 Cause all subsequent Add*Model*() operations to use strict parsing; warnings will be treated as errors. More...
 
std::vector< ModelInstanceIndexAddAllModelsFromFile (const std::string &file_name)
 Parses the SDF, URDF, or MJCF file named in file_name and adds all of its model(s) to plant. More...
 
ModelInstanceIndex AddModelFromFile (const std::string &file_name, const std::string &model_name={})
 Parses the SDFormat, URDF, or MJCF file named in file_name and adds one top-level model to plant. More...
 
ModelInstanceIndex AddModelFromString (const std::string &file_contents, const std::string &file_type, const std::string &model_name={})
 Provides same functionality as AddModelFromFile, but instead parses the SDFormat or URDF XML data via file_contents with type dictated by file_type. More...
 
Does not allow copy, move, or assignment
 Parser (const Parser &)=delete
 
Parseroperator= (const Parser &)=delete
 
 Parser (Parser &&)=delete
 
Parseroperator= (Parser &&)=delete
 

Friends

class internal::CompositeParse
 

Constructor & Destructor Documentation

◆ Parser() [1/3]

Parser ( const Parser )
delete

◆ Parser() [2/3]

Parser ( Parser &&  )
delete

◆ Parser() [3/3]

Parser ( MultibodyPlant< double > *  plant,
geometry::SceneGraph< double > *  scene_graph = nullptr 
)
explicit

Creates a Parser that adds models to the given plant and (optionally) scene_graph.

Parameters
plantA pointer to a mutable MultibodyPlant object to which parsed model(s) will be added; plant->is_finalized() must remain false for as long as the plant is in used by this.
scene_graphA pointer to a mutable SceneGraph object used for geometry registration (either to model visual or contact geometry). May be nullptr.

Member Function Documentation

◆ AddAllModelsFromFile()

std::vector<ModelInstanceIndex> AddAllModelsFromFile ( const std::string &  file_name)

Parses the SDF, URDF, or MJCF file named in file_name and adds all of its model(s) to plant.

SDFormat files may contain multiple <model> elements. New model instances will be added to plant for each <model> tag in the file.

Note
Adding multiple root-level models, i.e, <model>s directly under <sdf>, is deprecated. If you need multiple models in a single file, please use an SDFormat world file.

URDF files contain a single <robot> element. Only a single model instance will be added to plant.

MJCF (MuJoCo XML) files typically contain many bodies, they will all be added as a single model instance in the plant.

Parameters
file_nameThe name of the SDF, URDF, or MJCF file to be parsed. The file type will be inferred from the extension.
Returns
The set of model instance indices for the newly added models, including nested models.
Exceptions
std::exceptionin case of errors.

◆ AddModelFromFile()

ModelInstanceIndex AddModelFromFile ( const std::string &  file_name,
const std::string &  model_name = {} 
)

Parses the SDFormat, URDF, or MJCF file named in file_name and adds one top-level model to plant.

It is an error to call this using an SDFormat file with more than one root-level <model> element.

Note
This function might create additional model instances corresponding to nested models found in the top level SDFormat model. This means that elements contained by the returned model instance may not comprise all of the added elements due to how model instances are mutually exclusive and not hierarchical (#14043).
See also
http://sdformat.org/tutorials?tut=composition&ver=1.7 for details on nesting in SDFormat.

◆ AddModelFromString()

ModelInstanceIndex AddModelFromString ( const std::string &  file_contents,
const std::string &  file_type,
const std::string &  model_name = {} 
)

Provides same functionality as AddModelFromFile, but instead parses the SDFormat or URDF XML data via file_contents with type dictated by file_type.

Parameters
file_contentsThe XML data to be parsed.
file_typeThe data format; must be either "sdf", "urdf", or "xml".
model_nameThe name given to the newly created instance of this model. If empty, the "name" attribute from the <model> or <robot> tag will be used.
Returns
The instance index for the newly added model.
Exceptions
std::exceptionin case of errors.

◆ operator=() [1/2]

Parser& operator= ( Parser &&  )
delete

◆ operator=() [2/2]

Parser& operator= ( const Parser )
delete

◆ package_map()

PackageMap& package_map ( )

Gets a mutable reference to the PackageMap used by this parser.

◆ plant()

MultibodyPlant<double>& plant ( )

Gets a mutable reference to the plant that will be modified by this parser.

◆ SetStrictParsing()

void SetStrictParsing ( )

Cause all subsequent Add*Model*() operations to use strict parsing; warnings will be treated as errors.

Friends And Related Function Documentation

◆ internal::CompositeParse

friend class internal::CompositeParse
friend

The documentation for this class was generated from the following file: