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.

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")

# 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:

cd tests
pytest .

Build and package:

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.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

xacrodoc-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xacrodoc-0.1.0.tar.gz
  • Upload date:
  • Size: 4.6 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.1.0.tar.gz
Algorithm Hash digest
SHA256 8254884f2b880670bce42b92efffc3a86ae024525a217c1a54b140e6f0ad67d9
MD5 c5eecd12993fa8cefd3669e0378f6ca0
BLAKE2b-256 cccd8859533790dad5cec728c62f6992927f5647d6e73f61e9e9574702b992a2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xacrodoc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3bfa11c6cd22f8a542f7bf16c4b25af3f8ab4f76d34d3082a83b75d053134179
MD5 e4e6e99fce76cd9c8fdc47d47df12ee3
BLAKE2b-256 1e266156c78481f66393e07946acb33d03b0c92ed60243202d8b9d4ccbd48814

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