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
parser.
parse(
"path/to/tinyurdf/examples/urdf/example.urdf");
std::shared_ptr<Model> model_ = parser.
get();
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
parser.
parse(
"path/to/file.urdf");
std::shared_ptr<Model> model_ = parser.
get();
std::string name = model_->getName();
std::vector<std::shared_ptr<Joint>> joints_ = model_->getJoints();
std::vector<std::shared_ptr<Link>> links_ = model_->getLinks();
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
parser = pyurdf_parser.URDFParser()
urdf_file = "spot.urdf"
parser.parse(urdf_file)
model = parser.get()
print(model.getName())
print(model.__str__())
if __name__ == "__main__":