timor.Bodies

Classes

Body

The default body class, represents a static/immutable rigid body.

BodyBase

A body describes a rigid robot element with kinematic, dynamic, geometric, and connection properties.

BodySet

A set that raises an error if a duplicate body is added

Connector

A connector is the interface defining where a body can be attached to another body.

ConnectorSet

A set that raises an error if a duplicate connector is added.

Gender

Enumerates possible connector genders

PinBody

A wrapper for a body in pinocchio, which is usually represented only implicitly

Module Contents

class timor.Bodies.Body(body_id, collision, visual=None, connectors=(), inertia=pin.Inertia(0, np.zeros(3), np.zeros((3, 3))), in_module=None)
Inheritance diagram of timor.Bodies.Body

The default body class, represents a static/immutable rigid body.

Construct a Body.

Parameters:
  • body_id (str) – The unique ID of the body

  • collision (timor.Geometry.Geometry) – The collision geometry of the body

  • visual (timor.Geometry.Geometry) – The visual geometry of the body. If None is given, defaults to collision

  • connectors (Iterable[Connector]) – The connectors of the body, defining possible interfaces to other bodies

  • inertia (pinocchio.Inertia) – The inertia of the body, as pin.Inertia

  • in_module (ModuleBase) – The module this body is part of. Will be automatically assigned if the body is defined and added to a module later on.

__copy__()

Custom copy to allow differing connector parent references

Return type:

BodyBase

__eq__(other)

Equality check. The visual attribute is not checked as it does not provide relevant functionality.

__getstate__()

Return objects which will be pickled and saved.

__hash__()

Hashing: We assume IDs are unique, so it poses a valid hash.

__setstate__(state)

Take object from parameter and use it to retrieve class state.

__slots__ = ()
__str__()

The string representation of a body

Return type:

str

static _deduce_package_dir(filepath, content)

Logic for deducing the package directory if the JSONable object is loaded from a file.

Parameters:
  • filepath (pathlib.Path) – The path to the file.

  • content (Union[Dict, List]) – The content of the file parsed into a dictionary.

Note:

This method can be overridden by subclasses to provide custom package directory resolution; e.g. Task.py.

Return type:

pathlib.Path

_id: str = ''
_visual: timor.Geometry.Geometry = None
as_pin_body(placement=Transformation.neutral())

Extracts the body properties that describe a body in a pinocchio robot.

Always places the body in the origin.

Parameters:

placement (timor.utilities.transformation.TransformationLike) – Relative placement of the body to its parent joint

Return type:

PinBody

collision: timor.Geometry.Geometry
connectors: ConnectorSet
classmethod from_json_data(d, package_dir=None, *args, **kwargs)

Maps the json-serialized body description to an instance of this class.

The dictionary will be modified in-place until empty (everything was parsed).

Parameters:
  • d (Dict) – A dictionary with relevant meta-information

  • package_dir (pathlib.Path) – If a mesh is given, it is given relative to a package directory that must be specified

Returns:

An instantiated body

Return type:

Body

classmethod from_json_file(filepath, *args, **kwargs)

Factory method to load a class instance from a json file.

Parameters:
  • filepath (Union[pathlib.Path, str]) – The path to the json file.

  • args – Additional arguments to pass to the from_json_data factory method of the specific class.

  • kwargs – Additional arguments to pass to the from_json_data factory method of the specific class.

classmethod from_json_string(s, package_dir=None)

Maps the json-serialized body description to an instance of this class.

Parameters:
  • s (str) – A json string with relevant meta-information

  • package_dir (pathlib.Path) – If a mesh is given, it is given relative to a package directory that must be specified

Returns:

An instantiated body

Return type:

Body

property id: Tuple[None | str, str]

Composed ID: (module ID, body ID)

Return type:

Tuple[Union[None, str], str]

in_module: ModuleBase = None
inertia: pinocchio.Inertia
property mass: float

The mass of the body in [kg]

Return type:

float

possible_connections_with(other)

Returns a set of connectors that can connect this with other body.

This method does not check whether the connector IDs of the other body overlap with the connector IDs of this body - this has to be achieved by e.g. putting both bodies in a module or in the same ModulesDB.

Parameters:

