Drake
Parser Class Referencefinal

Detailed Description

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

#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...
 
PackageMappackage_map ()
 Gets a mutable reference to the PackageMap used by this parser. More...
 
std::vector< ModelInstanceIndexAddAllModelsFromFile (const std::string &file_name)
 Parses the SDF or URDF 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 or URDF 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
 

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 or URDF 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.

Parameters
file_nameThe name of the SDF or URDF 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 or URDF 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" or "urdf".
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.


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