Skip to main content

The ultimate Python tool for RObot Descriptions processing.

Project description

RObot Description processor

The ultimate Python tool for RObot Descriptions processing.

ROD is yet another library to operate on robot descriptions based on the SDFormat specification.

Why SDFormat?

Among the many existing robot description formats, SDFormat provides a well-defined and maintained versioned specification that controls the available fields and their content. Open Robotics already provides the C++ library gazebosim/sdformat with initial support of Python bindings. However, C++ dependencies in pure-Python projects are typically quite complicated to handle and maintain. Here ROD comes to rescue.

URDF, thanks to native ROS support, is historically the most popular robot description used by the community. The main problem of URDF is that it is not a specification, and developers of URDF descriptions might produce models and parsers that do not comply to any standard. Luckily, URDF models can be easily converted to SDF[^urdf_to_sdf]. If the URDF model is not compliant, the process errors with clear messages. Furthermore, modern versions of the converter produce a SDF description with standardized pose semantics, that greatly simplifies the life of downstream developers that do not have to guess the reference frame or pose elements. Last but not least, the pose semantics also makes SDF aware of the concept of frame that URDF is missing.

Features

  • Out-of-the-box support of SDFormat specifications ≥ 1.7
  • Serialization and deserialization support of SDF files
  • In-memory layout based on dataclasses
  • Syntax highlighting and auto-completion
  • Support of programmatic creation of SDF files from Python APIs
  • Transitive support of URDF through conversion to SDF[^urdf_to_sdf]
  • Type validation of elements and attributes
  • Automatic check of missing required elements
  • Based on Fatal1ty/mashumaro for great serialization and deserialization performance
  • Support of exporting the in-memory model description to URDF

[^urdf_to_sdf]: Conversion can be done either using ign sdf included in Ignition Gazebo Fortress, or gz sdf included in Gazebo Sim starting from Garden.

Installation

You can install the project with pypa/pip, preferably in a virtual environment:

pip install git+https://github.com/ami-iit/rod

Examples

Serialize and deserialize SDF files
import pathlib

from rod import Sdf

# Supported SDF resources
sdf_resource_1 = "/path/to/file.sdf"
sdf_resource_2 = pathlib.Path(sdf_resource_1)
sdf_resource_3 = sdf_resource_2.read_text()

# Deserialize SDF resources
sdf_1 = Sdf.load(sdf=sdf_resource_1)
sdf_2 = Sdf.load(sdf=sdf_resource_2)
sdf_3 = Sdf.load(sdf=sdf_resource_3)

# Serialize in-memory Sdf object
print(sdf_3.serialize(pretty=True))
Create SDF models programmatically
from rod import Axis, Inertia, Inertial, Joint, Limit, Link, Model, Sdf, Xyz

sdf = Sdf(
    version="1.7",
    model=Model(
        name="my_model",
        link=[
            Link(name="base_link", inertial=Inertial(mass=1.0, inertia=Inertia())),
            Link(name="my_link", inertial=Inertial(mass=0.5, inertia=Inertia())),
        ],
        joint=Joint(
            name="base_to_my_link",
            type="revolute",
            parent="base_link",
            child="my_link",
            axis=Axis(xyz=Xyz(xyz=[0, 0, 1]), limit=Limit(lower=-3.13, upper=3.14)),
        ),
    ),
)

print(sdf.serialize(pretty=True))
<?xml version="1.0" encoding="utf-8"?>
<sdf version="1.7">
  <model name="my_model">
    <link name="base_link">
      <inertial>
        <mass>1.0</mass>
        <inertia>
          <ixx>1.0</ixx>
          <iyy>1.0</iyy>
          <izz>1.0</izz>
          <ixy>0.0</ixy>
          <ixz>0.0</ixz>
          <iyz>0.0</iyz>
        </inertia>
      </inertial>
    </link>
    <link name="my_link">
      <inertial>
        <mass>0.5</mass>
        <inertia>
          <ixx>1.0</ixx>
          <iyy>1.0</iyy>
          <izz>1.0</izz>
          <ixy>0.0</ixy>
          <ixz>0.0</ixz>
          <iyz>0.0</iyz>
        </inertia>
      </inertial>
    </link>
    <joint name="base_to_my_link" type="revolute">
      <parent>base_link</parent>
      <child>my_link</child>
      <axis>
        <xyz>0 0 1</xyz>
        <limit>
          <lower>-3.13</lower>
          <upper>3.14</upper>
        </limit>
      </axis>
    </joint>
  </model>
</sdf>
Exporting SDF to URDF
# Generate first the 'sdf' object with the collapsed code
# of the section 'Create SDF models programmatically'.

from rod.urdf.exporter import UrdfExporter

urdf_string = UrdfExporter.sdf_to_urdf_string(
    sdf=sdf,
    pretty=True,
    gazebo_preserve_fixed_joints=True,
)

print(urdf_string)
<?xml version="1.0" encoding="utf-8"?>
<robot name="my_model">
  <link name="base_link">
    <inertial>
      <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
      <mass value="1.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>
    </inertial>
  </link>
  <link name="my_link">
    <inertial>
      <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
      <mass value="0.5"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>
    </inertial>
  </link>
  <joint name="base_to_my_link" type="revolute">
    <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
    <parent link="base_link"/>
    <child link="my_link"/>
    <axis xyz="0 0 1"/>
    <limit effort="3.4028235e+38" velocity="3.4028235e+38" lower="-3.13" upper="3.14"/>
  </joint>
</robot>

Similar projects

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Maintainers

@diegoferigo

License

BSD3

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

rod-0.1.dev91.tar.gz (36.2 kB view details)

Uploaded Source

Built Distribution

rod-0.1.dev91-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file rod-0.1.dev91.tar.gz.

File metadata

  • Download URL: rod-0.1.dev91.tar.gz
  • Upload date:
  • Size: 36.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for rod-0.1.dev91.tar.gz
Algorithm Hash digest
SHA256 8ee1dddcf6214a62f03db0b4611060616dc0fe02f38a0f4ed8b8ad38f5955744
MD5 c3b15071f0df62895c9f38b0142d1bda
BLAKE2b-256 68b70fdda16fd124b6b605b3171819e93ff2f983f37b99fafb4e6114bbc8fb66

See more details on using hashes here.

File details

Details for the file rod-0.1.dev91-py3-none-any.whl.

File metadata

  • Download URL: rod-0.1.dev91-py3-none-any.whl
  • Upload date:
  • Size: 37.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for rod-0.1.dev91-py3-none-any.whl
Algorithm Hash digest
SHA256 f742515fa468bb33be17ccdac9a028201e669d76cdad4762308614caa541e83e
MD5 1acccd7697c7a7b94a868fa8f8a38f4a
BLAKE2b-256 b2556fbbe7aec09a25be8c0e582a3c031e0d7410c59d4d4f748ccf1842a86dbe

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