other (BodyBase) – Another body

Returns:

A list of matching connector pairs like (this_body_connector, other_body_connector)

Return type:

timor.utilities.dtypes.SingleSet

to_json_data()
Returns:

Returns the body specification in a json-ready dictionary

Return type:

Dict[str, any]

to_json_file(save_at, *args, **kwargs)

Writes the instance to a json file.

Parameters:

save_at (Union[pathlib.Path, str]) – File location or folder to write the class to.

to_json_string()

Return the json string representation.

Return type:

str

property visual: timor.Geometry.Geometry

Defaults to collision if not explicitly specified

Return type:

timor.Geometry.Geometry

class timor.Bodies.BodyBase
Inheritance diagram of timor.Bodies.BodyBase

A body describes a rigid robot element with kinematic, dynamic, geometric, and connection properties.

A body is defined by a geometry and inertia-parameters. Its placement is defined implicitly by the connectors

attached to it.

abstractmethod __copy__()

Returns a copy of the body

__eq__(other)

Equality check. The visual attribute is not checked as it does not provide relevant functionality.

__getstate__()

Return objects which will be pickled and saved.

__hash__()

Hashing: We assume IDs are unique, so it poses a valid hash.

__setstate__(state)

Take object from parameter and use it to retrieve class state.

__slots__ = ()
__str__()

The string representation of a body

Return type:

str

static _deduce_package_dir(filepath, content)

Logic for deducing the package directory if the JSONable object is loaded from a file.

Parameters:
  • filepath (pathlib.Path) – The path to the file.

  • content (Union[Dict, List]) – The content of the file parsed into a dictionary.

Note:

This method can be overridden by subclasses to provide custom package directory resolution; e.g. Task.py.

Return type:

pathlib.Path

_id: str
_visual: timor.Geometry.Geometry | None = None
as_pin_body(placement=Transformation.neutral())

Extracts the body properties that describe a body in a pinocchio robot.

Always places the body in the origin.

Parameters:

placement (timor.utilities.transformation.TransformationLike) – Relative placement of the body to its parent joint

Return type:

PinBody

collision: timor.Geometry.Geometry
connectors: ConnectorSet
classmethod from_json_data(d, *args, **kwargs)

Create from a json description.

Parameters:

d (Dict)

classmethod from_json_file(filepath, *args, **kwargs)

Factory method to load a class instance from a json file.

Parameters:
  • filepath (Union[pathlib.Path, str]) – The path to the json file.

  • args – Additional arguments to pass to the from_json_data factory method of the specific class.

  • kwargs – Additional arguments to pass to the from_json_data factory method of the specific class.

classmethod from_json_string(s, *args, **kwargs)

Create from a json string.

Parameters:

s (str)

property id: Tuple[None | str, str]

Composed ID: (module ID, body ID)

Return type:

Tuple[Union[None, str], str]

in_module: ModuleBase
inertia: pinocchio.Inertia
property mass: float

The mass of the body in [kg]

Return type:

float

possible_connections_with(other)

Returns a set of connectors that can connect this with other body.

This method does not check whether the connector IDs of the other body overlap with the connector IDs of this body - this has to be achieved by e.g. putting both bodies in a module or in the same ModulesDB.

Parameters:

other (BodyBase) – Another body

Returns:

A list of matching connector pairs like (this_body_connector, other_body_connector)

Return type:

timor.utilities.dtypes.SingleSet

to_json_data()
Returns:

Returns the body specification in a json-ready dictionary

Return type:

Dict[str, any]

to_json_file(save_at, *args, **kwargs)

Writes the instance to a json file.

Parameters:

save_at (Union[pathlib.Path, str]) – File location or folder to write the class to.

to_json_string()

Return the json string representation.

Return type:

str

property visual: timor.Geometry.Geometry

Defaults to collision if not explicitly specified

Return type:

timor.Geometry.Geometry

class timor.Bodies.BodySet(*elements)
Inheritance diagram of timor.Bodies.BodySet

A set that raises an error if a duplicate body is added

Custom init function.

Might be slow, but provides safety that every element in the input argument is checked using the tested update and add methods. For sophisticated element checking, consider overriding the __contains__ method in sub-classes.

