pycram.datastructures.world_entity

Contents

pycram.datastructures.world_entity#

Classes#

StateEntity

The StateEntity class is used to store the state of an object or the physics simulator. This is used to save and

WorldEntity

A class that represents an entity of the world, such as an object or a link.

PhysicalBody

A class that represents a physical body in the world that has some related physical properties.

Module Contents#

class pycram.datastructures.world_entity.StateEntity#

The StateEntity class is used to store the state of an object or the physics simulator. This is used to save and restore the state of the World.

SAVED_FILE_PREFIX = 'pycram_saved_state_'#
_saved_states: typing_extensions.Dict[int, pycram.datastructures.dataclasses.State]#
property saved_states: typing_extensions.Dict[int, pycram.datastructures.dataclasses.State]#
Returns:

the saved states of this entity.

save_state(state_id: int, save_dir: typing_extensions.Optional[str] = None) int#

Saves the state of this entity with the given state id.

Parameters:
  • state_id – The unique id of the state.

  • save_dir – The directory where the file should be saved.

save_state_to_file(file_path: str, state_id: typing_extensions.Optional[int] = None)#

Saves the state of this entity to a file.

Parameters:
  • file_path – The path to the file.

  • state_id – The unique id of the state if saving a specific state not the current state.

restore_state_from_file(save_dir: str, state_id: int) None#

Restores the state of this entity from a file.

Parameters:
  • save_dir – The directory where the file is saved.

  • state_id – The unique id of the state.

get_saved_file_path_of_state(save_dir: str, state_id: int) str#

Gets the path of the file that stores the state with the given id.

Parameters:
  • save_dir – The directory where the file should be saved.

  • state_id – The unique id of the state.

Returns:

The name of the file that stores the state with the given id.

property current_state: pycram.datastructures.dataclasses.State#
Abstractmethod:

Returns:

The current state of this entity.

restore_state(state_id: int, saved_file_dir: typing_extensions.Optional[str] = None) None#

Restores the state of this entity from a saved state using the given state id.

Parameters:
  • state_id – The unique id of the state.

  • saved_file_dir – The directory where the file is saved.

remove_saved_states() None#

Removes all saved states of this entity.

class pycram.datastructures.world_entity.WorldEntity(_id: int, world: pycram.datastructures.world.World, concept: typing_extensions.Type[pycrap.ontologies.PhysicalObject] = PhysicalObject, parse_name: bool = True)#

Bases: StateEntity, pycram.datastructures.mixins.HasConcept

A class that represents an entity of the world, such as an object or a link.

id#
world: pycram.datastructures.world.World#
reset_concepts()#

Reset the concepts of this entity.

property name: str#
Abstractmethod:

Returns:

The name of this body.

property parent_entity: typing_extensions.Optional[WorldEntity]#
Abstractmethod:

Returns:

The parent entity of this entity, if it has one.

__eq__(other: WorldEntity) bool#

Check if this body is equal to another body.

__hash__() int#
class pycram.datastructures.world_entity.PhysicalBody(body_id: int, world: pycram.datastructures.world.World, concept: typing_extensions.Type[pycrap.ontologies.PhysicalObject] = PhysicalObject, parse_name: bool = True)#

Bases: WorldEntity

A class that represents a physical body in the world that has some related physical properties.

local_transformer#
_is_translating: typing_extensions.Optional[bool] = None#
_is_rotating: typing_extensions.Optional[bool] = None#
_velocity: typing_extensions.Optional[typing_extensions.List[float]] = None#
ontology_lock: threading.RLock#
updated_containment_of_parts: bool = False#
latest_known_parts: typing_extensions.Dict[str, PhysicalBody]#
reset_concepts()#

Reset the concepts of this entity.

property is_an_environment: bool#

Check if the object is of type environment.

Returns:

True if the object is of type environment, False otherwise.

property is_a_robot: bool#

Check if the object is a robot. TODO: Check if this is a the correct filter :return: True if the object is a robot, False otherwise.

property parts: typing_extensions.Dict[str, PhysicalBody]#
Abstractmethod:

Returns:

The parts of this body as a dictionary mapping the part name to the part.

update_containment(excluded_bodies: typing_extensions.Optional[typing_extensions.List[PhysicalBody]] = None, candidate_selection_method: pycram.datastructures.enums.AdjacentBodyMethod = AdjacentBodyMethod.ClosestPoints, max_distance: float = 0.5) None#
Update the containment of the object by checking if it is contained in other bodies,

excluding the given excluded bodies.

Parameters:
  • excluded_bodies – The bodies that should be excluded from the containment check.

  • candidate_selection_method – The method to select the candidates for the containment check.

  • max_distance – The maximum distance from this body to other bodies to consider a body as a candidate.

get_adjacent_bodies_using_closest_points(max_distance: float = 0.5) typing_extensions.List[PhysicalBody]#

Get the adjacent bodies of the body using the closest points between the bodies.

Parameters:

max_distance – The maximum distance to consider a body as adjacent.

Returns:

The bodies that are adjacent to this body if any.

get_adjacent_bodies_using_rays(max_distance: float = 0.5) typing_extensions.List[PhysicalBody]#
Cast rays in the 6 rays in all directions (+x, -x, +y, -y, +z, and -z directions) to find the adjacent bodies

of the body.

Parameters:

max_distance – The max distance that the rays can travel.

Returns:

The bodies that are adjacent to this body if any.

cast_rays_in_all_directions(max_distance: float = 0.5) typing_extensions.List[pycram.datastructures.dataclasses.RayResult]#

Get the rays in all 6 directions (+x, -x, +y, -y, +z, and -z directions).

Parameters:

