timor.task.Constraints ====================== .. py:module:: timor.task.Constraints Attributes ---------- .. autoapisummary:: timor.task.Constraints.DEFAULT_CONSTRAINTS Classes ------- .. autoapisummary:: timor.task.Constraints.AllGoalsFulfilled timor.task.Constraints.AlwaysTrueConstraint timor.task.Constraints.BasePlacement timor.task.Constraints.CollisionFree timor.task.Constraints.ConstraintBase timor.task.Constraints.CoterminalJointAngles timor.task.Constraints.EndEffector timor.task.Constraints.GoalOrderConstraint timor.task.Constraints.GoalsBySameRobot timor.task.Constraints.JointAngles timor.task.Constraints.JointLimits timor.task.Constraints.RobotConstraint timor.task.Constraints.SelfCollisionFree Module Contents --------------- .. py:class:: AllGoalsFulfilled .. autoapi-inheritance-diagram:: timor.task.Constraints.AllGoalsFulfilled :parts: 1 :private-bases: Checks whether all goals are fulfilled .. py:method:: __eq__(other) Checks if two constraints are equal .. py:method:: __getstate__() Return objects which will be pickled and saved. .. py:method:: __setstate__(state) Take object from parameter and use it to retrieve class state. .. py:attribute:: __slots__ :value: () .. 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:property:: _equality_parameters :type: Tuple[any, Ellipsis] All goals, same constraint .. py:method:: _from_json_data(description, *args, **kwargs) :classmethod: Default constraints can just be constructed from using json fields as constructor inputs. Can be overwritten by children if more complex unpacking needed. .. py:method:: from_json_data(d, *args, **kwargs) :classmethod: Converts a description (string, parsed from json) to a constraint :param d: A description, mapping a constraint name to one or more constraint specifications .. py:method:: from_json_file(filepath, *args, **kwargs) :classmethod: Factory method to load a class instance from a json file. :param filepath: The path to the json file. :param args: Additional arguments to pass to the from_json_data factory method of the specific class. :param kwargs: Additional arguments to pass to the from_json_data factory method of the specific class. .. py:method:: from_json_string(s, *args, **kwargs) :classmethod: Create from a json string. .. py:method:: fulfilled(solution) Check if all goals are fulfilled by this solution. .. py:attribute:: global_only :value: True .. py:method:: is_valid_at(solution, t) This constraint inherently needs access to more than one point in time .. py:method:: is_valid_until(solution, t) Test if all goals can still be fulfilled up to time t. .. py:method:: to_json_data() Return json-able dict of this constraint. .. 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() Return the json string representation. .. py:method:: visualize(viz, scale = 1.0, show_name = False) Visualize the constraint in an existing meshcat window. If possible a constraint should have a visualization. The default is no visualization and should be overwritten if a visualization is possible. :param viz: A meshcat visualizer as defined in pinocchio :param scale: The visualization method assumes the robot size is ~1-2m maximum reach. Use the scale factor to adapt for significantly different sizes of robots and/or obstacles. :param show_name: If True, the name of the constraint is shown in the visualization .. py:class:: AlwaysTrueConstraint .. autoapi-inheritance-diagram:: timor.task.Constraints.AlwaysTrueConstraint :parts: 1 :private-bases: This constraint is always true and can be used for constraints ensured by the software library before evaluation. .. py:method:: __eq__(other) Checks if two constraints are equal .. py:method:: __getstate__() Return objects which will be pickled and saved. .. py:method:: __setstate__(state) Take object from parameter and use it to retrieve class state. .. py:attribute:: __slots__ :value: () .. py:method:: _check_single_state(task, robot, q, dq, ddq) As the name says, this constraint is always valid .. 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:property:: _equality_parameters :type: Tuple[any, Ellipsis] Two always true constraints are always equal .. py:method:: _from_json_data(description, *args, **kwargs) :classmethod: Default constraints can just be constructed from using json fields as constructor inputs. Can be overwritten by children if more complex unpacking needed. .. py:method:: check_single_state(task, robot, q, dq, ddq = None) Checks whether the constraint is fulfilled for a single state of the robot. :param task: The task that is being solved -- if not provided, an empty task will be generated. :param robot: The robot that is used to solve the task. :param q: The joint positions of the robot. :param dq: The joint velocities of the robot. :param ddq: The joint accelerations of the robot. .. py:method:: from_json_data(d, *args, **kwargs) :classmethod: Converts a description (string, parsed from json) to a constraint :param d: A description, mapping a constraint name to one or more constraint specifications .. py:method:: from_json_file(filepath, *args, **kwargs) :classmethod: Factory method to load a class instance from a json file. :param filepath: The path to the json file. :param args: Additional arguments to pass to the from_json_data factory method of the specific class. :param kwargs: Additional arguments to pass to the from_json_data factory method of the specific class. .. py:method:: from_json_string(s, *args, **kwargs) :classmethod: Create from a json string. .. py:method:: fulfilled(solution) As the name says, this constraint is always valid .. py:attribute:: global_only :type: bool :value: False .. py:method:: is_valid_at(solution, t) As the name says, this constraint is always valid .. py:method:: is_valid_until(solution, t) As the name says, this constraint is always valid .. py:method:: to_json_data() Dumps this constraint to a dictionary .. 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() Return the json string representation. .. py:method:: visualize(viz, scale = 1.0, show_name = False) Visualize the constraint in an existing meshcat window. If possible a constraint should have a visualization. The default is no visualization and should be overwritten if a visualization is possible. :param viz: A meshcat visualizer as defined in pinocchio :param scale: The visualization method assumes the robot size is ~1-2m maximum reach. Use the scale factor to adapt for significantly different sizes of robots and/or obstacles. :param show_name: If True, the name of the constraint is shown in the visualization .. py:class:: BasePlacement(base_pose) .. autoapi-inheritance-diagram:: timor.task.Constraints.BasePlacement :parts: 1 :private-bases: Constraint on the placement of the base coordinate system. :param base_pose: The desired placement of the base coordinate system with arbitrary tolerances. .. py:method:: __eq__(other) Checks if two constraints are equal .. py:method:: __getstate__() Return objects which will be pickled and saved. .. py:method:: __setstate__(state) Take object from parameter and use it to retrieve class state. .. py:attribute:: __slots__ :value: () .. 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:property:: _equality_parameters :type: Tuple[timor.utilities.tolerated_pose.ToleratedPose] Equal if the placements are equal .. py:method:: _from_json_data(description, *args, **kwargs) :classmethod: Create Base placement constraint from json data. .. py:attribute:: base_pose .. py:method:: from_json_data(d, *args, **kwargs) :classmethod: Converts a description (string, parsed from json) to a constraint :param d: A description, mapping a constraint name to one or more constraint specifications .. py:method:: from_json_file(filepath, *args, **kwargs) :classmethod: Factory method to load a class instance from a json file. :param filepath: The path to the json file. :param args: Additional arguments to pass to the from_json_data factory method of the specific class. :param kwargs: Additional arguments to pass to the from_json_data factory method of the specific class. .. py:method:: from_json_string(s, *args, **kwargs) :classmethod: Create from a json string. .. py:method:: fulfilled(solution) Checks whether the center of the base is within the defined tolerance. .. py:attribute:: global_only :value: True .. py:method:: is_valid_at(solution, t) :abstractmethod: We assume the base placement does not change, so this method makes no sense. .. py:method:: is_valid_until(solution, t) Checks that a constraint is valid on a subset of a solution until time t. .. py:method:: sample_random_valid_position() Helps to find a valid base placement, but only works if the tolerances are not too complex. :return: A valid base placement as 4x4 np array .. py:method:: to_json_data() Dumps this constraint to a dictionary .. 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() Return the json string representation. .. py:property:: tolerance Utility wrapper .. py:method:: visualize(viz, scale = 1.0, show_name = False) Visualize the constraint .. py:class:: CollisionFree(safety_margin = 0) .. autoapi-inheritance-diagram:: timor.task.Constraints.CollisionFree :parts: 1 :private-bases: A constraint that checks whether the robot is in collision with the environment or itself. Initialize collision-free constraint :param safety_margin: A safety margin to use for collision checking. The default is 0, which means that the collision checking is done with the exact geometries. For any value larger than 0, the collision checking is done with the inflated geometries. .. py:method:: __eq__(other) Checks if two constraints are equal .. py:method:: __getstate__() Return objects which will be pickled and saved. .. py:method:: __setstate__(state) Take object from parameter and use it to retrieve class state. .. py:attribute:: __slots__ :value: () .. py:method:: _check_single_state(task, robot, q, dq, ddq = None) Checks the constraint for the given task in configuration q. .. 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:property:: _equality_parameters :type: Tuple[any, Ellipsis] Collision-free is equal to itself .. py:method:: _from_json_data(description, *args, **kwargs) :classmethod: Default constraints can just be constructed from using json fields as constructor inputs. Can be overwritten by children if more complex unpacking needed. .. py:method:: check_single_state(task, robot, q, dq, ddq = None) Checks whether the constraint is fulfilled for a single state of the robot. :param task: The task that is being solved -- if not provided, an empty task will be generated. :param robot: The robot that is used to solve the task. :param q: The joint positions of the robot. :param dq: The joint velocities of the robot. :param ddq: The joint accelerations of the robot. .. py:method:: from_json_data(d, *args, **kwargs) :classmethod: Converts a description (string, parsed from json) to a constraint :param d: A description, mapping a constraint name to one or more constraint specifications .. py:method:: from_json_file(filepath, *args, **kwargs) :classmethod: Factory method to load a class instance from a json file. :param filepath: The path to the json file. :param args: Additional arguments to pass to the from_json_data factory method of the specific class. :param kwargs: Additional arguments to pass to the from_json_data factory method of the specific class. .. py:method:: from_json_string(s, *args, **kwargs) :classmethod: Create from a json string. .. py:method:: fulfilled(solution) Returns True iff a constraint is held over the whole solution .. py:attribute:: global_only :type: bool :value: False .. py:method:: is_valid_at(solution, t) Checks whether the robot is in collision with the environment or itself at time t. .. py:method:: is_valid_until(solution, t) Checks that a constraint is valid on a subset of a solution until time t. .. py:attribute:: safety_margin :type: float :value: 0 .. py:method:: to_json_data() Dumps this constraint to a dictionary .. 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() Return the json string representation. .. py:method:: visualize(viz, scale = 1.0, show_name = False) Visualize the constraint in an existing meshcat window. If possible a constraint should have a visualization. The default is no visualization and should be overwritten if a visualization is possible. :param viz: A meshcat visualizer as defined in pinocchio :param scale: The visualization method assumes the robot size is ~1-2m maximum reach. Use the scale factor to adapt for significantly different sizes of robots and/or obstacles. :param show_name: If True, the name of the constraint is shown in the visualization .. py:class:: ConstraintBase .. autoapi-inheritance-diagram:: timor.task.Constraints.ConstraintBase :parts: 1 :private-bases: Base class defining the interface all Constraints must implement. .. py:method:: __eq__(other) Checks if two constraints are equal .. py:method:: __getstate__() Return objects which will be pickled and saved. .. py:method:: __setstate__(state) Take object from parameter and use it to retrieve class state. .. py:attribute:: __slots__ :value: () .. 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:property:: _equality_parameters :type: Tuple[any, Ellipsis] :abstractmethod: Returns the parameters that should be used to check equality of constraints .. py:method:: _from_json_data(description, *args, **kwargs) :classmethod: Default constraints can just be constructed from using json fields as constructor inputs. Can be overwritten by children if more complex unpacking needed. .. py:method:: from_json_data(d, *args, **kwargs) :classmethod: Converts a description (string, parsed from json) to a constraint :param d: A description, mapping a constraint name to one or more constraint specifications .. py:method:: from_json_file(filepath, *args, **kwargs) :classmethod: Factory method to load a class instance from a json file. :param filepath: The path to the json file. :param args: Additional arguments to pass to the from_json_data factory method of the specific class. :param kwargs: Additional arguments to pass to the from_json_data factory method of the specific class. .. py:method:: from_json_string(s, *args, **kwargs) :classmethod: Create from a json string. .. py:method:: fulfilled(solution) Returns True iff a constraint is held over the whole solution .. py:attribute:: global_only :type: bool :value: False .. py:method:: is_valid_at(solution, t) :abstractmethod: Checks that a constraint is not hurt at a specific time t .. py:method:: is_valid_until(solution, t) Checks that a constraint is valid on a subset of a solution until time t. .. py:method:: to_json_data() :abstractmethod: Should be implemented to convert the constraint to a json-serializable dictionary .. 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() Return the json string representation. .. py:method:: visualize(viz, scale = 1.0, show_name = False) Visualize the constraint in an existing meshcat window. If possible a constraint should have a visualization. The default is no visualization and should be overwritten if a visualization is possible. :param viz: A meshcat visualizer as defined in pinocchio :param scale: The visualization method assumes the robot size is ~1-2m maximum reach. Use the scale factor to adapt for significantly different sizes of robots and/or obstacles. :param show_name: If True, the name of the constraint is shown in the visualization .. py:class:: CoterminalJointAngles(limits) .. autoapi-inheritance-diagram:: timor.task.Constraints.CoterminalJointAngles :parts: 1 :private-bases: Constrains a robot can reach a certain pose, being ignorant about full circle rotation deviations This constraint checks whether given joint position, given by joint angles, can be reached in general. It does not check for the exact joint angles but for their coterminal counterpart in the range [-pi, pi) :param limits: A 2xdof array of joint limits: [[lower_limits], [upper_limimts]] .. py:method:: __eq__(other) Checks if two constraints are equal .. py:method:: __getstate__() Return objects which will be pickled and saved. .. py:method:: __setstate__(state) Take object from parameter and use it to retrieve class state. .. py:attribute:: __slots__ :value: () .. py:method:: _check_single_state(task, robot, q, dq, ddq = None) Checks if q is within the joint limits, ignoring all other arguments. .. 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:property:: _equality_parameters :type: Tuple[float, Ellipsis] Flatten the limits to a 1d array .. py:method:: _from_json_data(description, *args, **kwargs) :classmethod: Default constraints can just be constructed from using json fields as constructor inputs. Can be overwritten by children if more complex unpacking needed. .. py:method:: _validate(q) Returns whether q is within the joint limits :param q: Joint angles in the interval [-pi, pi) .. py:method:: check_single_state(task, robot, q, dq, ddq = None) Checks whether the constraint is fulfilled for a single state of the robot. :param task: The task that is being solved -- if not provided, an empty task will be generated. :param robot: The robot that is used to solve the task. :param q: The joint positions of the robot. :param dq: The joint velocities of the robot. :param ddq: The joint accelerations of the robot. .. py:method:: from_json_data(d, *args, **kwargs) :classmethod: Converts a description (string, parsed from json) to a constraint :param d: A description, mapping a constraint name to one or more constraint specifications .. py:method:: from_json_file(filepath, *args, **kwargs) :classmethod: Factory method to load a class instance from a json file. :param filepath: The path to the json file. :param args: Additional arguments to pass to the from_json_data factory method of the specific class. :param kwargs: Additional arguments to pass to the from_json_data factory method of the specific class. .. py:method:: from_json_string(s, *args, **kwargs) :classmethod: Create from a json string. .. py:method:: fulfilled(solution) Returns True iff a constraint is held over the whole solution .. py:attribute:: global_only :type: bool :value: False .. py:method:: is_valid_at(solution, t) Checks whether the given joint angles are within the defined limits at time t. .. py:method:: is_valid_until(solution, t) Checks that a constraint is valid on a subset of a solution until time t. .. py:attribute:: limits .. py:method:: map(q) :staticmethod: Maps the input q to the range [-pi, pi). .. py:method:: to_json_data() :abstractmethod: Dumps this constraint to a dictionary .. 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() Return the json string representation. .. py:method:: visualize(viz, scale = 1.0, show_name = False) Visualize the constraint in an existing meshcat window. If possible a constraint should have a visualization. The default is no visualization and should be overwritten if a visualization is possible. :param viz: A meshcat visualizer as defined in pinocchio :param scale: The visualization method assumes the robot size is ~1-2m maximum reach. Use the scale factor to adapt for significantly different sizes of robots and/or obstacles. :param show_name: If True, the name of the constraint is shown in the visualization .. py:data:: DEFAULT_CONSTRAINTS .. py:class:: EndEffector(*, pose = None, velocity_lim = None, rotation_velocity_lim = None) .. autoapi-inheritance-diagram:: timor.task.Constraints.EndEffector :parts: 1 :private-bases: A constraint that checks whether the end-effector (eef) keeps a certain pose and/or velocity. Initialize eef constraint. :param pose: tolerated pose to keep within (either initialized or serialized in dict) :param velocity_lim: Minimal / Maximal translation velocity :math:`v` of the end-effector in :math:`\frac{m}{s}`; defaults to any allowed :param rotation_velocity_lim: Minimal / Maximal rotation velocity :math:`\omega` of the end-effector in :math:`\frac{rad}{s}`; defaults to any allowed .. py:method:: __eq__(other) Checks if two constraints are equal .. py:method:: __getstate__() Return objects which will be pickled and saved. .. py:method:: __setstate__(state) Take object from parameter and use it to retrieve class state. .. py:attribute:: __slots__ :value: () .. py:method:: _check_single_state(task, robot, q, dq, ddq = None) Can be used to check this constraint against a single, existing robot state. The task is ignored. .. 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:property:: _equality_parameters :type: Tuple[any, Ellipsis] End-effector constraints are equal if they have the same pose and limits .. py:method:: _from_json_data(description, *args, **kwargs) :classmethod: Default constraints can just be constructed from using json fields as constructor inputs. Can be overwritten by children if more complex unpacking needed. .. py:method:: check_single_state(task, robot, q, dq, ddq = None) Checks whether the constraint is fulfilled for a single state of the robot. :param task: The task that is being solved -- if not provided, an empty task will be generated. :param robot: The robot that is used to solve the task. :param q: The joint positions of the robot. :param dq: The joint velocities of the robot. :param ddq: The joint accelerations of the robot. .. py:attribute:: default_velocity_limits .. py:method:: from_json_data(d, *args, **kwargs) :classmethod: Converts a description (string, parsed from json) to a constraint :param d: A description, mapping a constraint name to one or more constraint specifications .. py:method:: from_json_file(filepath, *args, **kwargs) :classmethod: Factory method to load a class instance from a json file. :param filepath: The path to the json file. :param args: Additional arguments to pass to the from_json_data factory method of the specific class. :param kwargs: Additional arguments to pass to the from_json_data factory method of the specific class. .. py:method:: from_json_string(s, *args, **kwargs) :classmethod: Create from a json string. .. py:method:: fulfilled(solution) Returns True iff a constraint is held over the whole solution .. py:attribute:: global_only :type: bool :value: False .. py:method:: is_valid_at(solution, t) Checks whether the robot obeys eef velocity and pose constraints at time t. .. py:method:: is_valid_until(solution, t) Checks that a constraint is valid on a subset of a solution until time t. .. py:attribute:: pose :type: Optional[timor.utilities.tolerated_pose.ToleratedPose] :value: None .. py:attribute:: rotation_velocity_lim :type: Optional[numpy.ndarray] .. py:method:: to_json_data() Dumps this constraint to a dictionary. .. 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() Return the json string representation. .. py:attribute:: velocity_lim :type: Optional[numpy.ndarray] .. py:method:: visualize(viz, scale = 1.0, show_name = False) Visualize the constraint in an existing meshcat window. If possible a constraint should have a visualization. The default is no visualization and should be overwritten if a visualization is possible. :param viz: A meshcat visualizer as defined in pinocchio :param scale: The visualization method assumes the robot size is ~1-2m maximum reach. Use the scale factor to adapt for significantly different sizes of robots and/or obstacles. :param show_name: If True, the name of the constraint is shown in the visualization .. py:class:: GoalOrderConstraint(order) .. autoapi-inheritance-diagram:: timor.task.Constraints.GoalOrderConstraint :parts: 1 :private-bases: Checks that the goals in the task are fulfilled in the right order. :param order: An iterable of goal IDs that defines the order in which they should be achieved .. py:method:: __eq__(other) Checks if two constraints are equal .. py:method:: __getstate__() Return objects which will be pickled and saved. .. py:method:: __setstate__(state) Take object from parameter and use it to retrieve class state. .. py:attribute:: __slots__ :value: () .. 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:property:: _equality_parameters :type: Tuple[str, Ellipsis] Same order, same constraint .. py:method:: _from_json_data(description, *args, **kwargs) :classmethod: Default constraints can just be constructed from using json fields as constructor inputs. Can be overwritten by children if more complex unpacking needed. .. py:method:: from_json_data(d, *args, **kwargs) :classmethod: Converts a description (string, parsed from json) to a constraint :param d: A description, mapping a constraint name to one or more constraint specifications .. py:method:: from_json_file(filepath, *args, **kwargs) :classmethod: Factory method to load a class instance from a json file. :param filepath: The path to the json file. :param args: Additional arguments to pass to the from_json_data factory method of the specific class. :param kwargs: Additional arguments to pass to the from_json_data factory method of the specific class. .. py:method:: from_json_string(s, *args, **kwargs) :classmethod: Create from a json string. .. py:method:: fulfilled(solution) Every goal specified by this constraint must be fulfilled in the right order .. py:attribute:: global_only :value: True .. py:method:: is_valid_at(solution, t) This constraint inherently needs access to more than one point in time .. py:method:: is_valid_until(solution, t) Evaluates the solution up to time t .. py:attribute:: order :type: Tuple[str, Ellipsis] .. py:method:: to_json_data() Dumps this constraint to a dictionary .. 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() Return the json string representation. .. py:method:: visualize(viz, scale = 1.0, show_name = False) Visualize the constraint in an existing meshcat window. If possible a constraint should have a visualization. The default is no visualization and should be overwritten if a visualization is possible. :param viz: A meshcat visualizer as defined in pinocchio :param scale: The visualization method assumes the robot size is ~1-2m maximum reach. Use the scale factor to adapt for significantly different sizes of robots and/or obstacles. :param show_name: If True, the name of the constraint is shown in the visualization .. py:class:: GoalsBySameRobot(goals) .. autoapi-inheritance-diagram:: timor.task.Constraints.GoalsBySameRobot :parts: 1 :private-bases: Checks that all goals specified were achieved by the same robot. :param goals: The goals that need to be achieved by the same robot .. py:method:: __eq__(other) Checks if two constraints are equal .. py:method:: __getstate__() Return objects which will be pickled and saved. .. py:method:: __setstate__(state) Take object from parameter and use it to retrieve class state. .. py:attribute:: __slots__ :value: () .. 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:property:: _equality_parameters :type: Tuple[str, Ellipsis] Same goals, same constraint .. py:method:: _from_json_data(description, *args, **kwargs) :classmethod: Default constraints can just be constructed from using json fields as constructor inputs. Can be overwritten by children if more complex unpacking needed. .. py:method:: from_json_data(d, *args, **kwargs) :classmethod: Converts a description (string, parsed from json) to a constraint :param d: A description, mapping a constraint name to one or more constraint specifications .. py:method:: from_json_file(filepath, *args, **kwargs) :classmethod: Factory method to load a class instance from a json file. :param filepath: The path to the json file. :param args: Additional arguments to pass to the from_json_data factory method of the specific class. :param kwargs: Additional arguments to pass to the from_json_data factory method of the specific class. .. py:method:: from_json_string(s, *args, **kwargs) :classmethod: Create from a json string. .. py:method:: fulfilled(solution) Returns True iff a constraint is held over the whole solution .. py:attribute:: global_only :value: True .. py:attribute:: goals .. py:method:: is_valid_at(solution, t) This constraint inherently needs access to more than one point in time .. py:method:: is_valid_until(solution, t) :abstractmethod: Evaluates the solution up to time t .. py:method:: to_json_data() Dumps this constraint to a dictionary .. 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() Return the json string representation. .. py:method:: visualize(viz, scale = 1.0, show_name = False) Visualize the constraint in an existing meshcat window. If possible a constraint should have a visualization. The default is no visualization and should be overwritten if a visualization is possible. :param viz: A meshcat visualizer as defined in pinocchio :param scale: The visualization method assumes the robot size is ~1-2m maximum reach. Use the scale factor to adapt for significantly different sizes of robots and/or obstacles. :param show_name: If True, the name of the constraint is shown in the visualization .. py:class:: JointAngles(limits) .. autoapi-inheritance-diagram:: timor.task.Constraints.JointAngles :parts: 1 :private-bases: This is a stronger constraint than coterminal joint angles, verifying exact angles against joint limits. limits: A 2xdof array of joint limits: [[lower_limits], [upper_limimts]] .. py:method:: __eq__(other) Checks if two constraints are equal .. py:method:: __getstate__() Return objects which will be pickled and saved. .. py:method:: __setstate__(state) Take object from parameter and use it to retrieve class state. .. py:attribute:: __slots__ :value: () .. py:method:: _check_single_state(task, robot, q, dq, ddq = None) Checks if q is within the joint limits, ignoring all other arguments. .. 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:property:: _equality_parameters :type: Tuple[float, Ellipsis] Flatten the limits to a 1d array .. py:method:: _from_json_data(description, *args, **kwargs) :classmethod: Default constraints can just be constructed from using json fields as constructor inputs. Can be overwritten by children if more complex unpacking needed. .. py:method:: _validate(q) Returns whether q is within the joint limits :param q: Joint angles in the interval [-pi, pi) .. py:method:: check_single_state(task, robot, q, dq, ddq = None) Checks whether the constraint is fulfilled for a single state of the robot. :param task: The task that is being solved -- if not provided, an empty task will be generated. :param robot: The robot that is used to solve the task. :param q: The joint positions of the robot. :param dq: The joint velocities of the robot. :param ddq: The joint accelerations of the robot. .. py:method:: from_json_data(d, *args, **kwargs) :classmethod: Converts a description (string, parsed from json) to a constraint :param d: A description, mapping a constraint name to one or more constraint specifications .. py:method:: from_json_file(filepath, *args, **kwargs) :classmethod: Factory method to load a class instance from a json file. :param filepath: The path to the json file. :param args: Additional arguments to pass to the from_json_data factory method of the specific class. :param kwargs: Additional arguments to pass to the from_json_data factory method of the specific class. .. py:method:: from_json_string(s, *args, **kwargs) :classmethod: Create from a json string. .. py:method:: fulfilled(solution) Returns True iff a constraint is held over the whole solution .. py:attribute:: global_only :type: bool :value: False .. py:method:: is_valid_at(solution, t) Checks whether the given joint angles are within the defined limits at time t. .. py:method:: is_valid_until(solution, t) Checks that a constraint is valid on a subset of a solution until time t. .. py:attribute:: limits .. py:method:: map(q) :staticmethod: Overwrites the mapping to the interval [-pi, pi) s.t. the original angles are checked. .. py:method:: to_json_data() :abstractmethod: Dumps this constraint to a dictionary .. 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() Return the json string representation. .. py:method:: visualize(viz, scale = 1.0, show_name = False) Visualize the constraint in an existing meshcat window. If possible a constraint should have a visualization. The default is no visualization and should be overwritten if a visualization is possible. :param viz: A meshcat visualizer as defined in pinocchio :param scale: The visualization method assumes the robot size is ~1-2m maximum reach. Use the scale factor to adapt for significantly different sizes of robots and/or obstacles. :param show_name: If True, the name of the constraint is shown in the visualization .. py:class:: JointLimits(parts) .. autoapi-inheritance-diagram:: timor.task.Constraints.JointLimits :parts: 1 :private-bases: Holds constraints on the robots (hardware) limits like position, velocity, torques, etc. Builds the joint limit constraint :param parts: Can be any of (q, dq, ddq, tau) and define what is constrained .. py:method:: __eq__(other) Checks if two constraints are equal .. py:method:: __getstate__() Return objects which will be pickled and saved. .. py:method:: __setstate__(state) Take object from parameter and use it to retrieve class state. .. py:attribute:: __slots__ :value: () .. py:method:: _check_single_state(task, robot, q, dq, ddq = None) Checks whether the limits of the robot are held. As a single state doesn't have a solution reference, this check assumes no external influences. :param task: The task is not being used in this check. :param robot: The robot for which the limits are checked. :param q: The joint positions of the robot. :param dq: The joint velocities of the robot. :param ddq: The joint accelerations of the robot. .. 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:property:: _equality_parameters :type: Tuple[str, Ellipsis] Same parts, same constraint .. py:method:: _from_json_data(description, *args, **kwargs) :classmethod: Default constraints can just be constructed from using json fields as constructor inputs. Can be overwritten by children if more complex unpacking needed. .. py:attribute:: _robot_attributs :value: ('joint_limits', 'joint_velocity_limits', 'joint_acceleration_limits', 'joint_torque_limits') .. py:method:: check_single_state(task, robot, q, dq, ddq = None) Checks whether the constraint is fulfilled for a single state of the robot. :param task: The task that is being solved -- if not provided, an empty task will be generated. :param robot: The robot that is used to solve the task. :param q: The joint positions of the robot. :param dq: The joint velocities of the robot. :param ddq: The joint accelerations of the robot. .. py:attribute:: ddq .. py:attribute:: dq .. py:method:: from_json_data(d, *args, **kwargs) :classmethod: Converts a description (string, parsed from json) to a constraint :param d: A description, mapping a constraint name to one or more constraint specifications .. py:method:: from_json_file(filepath, *args, **kwargs) :classmethod: Factory method to load a class instance from a json file. :param filepath: The path to the json file. :param args: Additional arguments to pass to the from_json_data factory method of the specific class. :param kwargs: Additional arguments to pass to the from_json_data factory method of the specific class. .. py:method:: from_json_string(s, *args, **kwargs) :classmethod: Create from a json string. .. py:method:: fulfilled(solution) Returns True iff a constraint is held over the whole solution .. py:attribute:: global_only :type: bool :value: False .. py:method:: is_valid_at(solution, t) Evaluates the solution at time t .. py:method:: is_valid_until(solution, t) Evaluates the solution up to time t .. py:attribute:: q .. py:attribute:: robot_limit_types :value: ('q', 'dq', 'ddq', 'tau') .. py:attribute:: tau .. py:method:: to_json_data() Dumps this constraint to a dictionary .. 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() Return the json string representation. .. py:method:: visualize(viz, scale = 1.0, show_name = False) Visualize the constraint in an existing meshcat window. If possible a constraint should have a visualization. The default is no visualization and should be overwritten if a visualization is possible. :param viz: A meshcat visualizer as defined in pinocchio :param scale: The visualization method assumes the robot size is ~1-2m maximum reach. Use the scale factor to adapt for significantly different sizes of robots and/or obstacles. :param show_name: If True, the name of the constraint is shown in the visualization .. py:class:: RobotConstraint .. autoapi-inheritance-diagram:: timor.task.Constraints.RobotConstraint :parts: 1 :private-bases: This is a mixin for constraints that can be verified given a task, a robot, and its joint positions and velocities. They are not necessarily to be used only in tasks, but can be used to check whether a robot is in a valid state for downstream tasks like the computation of the inverse kinematics. .. py:attribute:: __slots__ :value: () .. py:method:: _check_single_state(task, robot, q, dq, ddq = None) :abstractmethod: This method needs to be implemented by all constraints that inherit from this mixin. .. py:method:: check_single_state(task, robot, q, dq, ddq = None) Checks whether the constraint is fulfilled for a single state of the robot. :param task: The task that is being solved -- if not provided, an empty task will be generated. :param robot: The robot that is used to solve the task. :param q: The joint positions of the robot. :param dq: The joint velocities of the robot. :param ddq: The joint accelerations of the robot. .. py:class:: SelfCollisionFree(safety_margin = 0) .. autoapi-inheritance-diagram:: timor.task.Constraints.SelfCollisionFree :parts: 1 :private-bases: A constraint that checks whether the robot is in collision with itself. Initialize self-collision-free constraint :param safety_margin: For self collisions, this parameter is currently ignored. .. py:method:: __eq__(other) Checks if two constraints are equal .. py:method:: __getstate__() Return objects which will be pickled and saved. .. py:method:: __setstate__(state) Take object from parameter and use it to retrieve class state. .. py:attribute:: __slots__ :value: () .. py:method:: _check_single_state(task, robot, q, dq, ddq = None) Checks the constraint for the given task in configuration q. .. 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:property:: _equality_parameters :type: Tuple[any, Ellipsis] Collision-free is equal to itself .. py:method:: _from_json_data(description, *args, **kwargs) :classmethod: Default constraints can just be constructed from using json fields as constructor inputs. Can be overwritten by children if more complex unpacking needed. .. py:method:: check_single_state(task, robot, q, dq, ddq = None) Checks whether the constraint is fulfilled for a single state of the robot. :param task: The task that is being solved -- if not provided, an empty task will be generated. :param robot: The robot that is used to solve the task. :param q: The joint positions of the robot. :param dq: The joint velocities of the robot. :param ddq: The joint accelerations of the robot. .. py:method:: from_json_data(d, *args, **kwargs) :classmethod: Converts a description (string, parsed from json) to a constraint :param d: A description, mapping a constraint name to one or more constraint specifications .. py:method:: from_json_file(filepath, *args, **kwargs) :classmethod: Factory method to load a class instance from a json file. :param filepath: The path to the json file. :param args: Additional arguments to pass to the from_json_data factory method of the specific class. :param kwargs: Additional arguments to pass to the from_json_data factory method of the specific class. .. py:method:: from_json_string(s, *args, **kwargs) :classmethod: Create from a json string. .. py:method:: fulfilled(solution) Returns True iff a constraint is held over the whole solution .. py:attribute:: global_only :type: bool :value: False .. py:method:: is_valid_at(solution, t) Checks whether the robot is in collision with the environment or itself at time t. .. py:method:: is_valid_until(solution, t) Checks that a constraint is valid on a subset of a solution until time t. .. py:attribute:: safety_margin :type: float :value: 0 .. py:method:: to_json_data() Dumps this constraint to a dictionary .. 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() Return the json string representation. .. py:method:: visualize(viz, scale = 1.0, show_name = False) Visualize the constraint in an existing meshcat window. If possible a constraint should have a visualization. The default is no visualization and should be overwritten if a visualization is possible. :param viz: A meshcat visualizer as defined in pinocchio :param scale: The visualization method assumes the robot size is ~1-2m maximum reach. Use the scale factor to adapt for significantly different sizes of robots and/or obstacles. :param show_name: If True, the name of the constraint is shown in the visualization