Parameters:

elements (Iterable)

__contains__(item)

Custom duplicate check (unique ID)

Parameters:

item (any)

__eq__(other)

If there is a unique ordering to this set, try to sort the elements and compare them

__hash__()

Hash all the contained elements

__ne__(other)

Override the not equal operatorof a set

_err = 'Element {} already present!'
classmethod _sorting_key(element)

Key function for sorting elements in this set

Parameters:

element (any)

Return type:

any

add(element)

Custom add to set needed s.t. uniqueness is ensured

Return type:

None

copy()

Custom copy should also return a SingleSet

Return type:

SingleSet

filter(func)

Convenience function to avoid set comparison over and over again

Parameters:

func (Callable[[any], bool]) – A filter function that takes an element of this set and evaluates to true if the element should be kept

Returns:

A new set of elements fulfilling the filter criterion

Return type:

SingleSet

intersection(*s)

Intersection should also retutrn a SingleSet

Parameters:

s (Iterable)

Return type:

SingleSet

union(*s)

Returns a SingleSet of the union of this and the input

Parameters:

s (Iterable)

Return type:

SingleSet

update(*s)

Update method that does not change this instance if the input iterable contains duplicates

Parameters:

s (Iterable)

Return type:

None

class timor.Bodies.Connector(connector_id, body2connector=Transformation.neutral(), parent=None, gender=Gender.hermaphroditic, connector_type='', size=tuple())
Inheritance diagram of timor.Bodies.Connector

A connector is the interface defining where a body can be attached to another body.

In order to connect two bodies, they must have a matching pair of connectors. The connector coordinate system is always “pointing away from the body it is attached to”.

Construct a Connector.

Parameters:
  • connector_id (str) – Unique “own” ID of the connector

  • body2connector (timor.utilities.transformation.TransformationLike) – The transformation from the body cos to connector coordinates

  • parent (BodyBase) – The body this connector is attached to. Will be set automatically when the connector is defined before the body and added later on. Every instance can have at most one parent.

  • gender (Union[Gender, str]) – Connector gender. Male and Female connect, Hermaphroditic and Hermaphroditic connect.

  • connector_type (str) – Can be a custom string to define the type of the connector.

  • size (Union[int, float, numpy.ndarray]) – Can be an integer, float or array describing the size of the connector.

__copy__()

Custom copy behavior: Remove the reference to the parent body.

__eq__(other)

Equality check: Same ID, gender, type, size, and pose

__getstate__()

Return objects which will be pickled and saved.

__hash__()

Hashing: We assume IDs are unique, so it poses a valid hash.

__setstate__(state)

Take object from parameter and use it to retrieve class state.

__str__()

The string representation of the connector

Return type:

str

static _deduce_package_dir(filepath, content)

Logic for deducing the package directory if the JSONable object is loaded from a file.

Parameters:
  • filepath (pathlib.Path) – The path to the file.

  • content (Union[Dict, List]) – The content of the file parsed into a dictionary.

Note:

This method can be overridden by subclasses to provide custom package directory resolution; e.g. Task.py.

Return type:

pathlib.Path

_id: str = ''
_type: str = ''
body2connector: timor.utilities.transformation.Transformation
property connector2body: timor.utilities.transformation.Transformation

The inverse transformation from connector to body coordinates

Return type:

timor.utilities.transformation.Transformation

connects(other)

Checks if this connector can be connected with “other”.

Parameters:

other (Connector) – Another connector

Returns:

True if connection is possible. False else.

Return type:

bool

classmethod from_json_data(d, *args, **kwargs)

Maps the serialized connector description to an instance of this class.

Parameters:

d (Dict) – A dictionary with relevant meta-information

Returns:

An instantiated connector

Return type:

Connector

classmethod from_json_file(filepath, *args, **kwargs)

Factory method to load a class instance from a json file.

Parameters:
  • filepath (Union[pathlib.Path, str]) – The path to the json file.

  • args – Additional arguments to pass to the from_json_data factory method of the specific class.

  • kwargs – Additional arguments to pass to the from_json_data factory method of the specific class.

classmethod from_json_string(s, *args, **kwargs)

Create from a json string.

Parameters:

s (str)

