pycram.datastructures.world

Contents

pycram.datastructures.world#

Classes#

World

The World Class represents the physics Simulation and belief state, it is the main interface for reasoning about

UseProspectionWorld

An environment for using the prospection world, while in this environment the current_world

WorldSync

Synchronizes the state between the World and its prospection world.

Module Contents#

class pycram.datastructures.world.World(mode: pycram.datastructures.enums.WorldMode = WorldMode.DIRECT, is_prospection: bool = False, clear_cache: bool = False, id_: int = -1)#

Bases: pycram.datastructures.world_entity.WorldEntity, abc.ABC

The World Class represents the physics Simulation and belief state, it is the main interface for reasoning about the World. This is implemented as a singleton, the current World can be accessed via the static variable current_world which is managed by the World class itself.

conf: typing_extensions.Type[pycram.config.world_conf.WorldConfig]#

The configurations of the world, the default configurations are defined in world_conf.py in the config folder.

current_world: typing_extensions.Optional[World] = None#

Global reference to the currently used World, usually this is the graphical one. However, if you are inside a UseProspectionWorld() environment the current_world points to the prospection world. In this way you can comfortably use the current_world, which should point towards the World used at the moment.

robot: typing_extensions.Optional[pycram.world_concepts.world_object.Object] = None#
Global reference to the spawned Object that represents the robot. The robot is identified by checking the name in

the URDF with the name of the URDF on the parameter server.

environment: typing_extensions.Optional[pycram.world_concepts.world_object.Object] = None#
Global reference to the spawned Object that represents the environment. The environment is identified by checking the name in

the URDF with the name of the URDF on the parameter server.

cache_manager: pycram.cache_manager.CacheManager#

Global reference for the cache manager, this is used to cache the description files of the robot and the objects.

ontology: typing_extensions.Optional[pycrap.ontology_wrapper.OntologyWrapper] = None#

The ontology of this world.

is_prospection_world: bool = False#
latest_state_id: typing_extensions.Optional[int] = None#
object_lock: threading.Lock#
objects: typing_extensions.List[pycram.world_concepts.world_object.Object] = []#
local_transformer#
mode: pycram.datastructures.enums.WorldMode#
coll_callbacks: typing_extensions.Dict[typing_extensions.Tuple[pycram.world_concepts.world_object.Object, pycram.world_concepts.world_object.Object], pycram.datastructures.dataclasses.CollisionCallbacks]#
_current_state: typing_extensions.Optional[pycram.datastructures.dataclasses.WorldState] = None#
original_state_id = None#
on_add_object_callbacks: typing_extensions.List[typing_extensions.Callable[[pycram.world_concepts.world_object.Object], None]] = []#
_set_world_rules()#

Create the rules for the world.

property rules: typing_extensions.List[pycrap.ontologies.crax.rules.CRAXRule]#

Return the rules of the world.

static update_containment_for(bodies: typing_extensions.List[pycram.datastructures.world_entity.PhysicalBody], candidate_selection_method: pycram.datastructures.enums.AdjacentBodyMethod = ABM.ClosestPoints) typing_extensions.List[pycram.datastructures.world_entity.PhysicalBody]#

Update the containment for the given bodies by checking if they are contained in other bodies.

Parameters:
  • bodies – The bodies to update the containment for.

  • candidate_selection_method – The method to select the candidate bodies for containment update.

Returns:

The updated bodies.

property parent_entity: typing_extensions.Optional[pycram.datastructures.world_entity.WorldEntity]#

Return the parent entity of this entity, in this case it is None as the World is the top level entity.

property name: str#

Return the name of the world, which is the name of the implementation class (e.g. BulletWorld).

abstract get_body_convex_hull(body: pycram.datastructures.world_entity.PhysicalBody) trimesh.Trimesh#
Parameters:

body – The body object.

Returns:

The convex hull of the body as a Geometry3D object.

add_callback_on_add_object(callback: typing_extensions.Callable[[pycram.world_concepts.world_object.Object], None]) None#

Add a callback that is called when an object is added to the world.

Parameters:

callback – The callback.

remove_callback_on_add_object(callback: typing_extensions.Callable[[pycram.world_concepts.world_object.Object], None]) None#

Remove a callback that is called when an object is added to the world.

Parameters:

callback – The callback.

classmethod get_cache_dir() str#

Return the cache directory.

add_object(obj: pycram.world_concepts.world_object.Object) None#

Add an object to the world.

Parameters:

obj – The object to be added.

invoke_on_add_object_callbacks(obj: pycram.world_concepts.world_object.Object) None#

Invoke the object added callbacks.

Parameters:

obj – The object.

property robot_description: pycram.robot_description.RobotDescription#

Return the current robot description.

property robot_has_actuators: bool#

Return whether the robot has actuators.

get_actuator_for_joint(joint: pycram.description.Joint) str#

Get the actuator name for a given joint.

joint_has_actuator(joint: pycram.description.Joint) bool#

Return whether the joint has an actuator.

property robot_joint_actuators: typing_extensions.Dict[str, str]#

Return the joint actuators of the robot.

abstract check_object_exists(obj: pycram.world_concepts.world_object.Object) bool#

Check if the object exists in the simulator.

Parameters:

obj – The object to check.

Returns:

True if the object is in the world, False otherwise.

abstract _init_world(mode: pycram.datastructures.enums.WorldMode)#

Initialize the physics simulation.

_init_events()#

Initialize dynamic events that can be used to react to changes in the World.

