Skip to content

compas_robots.files ¤

This package provides the URDF file format parser used to load robot models from standard URDF descriptions.

Classes¤

URDF ¤

URDF(xml=None)

Class for working with URDF files.

Abstracts away the underlying XML of the Unified Robot Description Format (URDF) and represents it as an object graph.

Attributes:

  • xml (XML) –

    Instance of the XML reader/parser class.

  • robot (object) –

    Root element of the URDF model, i.e. a robot instance.

References

A detailed description of the model is available on the URDF Model wiki. This package parses URDF v1.0 according to the URDF XSD Schema.

Functions¤

from_file classmethod ¤
from_file(source: str | IO) -> URDF

Construct a URDF from a file path or file-like object.

Parameters:

  • source (str | IO) –

    File path or file-like object.

Examples:

>>> urdf = URDF.from_file(compas_robots.get("ur_description/urdf/ur5.urdf"))
from_robot classmethod ¤
from_robot(robot: RobotModel) -> URDF

Construct a URDF from a robot.

Parameters:

  • robot (RobotModel) –

    The robot model to be converted to URDF.

from_string classmethod ¤
from_string(text: str) -> URDF

Construct a URDF from a string.

Parameters:

  • text (str) –

    XML string.

Examples:

>>> urdf = URDF.from_string('<robot name="panda"/>')
to_file ¤
to_file(destination: str | None = None, prettify: bool = False) -> None

Writes the string representation of this URDF instance, including all sub-elements, to the destination.

Parameters:

  • destination (str | None, default: None ) –

    Filepath where the URDF should be written. Defaults to the filepath of the associated XML object.

  • prettify (bool, default: False ) –

    Whether the string should add whitespace for legibility.

to_string ¤
to_string(encoding: str = 'utf-8', prettify: bool = False) -> str

Generate a string representation of this URDF instance, including all sub-elements.

Parameters:

  • encoding (str, default: 'utf-8' ) –

    Output encoding.

  • prettify (bool, default: False ) –

    Whether the string should add whitespace for legibility.

Returns:

  • str

    String representation of the URDF.

write ¤
write(destination: str | None = None, prettify: bool = False) -> None

Writes the string representation of this URDF instance, including all sub-elements, to the destination.

Parameters:

  • destination (str | None, default: None ) –

    Filepath where the URDF should be written. Defaults to the filepath of the associated XML object.

  • prettify (bool, default: False ) –

    Whether the string should add whitespace for legibility.

URDFGenericElement ¤

URDFGenericElement(name=None)

Generic representation for all URDF elements that are not explicitly supported.

URDFParser ¤

Class for parsing URDF elements into an object graph.

Functions¤

install_parser classmethod ¤
install_parser(parser_type: type, *tags: str, **kwargs) -> None

Installs an URDF parser type for a defined tag.

Parameters:

  • parser_type (type) –

    Python class handling URDF parsing of the tag.

  • *tags (str, default: () ) –

    One or more URDF string tag that the parser can parse.

Other Parameters:

  • proxy_type (type) –

    In some cases, the parser type is a general class without knowledge of URDF, and it requires a proxy class to add URDF-related functions to it.

Raises:

parse_element classmethod ¤
parse_element(
    element: XMLElement, path: str = "", element_default_namespace: str | None = None
) -> object

Recursively parse URDF element and its children.

If the parser type implements a class method from_urdf, it will use it to parse the element, otherwise a generic implementation that relies on conventions will be used.

Parameters:

  • element (XMLElement) –

    XML Element node.

  • path (str, default: '' ) –

    Full path to the element.

  • element_default_namespace (str | None, default: None ) –

    Default namespace at the current level current document.

Returns:

  • object

    An instance of the model object represented by the given element.

Raises:

  • TypeError

    If the element instance cannot be created.