timor.task.Solution =================== .. py:module:: timor.task.Solution Classes ------- .. autoapisummary:: timor.task.Solution.SolutionBase timor.task.Solution.SolutionHeader timor.task.Solution.SolutionTrajectory Module Contents --------------- .. py:class:: SolutionBase(header, task, assembly, cost_function = None, base_pose = Transformation.neutral()) .. autoapi-inheritance-diagram:: timor.task.Solution.SolutionBase :parts: 1 :private-bases: 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. :param header: The header of the solution, containing information about the task it was crafted for and some more distinctive meta-information. :param task: The task the solution was crafted for :param assembly: 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. :param cost_function: The cost function used to evaluate the solution (usually the lower, the better) :param base_pose: The base placement of the assembly .. py:method:: __getstate__() State of solution contains json-able part and the associated task object. .. py:method:: __repr__() Debug representation of a solution. .. py:method:: __setstate__(state) To recreate solution use the state Tuple including the solution json and associated task object. .. py:attribute:: __slots__ :value: () .. py:method:: __str__() String representation of the solution .. py:attribute:: _base_pose :type: timor.utilities.transformation.Transformation .. py:method:: _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 .. py:attribute:: _cost :type: Union[timor.utilities.dtypes.Lazy, bool] .. py:method:: _deduce_package_dir(filepath, content) :staticmethod: Logic for deducing the package directory if the JSONable object is loaded from a file. :param filepath: The path to the file. :param content: 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. .. py:method:: _evaluate_cost() Evaluates the cost function - without checking validity though .. py:attribute:: _module_assembly :type: timor.Module.ModuleAssembly .. py:attribute:: _task :type: timor.task.Task.Task .. py:attribute:: _valid :type: Union[timor.utilities.dtypes.Lazy, bool] .. py:property:: cost :type: float Evaluating lazy variable _cost .. py:attribute:: cost_function :type: timor.task.CostFunctions.CostFunctionBase :value: None .. py:property:: ddq :type: numpy.ndarray :abstractmethod: Joint accelerations of the trajectory .. py:property:: dq :type: numpy.ndarray :abstractmethod: Joint velocities of the trajectory .. py:property:: eef_wrench :type: numpy.ndarray :abstractmethod: End effector wrench [f_x, f_y, f_z, tau_x, tau_y, tau_z] acting on the end-effector (external wrench) .. py:method:: empty() :classmethod: :abstractmethod: Create an empty solution .. py:property:: failed_constraints :type: Tuple[timor.task.Constraints.ConstraintBase, Ellipsis] A tuple of all task-level constraints that were hurt by this solution .. py:property:: failed_goals :type: Tuple[timor.task.Goals.GoalBase, Ellipsis] A tuple of all goals that were not fulfilled by this solution .. py:method:: from_json_data(content, tasks, *args, **kwargs) :staticmethod: Factory method to load a class instance from a dictionary. :param kwargs: * reload_module_DB: If True, the module DB will be reloaded from file (default) otherwise will be cached for faster solution loading. .. py:method:: from_json_file(json_path, tasks) :classmethod: Factory method to load a class instance from a json file. .. py:method:: from_json_string(s, *args, **kwargs) :classmethod: Create from a json string. .. py:method:: get_time_id(t) Get the index of the time step at which the given time is located .. py:attribute:: header :type: SolutionHeader .. py:property:: module_assembly :type: timor.Module.ModuleAssembly The robot / module assembly set to solve this task. .. py:property:: q :type: numpy.ndarray :abstractmethod: Joint positions of the trajectory .. py:property:: robot :type: timor.Robot.RobotBase Provide read access to the robot. This call might be expensive, depending on whether the robot is cached. .. py:property:: t_goals :type: Dict[str, float] :abstractmethod: Mapping from goal IDs to the time at which they were achieved .. py:property:: t_resolution :type: float All goal times can be at most t_resolution apart from the next time step defined in self .. py:property:: task Prevent setting task directly .. py:property:: tau :type: numpy.ndarray Alias for torques .. py:method:: tcp_acceleration_at(t) Returns the velocity of the tool center point at time t :param t: 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). :return: Acceleration [m / s**2] .. py:method:: tcp_pose_at(t) Returns the placement of the tool center point at time t :param t: 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). .. py:method:: tcp_velocity_at(t) Returns the velocity of the tool center point at time t :param t: 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). :return: Velocity [m/s] .. py:property:: time_steps :type: numpy.ndarray :abstractmethod: Time steps of the trajectory .. py:method:: to_json_data() :abstractmethod: Should be implemented by children to dump a solution .. py:method:: to_json_file(save_at, *args, **kwargs) Writes the instance to a json file. :param save_at: File location or folder to write the class to. .. py:method:: to_json_string() Convert the solution to a json string .. py:property:: torques :type: numpy.ndarray :abstractmethod: Torques of the trajectory .. py:property:: valid :type: bool Evaluating lazy variable _lazy .. py:method:: visualize(viz = None, fps = 30.0, center_view = True) Visualize a solution trajectory :param viz: Visualizer to use (default create new) :param fps: fps to use for visualization :param center_view: Whether to try to set camera such that robot / base pose constraint visible .. py:class:: SolutionHeader .. autoapi-inheritance-diagram:: timor.task.Solution.SolutionHeader :parts: 1 :private-bases: The header every solution contains .. py:method:: __delattr__(item) Delete attribute .. py:method:: __post_init__() Post init function that ensures the correct datatypes .. py:method:: __setattr__(key, value) Sets an attribute of this class .. py:method:: _raise_immutable(f) Raises error if objects in this dataclass are to be resetted but the instance is set to immutable .. py:attribute:: affiliation :type: List[str] :value: [''] .. py:method:: asdict() Returns a dictionary representation of this object .. py:attribute:: author :type: List[str] :value: [''] .. py:method:: cast(value, cast_to_type) :staticmethod: Casts the value to the dtype .. py:method:: cast_to_date(value) :staticmethod: Casts the value to a datetime.date object .. py:attribute:: computationTime :type: float :value: -1.0 .. py:attribute:: date :type: datetime.date .. py:attribute:: email :type: List[str] :value: [''] .. py:method:: empty() :classmethod: Creates an empty solution header with a random taskID .. py:method:: fields() :classmethod: Returns the fields of this class .. py:attribute:: notes :type: str :value: '' .. py:attribute:: processorName :type: str :value: '' .. py:attribute:: publication :type: str :value: '' .. py:method:: string_list_factory() :staticmethod: Returns a field with a default factory that returns a list with one empty string .. py:attribute:: tags :type: List[str] :value: [''] .. py:attribute:: taskID :type: str .. py:attribute:: version :type: str :value: '2023' .. py:class:: SolutionTrajectory(trajectory, header, task, assembly, cost_function = None, base_pose = Transformation.neutral()) .. autoapi-inheritance-diagram:: timor.task.Solution.SolutionTrajectory :parts: 1 :private-bases: A solution based on a given trajectory (as opposed to a solution based on torques given) Build a solution based on a given trajectory :param trajectory: The solution trajectory :param header: The header of the solution :param task: The task that the solution belongs to :param assembly: The assembly of modules representing the assembly that performs the given trajectory :param cost_function: The cost function that should be used to evaluate the solution :param base_pose: The base placement of the assembly .. py:method:: __getstate__() State of solution contains json-able part and the associated task object. .. py:method:: __repr__() Debug representation of a solution. .. py:method:: __setstate__(state) To recreate solution use the state Tuple including the solution json and associated task object. .. py:attribute:: __slots__ :value: () .. py:method:: __str__() String representation of the solution .. py:attribute:: _base_pose :type: timor.utilities.transformation.Transformation .. py:method:: _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 .. py:attribute:: _cost :type: Union[timor.utilities.dtypes.Lazy, bool] .. py:method:: _deduce_package_dir(filepath, content) :staticmethod: Logic for deducing the package directory if the JSONable object is loaded from a file. :param filepath: The path to the file. :param content: 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. .. py:method:: _evaluate_cost() Evaluates the cost function - without checking validity though .. py:method:: _get_torques(motor_inertia = True, friction = True) Utility method to calculate joint torques to command based on the trajectory. :param motor_inertia: Include motor side inertia in torque calculations to compensate them (details see robot.id) :param friction: 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. .. py:attribute:: _link_side_torques .. py:attribute:: _module_assembly :type: timor.Module.ModuleAssembly .. py:attribute:: _task :type: timor.task.Task.Task .. py:attribute:: _torques .. py:attribute:: _valid :type: Union[timor.utilities.dtypes.Lazy, bool] .. py:property:: cost :type: float Evaluating lazy variable _cost .. py:attribute:: cost_function :type: timor.task.CostFunctions.CostFunctionBase :value: None .. py:property:: ddq :type: numpy.ndarray The joint accelerations of the trajectory .. py:property:: dq :type: numpy.ndarray The joint velocities of the trajectory .. py:property:: eef_wrench :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) .. py:method:: empty() :classmethod: Returns an empty solution with an empty trajectory .. py:property:: failed_constraints :type: Tuple[timor.task.Constraints.ConstraintBase, Ellipsis] A tuple of all task-level constraints that were hurt by this solution .. py:property:: failed_goals :type: Tuple[timor.task.Goals.GoalBase, Ellipsis] A tuple of all goals that were not fulfilled by this solution .. py:method:: from_json_data(content, tasks, *args, **kwargs) :staticmethod: Factory method to load a class instance from a dictionary. :param kwargs: * reload_module_DB: If True, the module DB will be reloaded from file (default) otherwise will be cached for faster solution loading. .. py:method:: from_json_file(json_path, tasks) :classmethod: Factory method to load a class instance from a json file. .. py:method:: from_json_string(s, *args, **kwargs) :classmethod: Create from a json string. .. py:method:: get_mechanical_energy(motor_inertia = True, friction = True) Get mechanical energy needed to follow this solution. :param motor_inertia: Include energy to overcome motor side inertia. :param friction: 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. .. py:method:: get_power(motor_inertia = True, friction = True) Get mechanical power used in all joints for each time step. :param motor_inertia: Include power needed to overcome motor side inertia. :param friction: 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. .. py:method:: get_time_id(t) Get the index of the time step at which the given time is located .. py:attribute:: header :type: SolutionHeader .. py: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 .. py:property:: manipulability_indices :type: numpy.ndarray Return manipulability index at each time in time_steps. .. py:property:: module_assembly :type: timor.Module.ModuleAssembly The robot / module assembly set to solve this task. .. py:method:: plot(data = ('q', 'dq', 'ddq'), show_figure = True, subplot_kwargs = None) Plot time series data about this solution :param data: Can be any combination of q, dq, ddq, tau, manipulability, goals, eef_position, eef_rotation :param show_figure: 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. :param subplot_kwargs: Kwargs handed to subplots, including pyplot.figure kwargs (see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html) :return: Figure object containing the desired plots .. py:property:: q :type: numpy.ndarray The joint positions of the trajectory .. py:property:: robot :type: timor.Robot.RobotBase Provide read access to the robot. This call might be expensive, depending on whether the robot is cached. .. py:property:: t_goals :type: Dict[str, float] Mapping from goal ID to the time at which the goal was reached .. py:property:: t_resolution :type: float All goal times can be at most t_resolution apart from the next time step defined in self .. py:property:: task Prevent setting task directly .. py:property:: tau :type: numpy.ndarray Alias for torques .. py:method:: tcp_acceleration_at(t) Returns the velocity of the tool center point at time t :param t: 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). :return: Acceleration [m / s**2] .. py:method:: tcp_pose_at(t) Returns the placement of the tool center point at time t :param t: 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). .. py:property:: tcp_poses :type: Tuple[timor.utilities.transformation.Transformation, Ellipsis] Return TCP pose at each time in time_steps. .. py:method:: tcp_velocity_at(t) Returns the velocity of the tool center point at time t :param t: 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). :return: Velocity [m/s] .. py:property:: time_steps :type: numpy.ndarray The time steps of the trajectory .. py:method:: to_json_data() Creates jsonable dictionary that serializes this solution. :return: A dictionary that serializes this solution .. py:method:: to_json_file(save_at, *args, **kwargs) Writes the instance to a json file. :param save_at: File location or folder to write the class to. .. py:method:: to_json_string() Convert the solution to a json string .. py:property:: torques :type: numpy.ndarray The joint torques of the trajectory .. py:property:: trajectory :type: timor.utilities.trajectory.Trajectory The heart of a trajectory solution. Describes robot trajectory to follow in order to solve the task .. py:property:: valid :type: bool Evaluating lazy variable _lazy .. py:method:: visualize(viz = None, fps = 30.0, center_view = True) Visualize a solution trajectory :param viz: Visualizer to use (default create new) :param fps: fps to use for visualization :param center_view: Whether to try to set camera such that robot / base pose constraint visible