_init_and_sync_prospection_world()#

Initialize the prospection world and the synchronization between the main and the prospection world.

_update_local_transformer_worlds()#

Update the local transformer worlds with the current world and prospection world.

_init_prospection_world()#

Initialize the prospection world, if this is a prospection world itself it will not create another prospection, world, but instead set the prospection world to None, else it will create a prospection world.

_sync_prospection_world()#

Synchronize the prospection world with the main world, this means that every object in the main world will be added to the prospection world and vice versa.

preprocess_object_file_and_get_its_cache_path(path: str, ignore_cached_files: bool, description: pycram.description.ObjectDescription, name: str, scale_mesh: typing_extensions.Optional[float] = None, mesh_transform: typing_extensions.Optional[pycram.datastructures.pose.TransformStamped] = None, color: typing_extensions.Optional[pycram.datastructures.dataclasses.Color] = None) str#

Update the cache directory with the given object.

Parameters:
  • path – The path to the object.

  • ignore_cached_files – If the cached files should be ignored.

  • description – The object description.

  • name – The name of the object.

  • scale_mesh – The scale of the mesh.

  • mesh_transform – The mesh transform to apply to the mesh.

  • color – The color of the object.

Returns:

The path of the cached object.

property simulation_time_step#

The time step of the simulation in seconds.

abstract load_object_and_get_id(path: typing_extensions.Optional[str] = None, pose: typing_extensions.Optional[pycram.datastructures.pose.PoseStamped] = None, obj_type: typing_extensions.Optional[typing_extensions.Type[pycrap.ontologies.PhysicalObject]] = None) int#

Load a description file (e.g. URDF) at the given pose and returns the id of the loaded object.

Parameters:
  • path – The path to the description file, if None the description file is assumed to be already loaded.

  • pose – The pose at which the object should be loaded.

  • obj_type – The type of the object.

Returns:

The id of the loaded object.

abstract load_generic_object_and_get_id(description: pycram.object_descriptors.generic.ObjectDescription, pose: typing_extensions.Optional[pycram.datastructures.pose.PoseStamped] = None) int#

Create a visual and collision box in the simulation and returns the id of the loaded object.

Parameters:
  • description – The object description.

  • pose – The pose at which the object should be loaded.

get_object_names() typing_extensions.List[str]#

Return the names of all objects in the World.

Returns:

A list of object names.

get_object_by_name(name: str) typing_extensions.Optional[pycram.world_concepts.world_object.Object]#

Return the object with the given name. If there is no object with the given name, None is returned.

Parameters:

name – The name of the returned Objects.

Returns:

The object with the given name, if there is one.

get_object_by_type(obj_type: pycrap.ontologies.PhysicalObject) typing_extensions.List[pycram.world_concepts.world_object.Object]#

Return a list of all Objects which have the type ‘obj_type’.

Parameters:

obj_type – The type of the returned Objects.

Returns:

A list of all Objects that have the type ‘obj_type’.

get_object_by_id(obj_id: int) pycram.world_concepts.world_object.Object#

Return the single Object that has the unique id.

Parameters:

obj_id – The unique id for which the Object should be returned.

Returns:

The Object with the id ‘id’.

get_scene_objects() typing_extensions.List[pycram.world_concepts.world_object.Object]#
Returns:

A list of all objects in the world except the robot, floor, and apartment.

remove_visual_object(obj_id: int) bool#

Remove the object with the given id from the world, and saves a new original state for the world.

Parameters:

obj_id – The unique id of the object to be removed.

Returns:

Whether the object was removed successfully.

abstract _remove_visual_object(obj_id: int) bool#

Remove the visual object with the given id from the world, and update the simulator state in the original state.

Parameters:

obj_id – The unique id of the visual object to be removed.

Returns:

Whether the object was removed successfully.

abstract remove_object_from_simulator(obj: pycram.world_concepts.world_object.Object) bool#

Remove an object from the physics simulator.

Parameters:

obj – The object to be removed.

Returns:

Whether the object was removed successfully.

remove_object(obj: pycram.world_concepts.world_object.Object) None#

Remove this object from the current world. For the object to be removed it has to be detached from all objects it is currently attached to. After this is done a call to world remove object is done to remove this Object from the simulation/world.

Parameters:

obj – The object to be removed.

remove_object_from_original_state(obj: pycram.world_concepts.world_object.Object) None#

Remove an object from the original state of the world.

Parameters:

obj – The object to be removed.

add_object_to_original_state(obj: pycram.world_concepts.world_object.Object) None#

Add an object to the original state of the world.

Parameters:

obj – The object to be added.

add_fixed_constraint(parent_link: pycram.description.Link, child_link: pycram.description.Link, child_to_parent_transform: pycram.datastructures.pose.TransformStamped) int#

Create a fixed joint constraint between the given parent and child links, the joint frame will be at the origin of the child link frame, and would have the same orientation as the child link frame.

Parameters:
  • parent_link – The constrained link of the parent object.

  • child_link – The constrained link of the child object.

  • child_to_parent_transform – The transform from the child link frame to the parent link frame.

Returns:

The unique id of the created constraint.

abstract add_constraint(constraint: pycram.world_concepts.constraints.Constraint) int#

Add a constraint between two objects links so that they become attached for example.

Parameters:

constraint – The constraint data used to create the constraint.

abstract remove_constraint(constraint_id) None#

Remove a constraint by its ID.

Parameters:

constraint_id – The unique id of the constraint to be removed.

