timor.task.Solution

Classes

SolutionBase

A solution describes an assembly and a trajectory it follows in order to reach all goals in a task

SolutionHeader

The header every solution contains

SolutionTrajectory

A solution based on a given trajectory (as opposed to a solution based on torques given)

Module Contents

class timor.task.Solution.SolutionBase(header, task, assembly, cost_function=None, base_pose=Transformation.neutral())
Inheritance diagram of timor.task.Solution.SolutionBase

A solution describes an assembly and a trajectory it follows in order to reach all goals in a task

Build a solution that shows how to solve a Task.

Parameters:
  • header (Union[Dict, SolutionHeader]) – The header of the solution, containing information about the task it was crafted for and some more distinctive meta-information.

  • task (timor.task.Task.Task) – The task the solution was crafted for

  • assembly (Union[timor.Module.ModuleAssembly, timor.Robot.RobotBase]) – The assembly that solves the task. Providing a robot instance is supported but disencouraged - it will trigger an internal wrapping to assembly, which is not efficient.

  • cost_function (Optional[timor.task.CostFunctions.CostFunctionBase]) – The cost function used to evaluate the solution (usually the lower, the better)

  • base_pose (timor.utilities.transformation.TransformationLike) – The base placement of the assembly

__getstate__()

State of solution contains json-able part and the associated task object.

__repr__()

Debug representation of a solution.

__setstate__(state)

To recreate solution use the state Tuple including the solution json and associated task object.

__slots__ = ()
__str__()

String representation of the solution

_base_pose: timor.utilities.transformation.Transformation
_check_valid()

Returns true if all constraints are fulfilled by this solution.

Note:

add allGoalsFulfilled Constraint if you want to ensure all goals and their constraints are fulfilled

Return type:

bool

_cost: timor.utilities.dtypes.Lazy | bool
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

_evaluate_cost()

Evaluates the cost function - without checking validity though

Return type:

float

_module_assembly: timor.Module.ModuleAssembly
_task: timor.task.Task.Task
_valid: timor.utilities.dtypes.Lazy | bool
property cost: float

Evaluating lazy variable _cost

Return type:

float

cost_function: timor.task.CostFunctions.CostFunctionBase = None
property ddq: numpy.ndarray
Abstractmethod:

Return type:

numpy.ndarray

Joint accelerations of the trajectory

property dq: numpy.ndarray
Abstractmethod:

Return type:

numpy.ndarray

Joint velocities of the trajectory

property eef_wrench: numpy.ndarray
Abstractmethod:

Return type:

numpy.ndarray

End effector wrench [f_x, f_y, f_z, tau_x, tau_y, tau_z] acting on the end-effector (external wrench)

classmethod empty()
Abstractmethod:

Return type:

SolutionBase

Create an empty solution

property failed_constraints: Tuple[timor.task.Constraints.ConstraintBase, Ellipsis]

A tuple of all task-level constraints that were hurt by this solution

Return type:

Tuple[timor.task.Constraints.ConstraintBase, Ellipsis]

property failed_goals: Tuple[timor.task.Goals.GoalBase, Ellipsis]

A tuple of all goals that were not fulfilled by this solution

Return type:

Tuple[timor.task.Goals.GoalBase, Ellipsis]

static from_json_data(content, tasks, *args, **kwargs)

Factory method to load a class instance from a dictionary.

Parameters:
  • kwargs

    • reload_module_DB: If True, the module DB will be reloaded from file (default) otherwise will be

    cached for faster solution loading.

  • content (Dict)

  • tasks (Dict[str, timor.task.Task.Task])

Return type:

SolutionBase

classmethod from_json_file(json_path, tasks)

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

Parameters:
Return type:

SolutionBase

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

Create from a json string.

Parameters:

s (str)

get_time_id(t)

Get the index of the time step at which the given time is located

Parameters:

t (float)

Return type:

int

header: SolutionHeader
property module_assembly: timor.Module.ModuleAssembly

The robot / module assembly set to solve this task.

Return type:

timor.Module.ModuleAssembly

property q: numpy.ndarray
Abstractmethod:

Return type:

numpy.ndarray

Joint positions of the trajectory

property robot: timor.Robot.RobotBase

Provide read access to the robot. This call might be expensive, depending on whether the robot is cached.

Return type:

timor.Robot.RobotBase

property t_goals: Dict[str, float]
Abstractmethod:

Return type:

Dict[str, float]

Mapping from goal IDs to the time at which they were achieved

property t_resolution: float

All goal times can be at most t_resolution apart from the next time step defined in self

Return type:

float

property task

Prevent setting task directly

property tau: numpy.ndarray

Alias for torques

Return type:

numpy.ndarray

tcp_acceleration_at(t)

Returns the velocity of the tool center point at time t

Parameters:

t (float) – The time in the solution at which the tcp acceleration should be given. Must be one of the time steps in the provided (trajectory | torques).

Returns:

Acceleration [m / s**2]

Return type:

numpy.ndarray

tcp_pose_at(t)

Returns the placement of the tool center point at time t

Parameters:

t (float) – The time in the solution at which the tcp position should be given. Must be one of the time steps in the provided (trajectory | torques).

Return type:

timor.utilities.transformation.Transformation

tcp_velocity_at(t)

Returns the velocity of the tool center point at time t

Parameters:

t (float) – The time in the solution at which the tcp velocity should be given. Must be one of the time steps in the provided (trajectory | torques).

Returns:

Velocity [m/s]

Return type:

numpy.ndarray

property time_steps: numpy.ndarray
Abstractmethod:

Return type:

numpy.ndarray

Time steps of the trajectory

abstractmethod to_json_data()

Should be implemented by children to dump a solution

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()

Convert the solution to a json string

Return type:

str

property torques: numpy.ndarray
Abstractmethod:

Return type:

numpy.ndarray

Torques of the trajectory

property valid: bool

Evaluating lazy variable _lazy

Return type:

bool

visualize(viz=None, fps=30.0, center_view=True)

Visualize a solution trajectory

Parameters:
Return type:

pinocchio.visualize.MeshcatVisualizer

class timor.task.Solution.SolutionHeader
Inheritance diagram of timor.task.Solution.SolutionHeader

The header every solution contains

__delattr__(item)

Delete attribute

__post_init__()

Post init function that ensures the correct datatypes

__setattr__(key, value)

Sets an attribute of this class

_raise_immutable(f)

Raises error if objects in this dataclass are to be resetted but the instance is set to immutable

Parameters:

f (Callable)

Return type:

Callable

affiliation: List[str] = ['']
asdict()

Returns a dictionary representation of this object

Return type:

Dict[str, Any]

author: List[str] = ['']
static cast(value, cast_to_type)

Casts the value to the dtype

Parameters:
  • value (Any)

  • cast_to_type (Type)

Return type:

Any

static cast_to_date(value)

Casts the value to a datetime.date object

Parameters:

value (Union[str, datetime.date, datetime.datetime])

Return type:

datetime.date

computationTime: float = -1.0
date: datetime.date
email: List[str] = ['']
classmethod empty()

Creates an empty solution header with a random taskID

Return type:

SolutionHeader

classmethod fields()

Returns the fields of this class

Return type:

Tuple[str, Ellipsis]

notes: str = ''
processorName: str = ''
publication: str = ''
static string_list_factory()

Returns a field with a default factory that returns a list with one empty string

Return type:

dataclasses.field

tags: List[str] = ['']
taskID: str
version: str = '2023'
class timor.task.Solution.SolutionTrajectory(trajectory, header, task, assembly, cost_function=None, base_pose=Transformation.neutral())
Inheritance diagram of timor.task.Solution.SolutionTrajectory

A solution based on a given trajectory (as opposed to a solution based on torques given)

Build a solution based on a given trajectory

Parameters:
__getstate__()

State of solution contains json-able part and the associated task object.

__repr__()

Debug representation of a solution.

__setstate__(state)

To recreate solution use the state Tuple including the solution json and associated task object.

__slots__ = ()
__str__()

String representation of the solution

_base_pose: timor.utilities.transformation.Transformation
_check_valid()

Returns true if all constraints are fulfilled by this solution.

Note:

add allGoalsFulfilled Constraint if you want to ensure all goals and their constraints are fulfilled

Return type:

bool

_cost: timor.utilities.dtypes.Lazy | bool
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

_evaluate_cost()

Evaluates the cost function - without checking validity though

Return type:

float

_get_torques(motor_inertia=True, friction=True)

Utility method to calculate joint torques to command based on the trajectory.

Parameters:
  • motor_inertia (bool) – Include motor side inertia in torque calculations to compensate them (details see robot.id)

  • friction (bool) – Include joint friction in torque calculations to compensate for them (details see robot.id)

Note:

Disabling both motor_inertia and friction will lead to the torques provided to the physical links by the motor-gearbox subsystem.

Note:

Motor inertia and friction can be the dominating parts of the required torques especially for robots with high gear ratios.

Return type:

numpy.ndarray

_module_assembly: timor.Module.ModuleAssembly
_task: timor.task.Task.Task
_torques
_valid: timor.utilities.dtypes.Lazy | bool
property cost: float

Evaluating lazy variable _cost

Return type:

float

cost_function: timor.task.CostFunctions.CostFunctionBase = None
property ddq: numpy.ndarray

The joint accelerations of the trajectory

Return type:

numpy.ndarray

property dq: numpy.ndarray

The joint velocities of the trajectory

Return type:

numpy.ndarray

property eef_wrench: numpy.ndarray

End effector wrench [f_x, f_y, f_z, tau_x, tau_y, tau_z] acting on the end-effector (external wrench)

Return type:

numpy.ndarray

classmethod empty()

Returns an empty solution with an empty trajectory

Return type:

SolutionTrajectory

property failed_constraints: Tuple[timor.task.Constraints.ConstraintBase, Ellipsis]

A tuple of all task-level constraints that were hurt by this solution

Return type:

Tuple[timor.task.Constraints.ConstraintBase, Ellipsis]

property failed_goals: Tuple[timor.task.Goals.GoalBase, Ellipsis]

