dair_pll.urdf_utils

Utility functions for generating URDF’s for a given multibody system.

The URDFFindOrDefault class searches for elements in an urdf’s xml tree, and places a default in the event that the element does not exist. Many string literals are instantiated here for convenience.

The UrdfGeometryRepresentationFactory generates URDF XML representations of a CollisionGeometry, and fill_link_with_parameterization dumps these representations into a URDF “link” tag.

class dair_pll.urdf_utils.UrdfFindOrDefault[source]

Bases: object

URDF XML tool to automatically fill in default element tree structures.

URDF’s often represent an identifiable unit (e.g. a body’s spatial inertia) as a subtree of XML elements. URDFFindOrDefault implements a generalization of the xml.etree.ElementTree.find() method, which fills in a default subtree according to the tree structure given in _URDF_DEFAULT_TREE, with each element given tags according to _URDF_DEFAULT_ATTRIBUTES.

Typical usage example:

# element is an empty <inertial></inertial>
# obtain default mass
mass_element = URDFFindOrDefault.find(element, "mass")

# element is now <inertial><mass value="0." /></inertial>
# mass_element is now the child of element, <mass value="0." />
static find(element, sub_element_type)[source]

Finds an XML sub-element of specified type, adding a default element of that type if necessary.

Parameters:
  • element (Element) – Element containing the sub-element.

  • sub_element_type (str) – Name of the sub-element type.

Return type:

Element

Returns:

An ElementTree.Element, of type sub_element_type, which is a child of the argument element that either (a) one which existed before the function call or (b) the root of a new, default subtree.

sub-elements of given type.

static generate_default_element(element_type)[source]

Generates a default ElementTree.Element subtree of given type.

Parameters:

element_type (str) – Name of the new default element type.

Return type:

Element

Returns:

A default ElementTree.Element of type element_type.

class dair_pll.urdf_utils.UrdfGeometryRepresentationFactory[source]

Bases: object

Utility class for generating URDF representations of CollisionGeometry instances.

static representation(geometry, output_dir)[source]

Representation of an associated URDF tag that describes the properties of this geometry.

Tags are expected to be put inside a <collision> tag in the URDF file.

Example

To output <sphere radius="5.1"> for a Sphere, return the following:

('sphere', {'radius': '5.1'})
Parameters:
  • geometry (CollisionGeometry) – collision geometry to be represented

  • output_dir (str) – File directory to store helper files (e.g., meshes).

Return type:

Tuple[str, Dict[str, str]]

Returns:

URDF tag and attributes.

static polygon_representation()[source]

Todo: implement representation for Polygon

Return type:

Tuple[str, Dict[str, str]]

static box_representation(box)[source]

Returns URDF representation as box tag with full-length sizes.

Return type:

Tuple[str, Dict[str, str]]

static sphere_representation(sphere)[source]

Returns URDF representation as sphere tag with radius attribute.

Return type:

Tuple[str, Dict[str, str]]

static mesh_representation(convex, output_dir)[source]

Returns URDF representation as mesh tag with name of saved mesh file.

Return type:

Tuple[str, Dict[str, str]]

Convert pytorch inertial and geometric representations to URDF elements.

Parameters:
  • element (Element) – XML “link” tag in which representation is stored.

  • pi_cm (Tensor) – (10,) inertial representation of link in pi_cm parameterization.

  • geometries (List[CollisionGeometry]) – All geometries attached to body.

  • friction_coeffs (Tensor) – All friction coefficients associated with each geometry. The Tensor will be of shape (len(geometries),).

  • output_dir (str) – File directory to store helper files (e.g., meshes).

Warning

Does not handle multiple geometries.

Raises:

NotImplementedError – when multiple geometries are provided.

Return type:

None

dair_pll.urdf_utils.represent_multibody_terms_as_urdfs(multibody_terms, output_dir)[source]

Renders the current parameterization of multibody terms as a set of urdfs.

Parameters:
  • multibody_terms (MultibodyTerms) – Multibody dynamics representation to convert.

  • output_dir (str) – File directory to store helper files (e.g., meshes).

Return type:

Dict[str, str]

Returns:

Dictionary of (urdf name, urdf XML string) pairs.

Warning

For now, assumes that each URDF link element e gets modeled as a corresponding body b with b.name() == e.get("name"). Drake however does not guarantee this relationship. A more stable implementation would be to directly edit the MultibodyPlant, but this would make the representation less portable.