get_joint_position(joint: pycram.description.Joint) float#

Wrapper for _get_joint_position() that return 0.0 for a joint if it is in the ignore joints list.

abstract _get_joint_position(joint: pycram.description.Joint) float#

Get the position of a joint of an articulated object

Parameters:

joint – The joint to get the position for.

Returns:

The joint position as a float.

abstract get_object_joint_names(obj: pycram.world_concepts.world_object.Object) typing_extensions.List[str]#

Return the names of all joints of this object.

Parameters:

obj – The object.

Returns:

A list of joint names.

Get the pose of a link of an articulated object with respect to the world frame.

Parameters:

link – The link as a AbstractLink object.

Returns:

The pose of the link as a Pose object.

Get the poses of multiple links of an articulated object with respect to the world frame.

Parameters:

links – The links as a list of AbstractLink objects.

Returns:

A dictionary with link names as keys and Pose objects as values.

Get the position of a link of an articulated object with respect to the world frame.

Parameters:

link – The link as a AbstractLink object.

Returns:

The position of the link as a list of floats.

Get the orientation of a link of an articulated object with respect to the world frame.

Parameters:

link – The link as a AbstractLink object.

Returns:

The orientation of the link as a list of floats.

Get the positions of multiple links of an articulated object with respect to the world frame.

Parameters:

links – The links as a list of AbstractLink objects.

Returns:

A dictionary with link names as keys and lists of floats as values.

Get the orientations of multiple links of an articulated object with respect to the world frame.

Parameters:

links – The links as a list of AbstractLink objects.

Returns:

A dictionary with link names as keys and lists of floats as values.

Return the names of all links of this object.

Parameters:

obj – The object.

Returns:

A list of link names.

simulate(seconds: float, real_time: typing_extensions.Optional[bool] = False, func: typing_extensions.Optional[typing_extensions.Callable[[], None]] = None) None#

Simulate Physics in the World for a given amount of seconds. Usually this simulation is faster than real time. By setting the ‘real_time’ parameter this simulation is slowed down such that the simulated time is equal to real time.

Parameters:
  • seconds – The amount of seconds that should be simulated.

  • real_time – If the simulation should happen in real time or faster.

  • func – A function that should be called during the simulation

abstract get_object_pose(obj: pycram.world_concepts.world_object.Object) pycram.datastructures.pose.PoseStamped#

Get the pose of an object in the world frame from the current object pose in the simulator.

Parameters:

obj – The object.

abstract get_multiple_object_poses(objects: typing_extensions.List[pycram.world_concepts.world_object.Object]) typing_extensions.Dict[str, pycram.datastructures.pose.PoseStamped]#

Get the poses of multiple objects in the world frame from the current object poses in the simulator.

Parameters:

objects – The objects.

abstract get_multiple_object_positions(objects: typing_extensions.List[pycram.world_concepts.world_object.Object]) typing_extensions.Dict[str, typing_extensions.List[float]]#

Get the positions of multiple objects in the world frame from the current object poses in the simulator.

Parameters:

objects – The objects.

abstract get_object_position(obj: pycram.world_concepts.world_object.Object) typing_extensions.List[float]#

Get the position of an object in the world frame from the current object pose in the simulator.

Parameters:

obj – The object.

abstract get_multiple_object_orientations(objects: typing_extensions.List[pycram.world_concepts.world_object.Object]) typing_extensions.Dict[str, typing_extensions.List[float]]#

Get the orientations of multiple objects in the world frame from the current object poses in the simulator.

Parameters:

objects – The objects.

abstract get_object_orientation(obj: pycram.world_concepts.world_object.Object) typing_extensions.List[float]#

Get the orientation of an object in the world frame from the current object pose in the simulator.

Parameters:

obj – The object.

property robot_virtual_joints: typing_extensions.List[pycram.description.Joint]#

The virtual joints of the robot.

property robot_virtual_joints_names: typing_extensions.List[str]#

The names of the virtual joints of the robot.

get_robot_mobile_base_joints() pycram.datastructures.dataclasses.VirtualMobileBaseJoints#

Get the mobile base joints of the robot.

Returns:

The mobile base joints.

abstract perform_collision_detection() None#

Check for collisions between all objects in the World and updates the contact points.

get_object_contact_points(obj: pycram.world_concepts.world_object.Object) pycram.datastructures.dataclasses.ContactPointsList#

Same as get_body_contact_points() but with objects instead of any type of bodies.

abstract get_body_contact_points(body: pycram.datastructures.world_entity.PhysicalBody) pycram.datastructures.dataclasses.ContactPointsList#

Return the contact points of a body with all other bodies in the world.

Parameters:

body – The body.

get_contact_points_between_two_objects(obj1: pycram.world_concepts.world_object.Object, obj2: pycram.world_concepts.world_object.Object) pycram.datastructures.dataclasses.ContactPointsList#

Same as get_contact_points_between_two_bodies() but with objects instead of any type of bodies.

abstract get_contact_points_between_two_bodies(body_1: pycram.datastructures.world_entity.PhysicalBody, body_2: pycram.datastructures.world_entity.PhysicalBody) pycram.datastructures.dataclasses.ContactPointsList#

Return a list of contact points between two bodies.

Parameters:
  • body_1 – The first body.

  • body_2 – The second body.

Returns:

A list of all contact points between the two bodies.

get_body_closest_points(body: pycram.datastructures.world_entity.PhysicalBody, max_distance: float) pycram.datastructures.dataclasses.ClosestPointsList#