A tuple of all goals that were not fulfilled by this solution

Return type:

Tuple[timor.task.Goals.GoalBase, Ellipsis]

static from_json_data(content, tasks, *args, **kwargs)

Factory method to load a class instance from a dictionary.

Parameters:
  • kwargs

    • reload_module_DB: If True, the module DB will be reloaded from file (default) otherwise will be

    cached for faster solution loading.

  • content (Dict)

  • tasks (Dict[str, timor.task.Task.Task])

Return type:

SolutionBase

classmethod from_json_file(json_path, tasks)

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

Parameters:
Return type:

SolutionBase

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

Create from a json string.

Parameters:

s (str)

get_mechanical_energy(motor_inertia=True, friction=True)

Get mechanical energy needed to follow this solution.

Parameters:
  • motor_inertia (bool) – Include energy to overcome motor side inertia.

  • friction (bool) – Include energy to overcome joint friction.

Note:

If both options enabled this is the mechanical energy expanded by all motors in the robot to follow this solution; if both options are disabled it is the mechanical energy expanded on moving all robot links.

get_power(motor_inertia=True, friction=True)

Get mechanical power used in all joints for each time step.

Parameters:
  • motor_inertia (bool) – Include power needed to overcome motor side inertia.

  • friction (bool) – Include power needed to overcome joint friction.

Note:

If both options enabled this is the mechanical power produced by all motors in the robot; if both options are disabled it is the mechanical power acting on all robot links.

get_time_id(t)

Get the index of the time step at which the given time is located

Parameters:

t (float)

Return type:

int

header: SolutionHeader

Method to calculate the torques acting from the motor-gearbox unit on the different links.

In comparison to self.torques excludes the torques required to counteract joint friction and rotor inertia

property manipulability_indices: numpy.ndarray

Return manipulability index at each time in time_steps.

Return type:

numpy.ndarray

property module_assembly: timor.Module.ModuleAssembly

The robot / module assembly set to solve this task.

Return type:

timor.Module.ModuleAssembly

plot(data=('q', 'dq', 'ddq'), show_figure=True, subplot_kwargs=None)

Plot time series data about this solution

Parameters:
  • data (Sequence[str]) – Can be any combination of q, dq, ddq, tau, manipulability, goals, eef_position, eef_rotation

  • show_figure (bool) – execute pyplot show() function on figure; might need to disable if further figure formating wanted later on; may need to activate text.usetex in the local environment where show is called.

  • subplot_kwargs (Optional[Dict]) – Kwargs handed to subplots, including pyplot.figure kwargs (see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html)

Returns:

Figure object containing the desired plots

Return type:

matplotlib.pyplot.Figure

property q: numpy.ndarray

The joint positions of the trajectory

Return type:

numpy.ndarray

property robot: timor.Robot.RobotBase

Provide read access to the robot. This call might be expensive, depending on whether the robot is cached.

Return type:

timor.Robot.RobotBase

property t_goals: Dict[str, float]

Mapping from goal ID to the time at which the goal was reached

Return type:

Dict[str, float]

property t_resolution: float

All goal times can be at most t_resolution apart from the next time step defined in self

Return type:

float

property task

Prevent setting task directly

property tau: numpy.ndarray

Alias for torques

Return type:

numpy.ndarray

tcp_acceleration_at(t)

Returns the velocity of the tool center point at time t

Parameters:

t (float) – The time in the solution at which the tcp acceleration should be given. Must be one of the time steps in the provided (trajectory | torques).

Returns:

Acceleration [m / s**2]

Return type:

numpy.ndarray

tcp_pose_at(t)

Returns the placement of the tool center point at time t

Parameters:

t (float) – The time in the solution at which the tcp position should be given. Must be one of the time steps in the provided (trajectory | torques).

Return type:

timor.utilities.transformation.Transformation

property tcp_poses: Tuple[timor.utilities.transformation.Transformation, Ellipsis]

Return TCP pose at each time in time_steps.

Return type:

Tuple[timor.utilities.transformation.Transformation, Ellipsis]

tcp_velocity_at(t)

Returns the velocity of the tool center point at time t

Parameters:

t (float) – The time in the solution at which the tcp velocity should be given. Must be one of the time steps in the provided (trajectory | torques).

Returns:

Velocity [m/s]

Return type:

numpy.ndarray

property time_steps: numpy.ndarray

The time steps of the trajectory

Return type:

numpy.ndarray

to_json_data()

Creates jsonable dictionary that serializes this solution.

Returns:

A dictionary that serializes this solution

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()

Convert the solution to a json string

Return type:

str

property torques: numpy.ndarray

The joint torques of the trajectory

Return type:

numpy.ndarray

property trajectory: timor.utilities.trajectory.Trajectory

The heart of a trajectory solution. Describes robot trajectory to follow in order to solve the task

Return type:

timor.utilities.trajectory.Trajectory

property valid: bool

Evaluating lazy variable _lazy

Return type:

bool

visualize(viz=None, fps=30.0, center_view=True)

Visualize a solution trajectory

Parameters:
Return type:

pinocchio.visualize.MeshcatVisualizer