max_distance – The maximum distance the rays can travel.

Returns:

The rays in all 6 directions.

static get_axis_rays(origin: typing_extensions.List[float], min_val: float, max_val: float, idx: int, max_distance: float = 0.5) typing_extensions.Tuple[typing_extensions.List[typing_extensions.List[float]], typing_extensions.List[typing_extensions.List[float]]]#

Get the rays in the given axis.

Parameters:
  • origin – The origin of the rays.

  • min_val – The start in the -ve direction of the axis.

  • max_val – The start in the +ve direction of the axis.

  • idx – The index of the direction/axis.

  • max_distance – The maximum distance the rays can travel.

contains_body(body: PhysicalBody) bool#

Check if this body contains another body.

Parameters:

body – The physical body to check if it is contained by this body.

Returns:

True if the body contains the other body, otherwise False.

property contained_bodies: typing_extensions.List[PhysicalBody]#
Returns:

True if the object contains the other object, otherwise False.

abstract get_axis_aligned_bounding_box() pycram.datastructures.dataclasses.AxisAlignedBoundingBox#
Returns:

The axis-aligned bounding box of this body.

abstract get_rotated_bounding_box() pycram.datastructures.dataclasses.RotatedBoundingBox#
Returns:

The rotated bounding box of this body.

_plot_convex_hull()#

Plot the convex hull of the geometry.

abstract get_convex_hull() trimesh.parent.Geometry3D#
Returns:

The convex hull of this body.

property body_state: pycram.datastructures.dataclasses.PhysicalBodyState#
property velocity: typing_extensions.Optional[typing_extensions.List[float]]#
property is_translating: typing_extensions.Optional[bool]#
property is_rotating: typing_extensions.Optional[bool]#
property position: pycram.datastructures.pose.Point#
Returns:

A Point object containing the position of the link relative to the world frame.

property orientation: pycram.datastructures.pose.GeoQuaternion#
Returns:

A Quaternion object containing the orientation of the link relative to the world frame.

property pose_as_list: typing_extensions.List[typing_extensions.List[float]]#
Returns:

A list containing the position and orientation of the link relative to the world frame.

property transform: pycram.datastructures.pose.TransformStamped#

The transform of this entity.

Returns:

The transform of this entity.

update_transform(transform_time: typing_extensions.Optional[pycram.ros.Time] = None) None#

Update the transformation of this link at the given time.

Parameters:

transform_time – The time at which the transformation should be updated.

property pose: pycram.datastructures.pose.PoseStamped#
Abstractmethod:

Returns:

A Pose object containing the pose of the link relative to the world frame.

property tf_frame: str#
Abstractmethod:

The tf frame of this entity.

Returns:

The tf frame of this entity.

property contact_points: pycram.datastructures.dataclasses.ContactPointsList#
Returns:

The contact points of this body with other physical bodies.

get_contact_points_with_body(body: PhysicalBody) pycram.datastructures.dataclasses.ContactPointsList#
Parameters:

body – The body to get the contact points with.

Returns:

The contact points of this body with the given body.

closest_points(max_distance: float) pycram.datastructures.dataclasses.ClosestPointsList#
Parameters:

max_distance – The maximum distance to consider a body as close, only points closer than or equal to this distance will be returned.

Returns:

The closest points of this body with other physical bodies within the given maximum distance.

get_closest_points_with_body(body: PhysicalBody, max_distance: float) pycram.datastructures.dataclasses.ClosestPointsList#
Parameters:
  • body – The body to get the points with.

  • max_distance – The maximum distance to consider a body as close, only points closer than or equal to this distance will be returned.

Returns:

The closest points of this body with the given body within the given maximum distance.

property is_moving: typing_extensions.Optional[bool]#
Returns:

True if this body is moving, False if not, and None if not known.

property is_stationary: typing_extensions.Optional[bool]#
Returns:

True if this body is stationary, False otherwise.

property color: typing_extensions.Union[pycram.datastructures.dataclasses.Color, typing_extensions.Dict[str, pycram.datastructures.dataclasses.Color]]#
Abstractmethod:

Returns:

A Color object containing the rgba_color of this body or a dictionary if the body is articulated.

set_color(color: pycram.datastructures.dataclasses.Color) None#

Set the color of this body, could be rgb or rgba.

Parameters:

color – The color as a list of floats, either rgb or rgba.

get_preferred_grasp_alignment() pycram.datastructures.grasp.PreferredGraspAlignment#

Determines the preferred grasp alignment for an object based on its type. This includes the preferred axis, whether grasping from the top is preferred, and whether horizontal alignment (90° rotation around X) is preferred.

Returns:

The preferred grasp alignment for the object.

calculate_grasp_descriptions(robot: pycram.world_concepts.world_object.Object) typing_extensions.List[pycram.datastructures.pose.GraspDescription]#

Calculates the grasp configurations of an object relative to the robot based on orientation and position.

This method determines the possible grasp configurations (side and top/bottom faces) of the object, taking into account the object’s orientation, position, and whether horizontal alignment is preferred.

Parameters:

robot – The robot for which the grasp configurations are being calculated.

Returns:

A sorted list of GraspDescription instances representing all grasp permutations.

get_grasp_pose(end_effector, grasp: pycram.datastructures.pose.GraspDescription) Pose#

Translates the grasp pose of the object using the desired grasp description and object knowledge. Leaves the orientation untouched. Returns the translated grasp pose.

Parameters:
  • end_effector – The end effector that will be used to grasp the object.

  • grasp – The desired grasp description.

Returns:

The grasp pose of the object.

get_approach_offset() float#
Returns:

The pre-grasp offset of the object. It is the largest dimension of the object divided by 2.