Return the closest points of this body with all other bodies in the world.

Parameters:
  • body – The body.

  • max_distance – The maximum allowed distance between the points.

Returns:

A list of the closest points.

abstract get_closest_points_between_two_bodies(body_a: pycram.datastructures.world_entity.PhysicalBody, body_b: pycram.datastructures.world_entity.PhysicalBody, max_distance: float) pycram.datastructures.dataclasses.ClosestPointsList#

Return the closest points between two objects.

Parameters:
  • body_a – The first body.

  • body_b – The second body.

  • max_distance – The maximum distance between the points.

Returns:

A list of the closest points.

reset_joint_position(joint: pycram.description.Joint, joint_position: float) bool#

Wrapper around _reset_joint_position() that checks if the joint should be ignored.

abstract _reset_joint_position(joint: pycram.description.Joint, joint_position: float) bool#

Reset the joint position instantly without physics simulation

Note

It is recommended to use the validate_joint_position decorator to validate the joint position for the implementation of this method.

Parameters:
  • joint – The joint to reset the position for.

  • joint_position – The new joint pose.

Returns:

True if the reset was successful, False otherwise

set_multiple_joint_positions(joint_positions: typing_extensions.Dict[pycram.description.Joint, float]) bool#

Wrapper around _set_multiple_joint_positions() that checks if any of the joints should be ignored.

abstract _set_multiple_joint_positions(joint_positions: typing_extensions.Dict[pycram.description.Joint, float]) bool#

Set the positions of multiple joints of an articulated object.

Note

It is recommended to use the validate_multiple_joint_positions decorator to validate the joint positions for the implementation of this method.

Parameters:

joint_positions – A dictionary with joint objects as keys and joint positions as values.

Returns:

True if the set was successful, False otherwise.

get_multiple_joint_positions(joints: typing_extensions.List[pycram.description.Joint]) typing_extensions.Dict[str, float]#

Wrapper around _get_multiple_joint_positions() that checks if any of the joints should be ignored.

abstract _get_multiple_joint_positions(joints: typing_extensions.List[pycram.description.Joint]) typing_extensions.Dict[str, float]#

Get the positions of multiple joints of an articulated object.

Parameters:

joints – The joints as a list of Joint objects.

abstract reset_object_base_pose(obj: pycram.world_concepts.world_object.Object, pose: pycram.datastructures.pose.PoseStamped) bool#

Reset the world position and orientation of the base of the object instantaneously, not through physics simulation. (x,y,z) position vector and (x,y,z,w) quaternion orientation.

Note

It is recommended to use the validate_object_pose decorator to validate the object pose for the implementation of this method.

Parameters:
  • obj – The object.

  • pose – The new pose as a Pose object.

Returns:

True if the reset was successful, False otherwise.

abstract reset_multiple_objects_base_poses(objects: typing_extensions.Dict[pycram.world_concepts.world_object.Object, pycram.datastructures.pose.PoseStamped]) bool#

Reset the world position and orientation of the base of multiple objects instantaneously, not through physics simulation. (x,y,z) position vector and (x,y,z,w) quaternion orientation.

Parameters:

objects – A dictionary with objects as keys and poses as values.

Returns:

True if the reset was successful, False otherwise.

abstract step(func: typing_extensions.Optional[typing_extensions.Callable[[], None]] = None, step_seconds: typing_extensions.Optional[float] = None) None#

Step the world simulation using forward dynamics.

Parameters:
  • func – An optional function to be called during the step.

  • step_seconds – The amount of seconds to step the simulation if None the simulation is stepped by the

simulation time step.

Get the tool frame link of the arm of the robot.

Parameters:

arm – The arm for which the tool frame link should be returned.

Returns:

The tool frame link of the arm.

Change the rgba_color of a link of this object, the rgba_color has to be given as Color object.

Parameters:
  • link – The link which should be colored.

  • rgba_color – The rgba_color as Color object with RGBA values between 0 and 1.

Parameters:

link – The link for which the rgba_color should be returned.

Returns:

The rgba_color as Color object with RGBA values between 0 and 1.

Parameters:

obj – The object

Returns:

The RGBA colors of each link in the object as a dictionary from link name to rgba_color.

abstract get_object_axis_aligned_bounding_box(obj: pycram.world_concepts.world_object.Object) pycram.datastructures.dataclasses.AxisAlignedBoundingBox#
Parameters:

obj – The object for which the bounding box should be returned.

Returns:

the axis aligned bounding box of this object. The return of this method are two points in

world coordinate frame which define a bounding box.

abstract get_object_rotated_bounding_box(obj: pycram.world_concepts.world_object.Object) pycram.datastructures.dataclasses.RotatedBoundingBox#
Parameters:

obj – The object for which the bounding box should be returned.

Returns:

the rotated bounding box of this object. The return of this method are two points in

world coordinate frame which define a bounding box.

Parameters:

link – The link for which the bounding box should be returned.

Returns:

The axis aligned bounding box of the link. The return of this method are two points in

world coordinate frame which define a bounding box.

Parameters:

link – The link for which the bounding box should be returned.

Returns:

The rotated bounding box of the link. The return of this method are two points in

world coordinate frame which define a bounding box.

abstract set_realtime(real_time: bool) None#

Enable the real time simulation of Physics in the World. By default, this is disabled and Physics is only simulated to reason about it.

Parameters:

real_time – Whether the World should simulate Physics in real time.

