Skip to main content

Programmatically compile xacro files.

Project description

xacrodoc

xacrodoc is a tool for programmatically compiling xacro'd URDF files.

Why?

  • Avoid the clutter of redundant compiled raw URDFs; only keep the xacro source files.
  • Programmatically compose multiple xacro files and apply subtitution arguments to build a flexible URDF model.
  • Convenient interfaces to provide URDF strings and URDF file paths as needed. For example, many libraries (such as Pinocchio) accept a URDF string to build a model, but others (like PyBullet) only load URDFs directly from file paths.

See the documentation here.

Installation

xacrodoc requires ROS to be installed on your system with Python 3.

From pip:

pip install xacrodoc

For a source installation, build in a catkin workspace:

cd catkin_ws/src
git clone https://github.com/adamheins/xacrodoc
catkin build

Usage

A basic use-case of compiling a URDF from a xacro file:

from xacrodoc import XacroDoc

doc = XacroDoc.from_file("robot.urdf.xacro")

# or relative to a ROS package
# e.g., for a file located at some_ros_package/urdf/robot.urdf.xacro:
doc = XacroDoc.from_package_file("some_ros_package", "urdf/robot.urdf.xacro")

# convert to a string of URDF
urdf_str = doc.to_urdf_string()

# or write to a file
doc.to_urdf_file("robot.urdf")

# or just work with a temp file
# this is useful for working with libraries that expect a URDF *file* (rather
# than a string)
with doc.temp_urdf_file_path() as path:
  # do stuff with URDF file located at `path`...
  # file is cleaned up once context manager is exited

We can also build a URDF programmatically from multiple xacro files:

from xacrodoc import XacroDoc

# specify files to compose (using xacro include directives)
includes = ["robot_base.urdf.xacro", "robot_arm.urdf.xacro", "tool.urdf.xacro"]
doc = XacroDoc.from_includes(includes)

# includes can also use $(find ...) directives:
includes = [
    "$(find my_ros_package)/urdf/robot_base.urdf.xacro",
    "$(find another_ros_package)/urdf/"robot_arm.urdf.xacro",
    "tool.urdf.xacro"
]
doc = XacroDoc.from_includes(includes)

Finally, we can also pass in substution arguments. For example, suppose our file robot.urdf.xacro contains the directive <xacro:arg name="mass" default="1"/>. On the command line, we could write

xacro robot_base.urdf.xacro -o robot_base.urdf mass:=2

to set the mass value. Programmatically, we do

from xacrodoc import XacroDoc

doc = XacroDoc.from_file("robot.urdf.xacro", subargs={"mass": "2"})

Development

Tests use pytest. Ensure that the catkin workspace's setup file has been sourced to make the package available, then do:

cd tests
pytest .

For local testing, the project needs to be built as a ROS package in a catkin workspace, which uses the setup.py file. For building and publishing to PyPI, we use poetry and the configuration in pyproject.toml.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xacrodoc-0.2.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

xacrodoc-0.2.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file xacrodoc-0.2.0.tar.gz.

File metadata

  • Download URL: xacrodoc-0.2.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.10 Linux/5.15.79-rt54

File hashes

Hashes for xacrodoc-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b7176b5dc2c2f1ed0026c0edfe55a7be160a1c0bcbc200410239e43af8660135
MD5 554e80335c1fc8c1e2c61ba29bb14e50
BLAKE2b-256 d984432b043437fc3fe747f2daf1917b766346ad8ce1599c150b3ef46d4abbaa

See more details on using hashes here.

File details

Details for the file xacrodoc-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: xacrodoc-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.10 Linux/5.15.79-rt54

File hashes

Hashes for xacrodoc-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51c1f06deaea94edbb8c90b914348da8c139dc405df6e16d1fa85b4e25afd114
MD5 3d34a59d82b4c375b85eb1a6529e2998
BLAKE2b-256 5089a1adb286c4a837177c65119df08e0f3bf676e034fc0753d6b4746ef33ea9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page