simulation.utils.urdf.core module

Class definitions of core building blocks of the package.

Summary

Classes:

Attribute

Basic class that will be converted into a xml attribute.

Axis

Origin

XmlObject

Base class for all urdf xml objects.

Reference

class Attribute(val: str, name: Optional[str] = None)[source]

Bases: str

Basic class that will be converted into a xml attribute.

Important: Within a subclass of XmlObject an attribute can be defined by simply annotating a class variable with py:class:Attribute!

Example

>>> from dataclasses import dataclass
>>> from urdf.core import XmlObject, Attribute
>>> @dataclass
... class Example(XmlObject):
...     TAG = "example"
...     name: Attribute
...     value1: str
...     value2: float = None
>>> ex = Example("example_name",value1="I'm an example.")

The code block defines a simple example class that results in the xml string:

<example name="example_name">
  <value1>I'm an example.</value1>
</example>
Parameters
  • val – Attribute value.

  • nameOptionally the name of the can be provided. By default the name of the Attribute instance defines the name of the resulting xml attribute.

class XmlObject[source]

Bases: object

Base class for all urdf xml objects.

TAG = None
_get_val(val: Any) → str[source]

Convert a value to a string that is included into the xml.

create_xml(root_el: Optional[xml.etree.ElementTree.Element] = None) → xml.etree.ElementTree.Element[source]

Convert this instance into a xml element.

  • If the class of this instance does not define a tag, new xml elements from this instance are appended to the root_el. Otherwise, a sub element is created and returned.

  • Additionally to all instance attributes, a dictionary parameters can be used to define sub elements.

  • A Attribute type annotation for any of the object`s attributes, will result in a xml attribute.

Parameters

root_elOptional element that is used a parent xml element when provided.

save(file_path: str)[source]

Save this instance as a xml string to a file.

Parameters

file_path – Location to store the xml.

_origin_default_list()[source]
class Origin(xyz: simulation.utils.urdf.core.Attribute = <factory>, rpy: simulation.utils.urdf.core.Attribute = <factory>)[source]

Bases: simulation.utils.urdf.core.XmlObject

TAG = 'origin'
xyz: simulation.utils.urdf.core.Attribute
rpy: simulation.utils.urdf.core.Attribute
classmethod from_vector(vector: simulation.utils.geometry.vector.Vector)[source]
classmethod from_list(lst: List[float])[source]
class Axis(xyz: simulation.utils.urdf.core.Attribute = <factory>)[source]

Bases: simulation.utils.urdf.core.XmlObject

TAG = 'axis'
xyz: simulation.utils.urdf.core.Attribute