abstract set_gravity(gravity_vector: typing_extensions.List[float]) None#
Set the gravity that is used in the World. By default, it is set to the gravity on earth ([0, 0, -9.8]).

Gravity is given as a vector in x,y,z. Gravity is only applied while simulating Physic.

Parameters:

gravity_vector – The gravity vector that should be used in the World.

set_robot_if_not_set(robot: pycram.world_concepts.world_object.Object) None#

Set the robot if it is not set yet.

Parameters:

robot – The Object reference to the Object representing the robot.

static set_robot(robot: typing_extensions.Union[pycram.world_concepts.world_object.Object, None]) None#

Set the global variable for the robot Object This should be set on spawning the robot.

Parameters:

robot – The Object reference to the Object representing the robot.

static robot_is_set() bool#

Return whether the robot has been set or not.

Returns:

True if the robot has been set, False otherwise.

exit(remove_saved_states: bool = True) None#

Close the World as well as the prospection world, also collects any other thread that is running.

Parameters:

remove_saved_states – Whether to remove the saved states.

exit_prospection_world_if_exists() None#

Exit the prospection world if it exists.

signal_handler(sig, frame) None#

Signal handler for graceful exit of the world when a signal is received (e.g., SIGINT).

abstract disconnect_from_physics_server() None#

Disconnect the world from the physics server.

reset_current_world() None#

Reset the pose of every object in the World to the pose it was spawned in and sets every joint to 0.

reset_robot() None#

Set the robot class variable to None.

abstract join_threads() None#

Join any running threads. Useful for example when exiting the world.

terminate_world_sync() None#

Terminate the world sync thread.

save_state(state_id: typing_extensions.Optional[int] = None, use_same_id: bool = False, to_file: bool = False) int#

Return the id of the saved state of the World. The saved state contains the states of all the objects and the state of the physics simulator.

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

  • use_same_id – Whether to use the same current state id for the new saved state.

  • to_file – Whether to save the state to a file.

Returns:

A unique id of the state

property current_state: pycram.datastructures.dataclasses.WorldState#
Returns:

The current state of this entity.

set_object_states_without_poses(states: typing_extensions.Dict[str, pycram.datastructures.dataclasses.ObjectState]) None#

Set the states of all objects in the World except the poses.

Parameters:

states – A dictionary with the object id as key and the object state as value.

property object_states: typing_extensions.Dict[str, pycram.datastructures.dataclasses.ObjectState]#

Return the states of all objects in the World.

Returns:

A dictionary with the object id as key and the object state as value.

save_objects_state(state_id: int) None#

Save the state of all objects in the World according to the given state using the unique state id.

Parameters:

state_id – The unique id representing the state.

abstract save_physics_simulator_state(state_id: typing_extensions.Optional[int] = None, use_same_id: bool = False) int#

Save the state of the physics simulator and returns the unique id of the state.

Parameters:
  • state_id – The used specified unique id representing the state.

  • use_same_id – If the same id should be used for the state.

Returns:

The unique id representing the state.

abstract remove_physics_simulator_state(state_id: int) None#

Remove the state of the physics simulator with the given id.

Parameters:

state_id – The unique id representing the state.

abstract restore_physics_simulator_state(state_id: int) None#
Restore the objects and environment state in the physics simulator according to

the given state using the unique state id.

Parameters:

state_id – The unique id representing the state.

get_images_for_target(target_pose: pycram.datastructures.pose.PoseStamped, cam_pose: pycram.datastructures.pose.PoseStamped, size: typing_extensions.Optional[int] = 256) typing_extensions.List[numpy.ndarray]#

Calculate the view and projection Matrix and returns 3 images:

  1. An RGB image

  2. A depth image

  3. A segmentation Mask, the segmentation mask indicates for every pixel the visible Object

Parameters:
  • target_pose – The pose to which the camera should point.

  • cam_pose – The pose of the camera.

  • size – The height and width of the images in pixels.

Returns:

A list containing an RGB and depth image as well as a segmentation mask, in this order.

register_two_objects_collision_callbacks(object_a: pycram.world_concepts.world_object.Object, object_b: pycram.world_concepts.world_object.Object, on_collision_callback: typing_extensions.Callable, on_collision_removal_callback: typing_extensions.Optional[typing_extensions.Callable] = None) None#

Register callback methods for contact between two Objects. There can be a callback for when the two Objects get in contact and, optionally, for when they are not in contact anymore.

Parameters:
  • object_a – An object in the World

  • object_b – Another object in the World

  • on_collision_callback – A function that should be called if the objects are in contact

  • on_collision_removal_callback – A function that should be called if the objects are not in contact

classmethod get_data_directories() typing_extensions.List[str]#

The resources directories where the objects, robots, and environments are stored.

classmethod add_resource_path(path: str, prepend: bool = False) None#

Add a resource path in which the World will search for files. This resource directory is searched if an Object is spawned only with a filename.

Parameters:
  • path – A path in the filesystem in which to search for files.

  • prepend – Put the new path at the beginning of the list such that it is searched first.

classmethod remove_resource_path(path: str) None#

Remove the given path from the data_directories list.

Parameters:

path – The path to remove.

classmethod change_cache_dir_path(path: str) None#

Change the cache directory to the given path

Parameters:

path – The new path for the cache directory.

get_prospection_object_for_object(obj: pycram.world_concepts.world_object.Object) pycram.world_concepts.world_object.Object#
Return the corresponding object from the prospection world for a given object in the main world.

