timor.Bodies
Classes
The default body class, represents a static/immutable rigid body. |
|
A body describes a rigid robot element with kinematic, dynamic, geometric, and connection properties. |
|
A set that raises an error if a duplicate body is added |
|
A connector is the interface defining where a body can be attached to another body. |
|
A set that raises an error if a duplicate connector is added. |
|
Enumerates possible connector genders |
|
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)

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.
- __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__ = ()
- 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:
- _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:
- 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:
- 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:
- in_module: ModuleBase = None
- inertia: pinocchio.Inertia
- 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:
- 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.
- property visual: timor.Geometry.Geometry
Defaults to collision if not explicitly specified
- Return type:
- class 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__ = ()
- 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:
- _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:
- 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.
- in_module: ModuleBase
- inertia: pinocchio.Inertia
- 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:
- 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.
- property visual: timor.Geometry.Geometry
Defaults to collision if not explicitly specified
- Return type:
- class timor.Bodies.BodySet(*elements)

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
- filter(func)
Convenience function to avoid set comparison over and over again
- intersection(*s)
Intersection should also retutrn a SingleSet
- Parameters:
s (Iterable)
- Return type:
- union(*s)
Returns a SingleSet of the union of this and the input
- Parameters:
s (Iterable)
- Return type:
- 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())

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.
- 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:
- body2connector: timor.utilities.transformation.Transformation
- property connector2body: timor.utilities.transformation.Transformation
The inverse transformation from connector to body coordinates
- Return type:
- connects(other)
Checks if this connector can be connected with “other”.
- 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:
- 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.
- property own_id: str
The last part of the id - uniquely identifying a connector within its module
- Return type:
- 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.
- class timor.Bodies.ConnectorSet(*elements)

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
- filter(func)
Convenience function to avoid set comparison over and over again
- intersection(*s)
Intersection should also retutrn a SingleSet
- Parameters:
s (Iterable)
- Return type:
- union(*s)
Returns a SingleSet of the union of this and the input
- Parameters:
s (Iterable)
- Return type:
- 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)

Enumerates possible connector genders
- __str__()
Ensures defined string casting behavior when storing a connector of a certain gender as json
- Return type:
- connects(other)
Indicates whether two genders form a connection. (sorry, code is homoamoric-agnostic)
Possible connections: h <-> h f <-> m
- 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)
- collision_geometries: List[pinocchio.GeometryObject] = []
- inertia: pinocchio.Inertia
- placement: pinocchio.SE3
- visual_geometries: List[pinocchio.GeometryObject] = []