timor.task.Solution
Classes
A solution describes an assembly and a trajectory it follows in order to reach all goals in a task |
|
The header every solution contains |
|
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())

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:
- _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:
- _module_assembly: timor.Module.ModuleAssembly
- _task: timor.task.Task.Task
- _valid: timor.utilities.dtypes.Lazy | bool
- cost_function: timor.task.CostFunctions.CostFunctionBase = None
- property ddq: numpy.ndarray
- Abstractmethod:
- Return type:
Joint accelerations of the trajectory
- property dq: numpy.ndarray
- Abstractmethod:
- Return type:
Joint velocities of the trajectory
- property eef_wrench: numpy.ndarray
- Abstractmethod:
- Return type:
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:
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:
- classmethod from_json_file(json_path, tasks)
Factory method to load a class instance from a json file.
- Parameters:
json_path (Union[pathlib.Path, str])
tasks (Dict[str, timor.task.Task.Task])
- Return type:
- get_time_id(t)
Get the index of the time step at which the given time is located
- header: SolutionHeader
- property module_assembly: timor.Module.ModuleAssembly
The robot / module assembly set to solve this task.
- Return type:
- property q: numpy.ndarray
- Abstractmethod:
- Return type:
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:
- property t_resolution: float
All goal times can be at most t_resolution apart from the next time step defined in self
- Return type:
- property task
Prevent setting task directly
- property tau: numpy.ndarray
Alias for torques
- Return type:
- 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:
- 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:
- 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:
- property time_steps: numpy.ndarray
- Abstractmethod:
- Return type:
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.
- property torques: numpy.ndarray
- Abstractmethod:
- Return type:
Torques of the trajectory
- visualize(viz=None, fps=30.0, center_view=True)
Visualize a solution trajectory
- Parameters:
viz (Union[pinocchio.visualize.MeshcatVisualizer, timor.utilities.visualization.MeshcatVisualizerWithAnimation]) – Visualizer to use (default create new)
fps (float) – fps to use for visualization
center_view (bool) – Whether to try to set camera such that robot / base pose constraint visible
- Return type:
pinocchio.visualize.MeshcatVisualizer
- class 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
- 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:
- date: datetime.date
- classmethod empty()
Creates an empty solution header with a random taskID
- Return type:
- static string_list_factory()
Returns a field with a default factory that returns a list with one empty string
- Return type:
dataclasses.field
- class timor.task.Solution.SolutionTrajectory(trajectory, header, task, assembly, cost_function=None, base_pose=Transformation.neutral())

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:
trajectory (timor.utilities.trajectory.Trajectory) – The solution trajectory
header (Union[Dict, SolutionHeader]) – The header of the solution
task (timor.task.Task.Task) – The task that the solution belongs to
assembly (Union[timor.Module.ModuleAssembly, timor.Robot.RobotBase]) – The assembly of modules representing the assembly that performs the given trajectory
cost_function (Optional[timor.task.CostFunctions.CostFunctionBase]) – The cost function that should be used to evaluate the solution
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:
- _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:
- _get_torques(motor_inertia=True, friction=True)
Utility method to calculate joint torques to command based on the trajectory.
- Parameters:
- 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:
- _link_side_torques
- _module_assembly: timor.Module.ModuleAssembly
- _task: timor.task.Task.Task
- _torques
- _valid: timor.utilities.dtypes.Lazy | bool
- cost_function: timor.task.CostFunctions.CostFunctionBase = None
- property ddq: numpy.ndarray
The joint accelerations of the trajectory
- Return type:
- property dq: numpy.ndarray
The joint velocities of the trajectory
- Return type:
- 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:
- classmethod empty()
Returns an empty solution with an empty trajectory
- Return type:
- 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:
- classmethod from_json_file(json_path, tasks)
Factory method to load a class instance from a json file.
- Parameters:
json_path (Union[pathlib.Path, str])
tasks (Dict[str, timor.task.Task.Task])
- Return type:
- get_mechanical_energy(motor_inertia=True, friction=True)
Get mechanical energy needed to follow this solution.
- Parameters:
- 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:
- 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
- header: SolutionHeader
- property link_side_torques
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:
- property module_assembly: timor.Module.ModuleAssembly
The robot / module assembly set to solve this task.
- Return type:
- 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:
- 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:
- property t_resolution: float
All goal times can be at most t_resolution apart from the next time step defined in self
- Return type:
- property task
Prevent setting task directly
- property tau: numpy.ndarray
Alias for torques
- Return type:
- 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:
- 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:
- 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:
- property time_steps: numpy.ndarray
The time steps of the trajectory
- Return type:
- 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.
- property torques: numpy.ndarray
The joint torques of the trajectory
- Return type:
- 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:
- visualize(viz=None, fps=30.0, center_view=True)
Visualize a solution trajectory
- Parameters:
viz (Union[pinocchio.visualize.MeshcatVisualizer, timor.utilities.visualization.MeshcatVisualizerWithAnimation]) – Visualizer to use (default create new)
fps (float) – fps to use for visualization
center_view (bool) – Whether to try to set camera such that robot / base pose constraint visible
- Return type:
pinocchio.visualize.MeshcatVisualizer