If the given Object is already in the prospection world, it is returned.

Parameters:

obj – The object for which the corresponding object in the prospection World should be found.

Returns:

The corresponding object in the prospection world.

get_object_for_prospection_object(prospection_object: pycram.world_concepts.world_object.Object) pycram.world_concepts.world_object.Object#

Return the corresponding object from the main World for a given object in the prospection world. If the given object is not in the prospection world an error will be raised.

Parameters:

prospection_object – The object for which the corresponding object in the main World should be found.

Returns:

The object in the main World.

remove_all_objects(exclude_objects: typing_extensions.Optional[typing_extensions.List[pycram.world_concepts.world_object.Object]] = None) None#

Remove all objects from the World.

Parameters:

exclude_objects – A list of objects that should not be removed.

reset_world(remove_saved_states=False) None#

Reset the World to the state it was first spawned in. All attached objects will be detached, all joints will be set to the default position of 0 and all objects will be set to the position and orientation in which they were spawned.

Parameters:

remove_saved_states – If the saved states should be removed.

reset_concepts()#

Reset the concepts of the World.

remove_saved_states() None#

Remove all saved states of the World.

remove_objects_saved_states() None#

Remove all saved states of the objects in the World.

update_transforms_for_objects_in_current_world() None#

Updates transformations for all objects that are currently in current_world.

ray_test(from_position: typing_extensions.List[float], to_position: typing_extensions.List[float], calculate_distance: bool = False) pycram.datastructures.dataclasses.RayResult#
A wrapper around the _ray_test() method that also calculates the distance

of the ray if the calculate_distance parameter is set to True.

Parameters:
  • from_position – The starting position of the ray in Cartesian world coordinates.

  • to_position – The ending position of the ray in Cartesian world coordinates.

  • calculate_distance – Whether to calculate the distance of the ray.

Returns:

A RayResult object.

abstract _ray_test(from_position: typing_extensions.List[float], to_position: typing_extensions.List[float]) pycram.datastructures.dataclasses.RayResult#

Cast a ray and return the first object hit, if any.

Parameters:
  • from_position – The starting position of the ray in Cartesian world coordinates.

  • to_position – The ending position of the ray in Cartesian world coordinates.

Returns:

A RayResult object.

ray_test_batch(from_positions: typing_extensions.List[typing_extensions.List[float]], to_positions: typing_extensions.List[typing_extensions.List[float]], num_threads: int = 1, calculate_distances: bool = False) typing_extensions.List[pycram.datastructures.dataclasses.RayResult]#

A wrapper around the _ray_test_batch() method that also calculates the distances of the rays if the calculate_distances parameter is set to True.

Parameters:
  • from_positions – The starting positions of the rays in Cartesian world coordinates.

  • to_positions – The ending positions of the rays in Cartesian world coordinates.

  • num_threads – The number of threads to use to compute the ray intersections for the batch.

  • calculate_distances – Whether to calculate the distances of the rays.

Returns:

A list of RayResult objects.

abstract _ray_test_batch(from_positions: typing_extensions.List[typing_extensions.List[float]], to_positions: typing_extensions.List[typing_extensions.List[float]], num_threads: int = 1) typing_extensions.List[pycram.datastructures.dataclasses.RayResult]#
Cast a batch of rays and return the result for each of the rays (first object hit, if any. or -1)
Takes optional argument num_threads to specify the number of threads to use
to compute the ray intersections for the batch. Specify 0 to let simulator decide, 1 (default) for single

core execution, 2 or more to select the number of threads to use.

Parameters:
  • from_positions – The starting positions of the rays in Cartesian world coordinates.

  • to_positions – The ending positions of the rays in Cartesian world coordinates.

  • num_threads – The number of threads to use to compute the ray intersections for the batch.

create_visual_shape(visual_shape: pycram.datastructures.dataclasses.VisualShape) int#

Creates a visual shape in the physics simulator and returns the unique id of the created shape.

Parameters:

visual_shape – The visual shape to be created, uses the VisualShape dataclass defined in world_dataclasses

Returns:

The unique id of the created shape.

abstract _create_visual_shape(visual_shape: pycram.datastructures.dataclasses.VisualShape) int#

See create_visual_shape()

create_multi_body_from_visual_shapes(visual_shape_ids: typing_extensions.List[int], pose: pycram.datastructures.pose.PoseStamped) int#

Creates a multi body from visual shapes in the physics simulator and returns the unique id of the created multi body.

Parameters:
  • visual_shape_ids – The ids of the visual shapes that should be used to create the multi body.

  • pose – The pose of the origin of the multi body relative to the world frame.

Returns:

The unique id of the created multi body.

create_multi_body(multi_body: pycram.datastructures.dataclasses.MultiBody) int#

Creates a multi body in the physics simulator and returns the unique id of the created multi body. The multibody is created by joining multiple links/shapes together with joints.

Parameters:

multi_body – The multi body to be created, uses the MultiBody dataclass defined in world_dataclasses.

Returns:

The unique id of the created multi body.

abstract _create_multi_body(multi_body: pycram.datastructures.dataclasses.MultiBody) int#

See create_multi_body()

create_box_visual_shape(shape_data: pycram.datastructures.dataclasses.BoxVisualShape) int#

Creates a box visual shape in the physics simulator and returns the unique id of the created shape.

Parameters:

shape_data – The parameters that define the box visual shape to be created, uses the BoxVisualShape dataclass defined in world_dataclasses.

Returns:

The unique id of the created shape.