gender: Gender
property id: Tuple[None | str, None | str, str]

Composed ID: (module ID, body ID, connector ID)

Return type:

Tuple[Union[None, str], Union[None, str], str]

property own_id: str

The last part of the id - uniquely identifying a connector within its module

Return type:

str

parent: BodyBase = None
size: int | float | numpy.ndarray = ()
to_json_data()
Returns:

Returns the connector specification in a json-ready dictionary

Return type:

Dict[str, any]

to_json_file(save_at, *args, **kwargs)

Writes the instance to a json file.

Parameters:

save_at (Union[pathlib.Path, str]) – File location or folder to write the class to.

to_json_string()

Return the json string representation.

Return type:

str

property type: str

Wrapped as _type attribute to not be confused with python-native type(). Also, is kind of static anyway

Return type:

str

class timor.Bodies.ConnectorSet(*elements)
Inheritance diagram of timor.Bodies.ConnectorSet

A set that raises an error if a duplicate connector is added.

Custom init function.

Might be slow, but provides safety that every element in the input argument is checked using the tested update and add methods. For sophisticated element checking, consider overriding the __contains__ method in sub-classes.

Parameters:

elements (Iterable)

__contains__(item)

Custom duplicate check (unique ID)

Parameters:

item (any)

__eq__(other)

If there is a unique ordering to this set, try to sort the elements and compare them

__hash__()

Hash all the contained elements

__ne__(other)

Override the not equal operatorof a set

_err = 'Element {} already present!'
classmethod _sorting_key(element)

Key function for sorting elements in this set

Parameters:

element (any)

Return type:

any

add(element)

Custom add to set needed s.t. uniqueness is ensured

Return type:

None

copy()

Custom copy should also return a SingleSet

Return type:

SingleSet

filter(func)

Convenience function to avoid set comparison over and over again

Parameters:

func (Callable[[any], bool]) – A filter function that takes an element of this set and evaluates to true if the element should be kept

Returns:

A new set of elements fulfilling the filter criterion

Return type:

SingleSet

intersection(*s)

Intersection should also retutrn a SingleSet

Parameters:

s (Iterable)

Return type:

SingleSet

union(*s)

Returns a SingleSet of the union of this and the input

Parameters:

s (Iterable)

Return type:

SingleSet

update(*s)

Update method that does not change this instance if the input iterable contains duplicates

Parameters:

s (Iterable)

Return type:

None

class timor.Bodies.Gender(*args, **kwds)
Inheritance diagram of timor.Bodies.Gender

Enumerates possible connector genders

__str__()

Ensures defined string casting behavior when storing a connector of a certain gender as json

Return type:

str

connects(other)

Indicates whether two genders form a connection. (sorry, code is homoamoric-agnostic)

Possible connections: h <-> h f <-> m

Parameters:

other (Gender) – Another gender

Returns:

True if connection works

Return type:

bool

f = 0
female = 0
h = 2
hermaphroditic = 2
m = 1
male = 1
class timor.Bodies.PinBody(inertia, placement, name, collision_geometries=None, visual_geometries=None)

A wrapper for a body in pinocchio, which is usually represented only implicitly

Set up a container for a pinocchio body.

Parameters:
  • inertia (pinocchio.Inertia) – the inertia of the body, as a pinocchio inertia object

  • placement (pinocchio.SE3) – the placement of the body, as a pinocchio SE3 object

  • name (str) – the name of the body, should be unique within the robot

  • collision_geometries (List[pinocchio.GeometryObject]) – the collision geometries of the body

  • visual_geometries (List[pinocchio.GeometryObject]) – the visual geometries of the body

body_data(parent_joint_id)

Returns a dictionary that can be used as kwargs for appendBodyToJoint (pinocchio)

Parameters:

parent_joint_id (int)

body_frame_data(parent_joint_id, parent_frame_id)

Returns a dictionary that can be used as kwargs for addBodyFrame (pinocchio)

Parameters:
  • parent_joint_id (int)

  • parent_frame_id (int)

collision_geometries: List[pinocchio.GeometryObject] = []
inertia: pinocchio.Inertia
name: str
placement: pinocchio.SE3
visual_geometries: List[pinocchio.GeometryObject] = []