TinyURDF 1.0.0
Loading...
Searching...
No Matches
Tutorials

At the moment, the available documentation does not provide extensive examples.

  • Additional test scripts, which may be useful, can be found in the test folder.
  • Samples of model files can be found in the urdf directory. These files are mainly sourced from the urdf_files_dataset.

The examples assume that all installation instructions have been followed and that the library is successfully installed.

Example 1: Parsing an URDF File

int main() {
// Create the parser
URDFParser parser;
// Parse the file
parser.parse("path/to/tinyurdf/examples/urdf/example.urdf");
// Get the model
std::shared_ptr<Model> model_ = parser.get();
// Print the model info
std::cout << model_->toString();
return 0;
}
Main user high-level interface for parsing URDF files.
Definition urdf_parser.h:18
void parse(const std::string &filename)
Definition urdf_parser.cc:34
std::shared_ptr< Model > get() override
Definition urdf_parser.cc:39
int main(int argc, char *argv[])
Definition urdf_parse.cc:15

This will print all model data to the standard output without any formatting or adjustments.

Alternatively, when -DBUILD_SCRIPTS is enabled, you can parse the files from the command line as shown below:

./urdf_parse --file path/to/your/urdf_model.urdf

Example 2: Get Multijoint Model Data

int main() {
// Construct the parser
URDFParser parser;
// Call the parsing routine
parser.parse("path/to/file.urdf");
// Get the model
std::shared_ptr<Model> model_ = parser.get();
// Get the model name
std::string name = model_->getName();
// Get model joints
std::vector<std::shared_ptr<Joint>> joints_ = model_->getJoints();
// Get model links
std::vector<std::shared_ptr<Link>> links_ = model_->getLinks();
// Check whether the model is empty
bool status = model_->empty();
return 0;
}

Python Interface Example

Here is an example of the Python interface, which is similar to the C++ interface:

from pytinyurdf import pyurdf_parser
def main():
parser = pyurdf_parser.URDFParser()
urdf_file = "spot.urdf"
parser.parse(urdf_file)
model = parser.get()
print(model.getName())
print(model.__str__())
if __name__ == "__main__":
main()