abstract _create_box_visual_shape(shape_data: pycram.datastructures.dataclasses.BoxVisualShape) int#

See create_box_visual_shape()

create_cylinder_visual_shape(shape_data: pycram.datastructures.dataclasses.CylinderVisualShape) int#

Creates a cylinder visual shape in the physics simulator and returns the unique id of the created shape.

Parameters:

shape_data – The parameters that define the cylinder visual shape to be created, uses the CylinderVisualShape dataclass defined in world_dataclasses.

Returns:

The unique id of the created shape.

abstract _create_cylinder_visual_shape(shape_data: pycram.datastructures.dataclasses.CylinderVisualShape) int#

See create_cylinder_visual_shape()

create_sphere_visual_shape(shape_data: pycram.datastructures.dataclasses.SphereVisualShape) int#

Creates a sphere visual shape in the physics simulator and returns the unique id of the created shape.

Parameters:

shape_data – The parameters that define the sphere visual shape to be created, uses the SphereVisualShape dataclass defined in world_dataclasses.

Returns:

The unique id of the created shape.

abstract _create_sphere_visual_shape(shape_data: pycram.datastructures.dataclasses.SphereVisualShape) int#

See create_sphere_visual_shape()

create_capsule_visual_shape(shape_data: pycram.datastructures.dataclasses.CapsuleVisualShape) int#

Creates a capsule visual shape in the physics simulator and returns the unique id of the created shape.

Parameters:

shape_data – The parameters that define the capsule visual shape to be created, uses the CapsuleVisualShape dataclass defined in world_dataclasses.

Returns:

The unique id of the created shape.

abstract _create_capsule_visual_shape(shape_data: pycram.datastructures.dataclasses.CapsuleVisualShape) int#

See create_capsule_visual_shape()

create_plane_visual_shape(shape_data: pycram.datastructures.dataclasses.PlaneVisualShape) int#

Creates a plane visual shape in the physics simulator and returns the unique id of the created shape.

Parameters:

shape_data – The parameters that define the plane visual shape to be created, uses the PlaneVisualShape dataclass defined in world_dataclasses.

Returns:

The unique id of the created shape.

abstract _create_plane_visual_shape(shape_data: pycram.datastructures.dataclasses.PlaneVisualShape) int#

See create_plane_visual_shape()

create_mesh_visual_shape(shape_data: pycram.datastructures.dataclasses.MeshVisualShape) int#

Creates a mesh visual shape in the physics simulator and returns the unique id of the created shape.

Parameters:

shape_data – The parameters that define the mesh visual shape to be created,

uses the MeshVisualShape dataclass defined in world_dataclasses. :return: The unique id of the created shape.

abstract _create_mesh_visual_shape(shape_data: pycram.datastructures.dataclasses.MeshVisualShape) int#

See create_mesh_visual_shape()

add_text(text: str, position: typing_extensions.List[float], orientation: typing_extensions.Optional[typing_extensions.List[float]] = None, size: float = 0.1, color: typing_extensions.Optional[pycram.datastructures.dataclasses.Color] = Color(), life_time: typing_extensions.Optional[float] = 0, parent_object_id: typing_extensions.Optional[int] = None, parent_link_id: typing_extensions.Optional[int] = None) int#

Adds text to the world.

Parameters:
  • text – The text to be added.

  • position – The position of the text in the world.

  • orientation

    By default, debug text will always face the camera, automatically rotation. By specifying a text orientation (quaternion), the orientation will be fixed in world space or local space

    (when parent is specified).

  • size – The size of the text.

  • color – The color of the text.

  • life_time – The lifetime in seconds of the text to remain in the world, if 0 the text will remain in the world until it is removed manually.

  • parent_object_id – The id of the object to which the text should be attached.

  • parent_link_id – The id of the link to which the text should be attached.

Returns:

The id of the added text.

abstract _add_text(text: str, position: typing_extensions.List[float], orientation: typing_extensions.Optional[typing_extensions.List[float]] = None, size: float = 0.1, color: typing_extensions.Optional[pycram.datastructures.dataclasses.Color] = Color(), life_time: typing_extensions.Optional[float] = 0, parent_object_id: typing_extensions.Optional[int] = None, parent_link_id: typing_extensions.Optional[int] = None) int#

See add_text()

remove_text(text_id: typing_extensions.Optional[int] = None) None#

Removes text from the world using the given id. if no id is given all text will be removed.

Parameters:

text_id – The id of the text to be removed.

abstract _remove_text(text_id: typing_extensions.Optional[int] = None) None#

See remove_text()

abstract enable_joint_force_torque_sensor(obj: pycram.world_concepts.world_object.Object, fts_joint_idx: int) None#

You can enable a joint force/torque sensor in each joint. Once enabled, if you perform a simulation step, the get_joint_reaction_force_torque will report the joint reaction forces in the fixed degrees of freedom: a fixed joint will measure all 6DOF joint forces/torques. A revolute/hinge joint force/torque sensor will measure 5DOF reaction forces along all axis except the hinge axis. The applied force by a joint motor is available through get_applied_joint_motor_torque.

Parameters:
  • obj – The object in which the joint is located.

  • fts_joint_idx – The index of the joint for which the force torque sensor should be enabled.

abstract disable_joint_force_torque_sensor(obj: pycram.world_concepts.world_object.Object, joint_id: int) None#

Disables the force torque sensor of a joint.

Parameters:
  • obj – The object in which the joint is located.

  • joint_id – The id of the joint for which the force torque sensor should be disabled.

abstract get_joint_reaction_force_torque(obj: pycram.world_concepts.world_object.Object, joint_id: int) typing_extensions.List[float]#

Get the joint reaction forces and torques of the specified joint.

Parameters:
  • obj – The object in which the joint is located.

  • joint_id – The id of the joint for which the force torque should be returned.

Returns:

The joint reaction forces and torques of the specified joint.

abstract get_applied_joint_motor_torque(obj: pycram.world_concepts.world_object.Object, joint_id: int) float#

Get the applied torque by a joint motor.

Parameters:
  • obj – The object in which the joint is located.

  • joint_id – The id of the joint for which the applied motor torque should be returned.

Returns:

The applied torque by a joint motor.

pause_world_sync() None#

Pause the world synchronization.

resume_world_sync() None#

Resume the world synchronization.

add_vis_axis(pose: pycram.datastructures.pose.PoseStamped) int#

Add a visual axis to the world.

Parameters:

pose – The pose of the visual axis.

Returns:

The id of the added visual axis.

_add_vis_axis(pose: pycram.datastructures.pose.PoseStamped) None#

See add_vis_axis()

remove_vis_axis() None#

Remove the visual axis from the world.

_remove_vis_axis() None#

See remove_vis_axis()

_simulator_object_creator(creator_func: typing_extensions.Callable, *args, **kwargs) int#

Create an object in the physics simulator and returns the created object id.

Parameters:
  • creator_func – The function that creates the object in the physics simulator.

  • args – The arguments for the creator function.

  • kwargs – The keyword arguments for the creator function.

Returns:

The created object id.

_simulator_object_remover(remover_func: typing_extensions.Callable, *args, **kwargs) None#

Remove an object from the physics simulator.

Parameters:
  • remover_func – The function that removes the object from the physics simulator.

  • args – The arguments for the remover function.

  • kwargs – The keyword arguments for the remover function.

update_original_state() int#

Update the original state of the world. :return: The id of the updated original state.

update_simulator_state_id_in_original_state(use_same_id: bool = False) None#

Update the simulator state id in the original state if use_physics_simulator_state is True in the configuration.

Parameters:

use_same_id – If the same id should be used for the state.

property original_state: pycram.datastructures.dataclasses.WorldState#

The saved original state of the world.

__eq__(other: World)#

Check if this body is equal to another body.

__hash__()#
class pycram.datastructures.world.UseProspectionWorld#

An environment for using the prospection world, while in this environment the current_world variable will point to the prospection world.

Example:
with UseProspectionWorld():

NavigateAction.Action([[1, 0, 0], [0, 0, 0, 1]]).perform()

prev_world: typing_extensions.Optional[World] = None#
__enter__()#

This method is called when entering the with block, it will set the current world to the prospection world

__exit__(*args)#

This method is called when exiting the with block, it will restore the previous world to be the current world.

class pycram.datastructures.world.WorldSync(world: World, prospection_world: World)#

Bases: threading.Thread

Synchronizes the state between the World and its prospection world. Meaning the cartesian and joint position of everything in the prospection world will be synchronized with the main World. The class provides the possibility to pause the synchronization, this can be used if reasoning should be done in the prospection world.

WAIT_TIME_AS_N_SIMULATION_STEPS = 20#

The time in simulation steps to wait between each iteration of the syncing loop.

world: World#
prospection_world: World#
terminate: bool = False#
pause_sync: bool = False#
object_to_prospection_object_map: typing_extensions.Dict[pycram.world_concepts.world_object.Object, pycram.world_concepts.world_object.Object]#
prospection_object_to_object_map: typing_extensions.Dict[pycram.world_concepts.world_object.Object, pycram.world_concepts.world_object.Object]#
equal_states = False#
sync_lock: threading.Lock#
run()#

Main method of the synchronization, this thread runs in a loop until the terminate flag is set. While this loop runs it continuously checks the cartesian and joint position of every object in the World and updates the corresponding object in the prospection world.

get_world_object(prospection_object: pycram.world_concepts.world_object.Object) pycram.world_concepts.world_object.Object#

Get the corresponding object from the main World for a given object in the prospection world.

Parameters:

prospection_object – The object for which the corresponding object in the main World should be found.

Returns:

The object in the main World.

get_prospection_object(obj: pycram.world_concepts.world_object.Object) pycram.world_concepts.world_object.Object#

Get the corresponding object from the prospection world for a given object in the main world.

Parameters:

obj – The object for which the corresponding object in the prospection World should be found.

Returns:

The corresponding object in the prospection world.

sync_worlds()#

Syncs the prospection world with the main world by adding and removing objects and synchronizing their states.

remove_objects_not_in_world()#

Removes all objects that are not in the main world from the prospection world.

add_objects_not_in_prospection_world()#

Adds all objects that are in the main world but not in the prospection world to the prospection world.

add_object(obj: pycram.world_concepts.world_object.Object) None#

Adds an object to the prospection world.

Parameters:

obj – The object to be added.

remove_object(obj: pycram.world_concepts.world_object.Object) None#

Removes an object from the prospection world.

Parameters:

obj – The object to be removed.

sync_objects_states() None#

Synchronizes the state of all objects in the World with the prospection world.

check_for_equal() bool#

Checks if both Worlds have the same state, meaning all objects are in the same position. This is currently not used, but might be used in the future if synchronization issues worsen.

Returns:

True if both Worlds have the same state, False otherwise.