pycram.worlds.multiverse
========================

.. py:module:: pycram.worlds.multiverse


Classes
-------

.. autoapisummary::

   pycram.worlds.multiverse.Multiverse


Module Contents
---------------

.. py:class:: Multiverse(is_prospection: typing_extensions.Optional[bool] = False, clear_cache: bool = False)

   Bases: :py:obj:`pycram.datastructures.world.World`


   This class implements an interface between Multiverse and PyCRAM.


   .. py:attribute:: conf
      :type:  pycram.config.multiverse_conf.MultiverseConfig

      The Multiverse configuration.



   .. py:attribute:: supported_joint_types

      A Tuple for the supported pycram joint types in Multiverse.



   .. py:attribute:: added_multiverse_resources
      :type:  bool
      :value: False


      A flag to check if the multiverse resources have been added.



   .. py:attribute:: latest_save_id
      :type:  typing_extensions.Optional[int]
      :value: None



   .. py:attribute:: saved_simulator_states
      :type:  typing_extensions.Dict


   .. py:attribute:: simulation
      :value: 'belief_state'



   .. py:attribute:: client_manager


   .. py:attribute:: ray_test_utils


   .. py:attribute:: is_paused
      :type:  bool
      :value: False



   .. py:method:: _init_clients(is_prospection: bool = False)

      Initialize the Multiverse clients that will be used to communicate with the Multiverse server.
      Each client is responsible for a specific task, e.g. reading data from the server, writing data to the serve,
       calling the API, or controlling the robot joints.

      :param is_prospection: Whether the world is prospection or not.



   .. py:method:: _init_constraint_and_object_id_name_map_collections()


   .. py:method:: _init_world(mode: pycram.datastructures.enums.WorldMode)


   .. py:method:: make_sure_multiverse_resources_are_added(clear_cache: bool = False) -> None
      :classmethod:


      Add the multiverse resources to the pycram world resources, and change the data directory and cache manager.

      :param clear_cache: Whether to clear the cache or not.



   .. py:method:: remove_multiverse_resources()

      Remove the multiverse resources from the pycram world resources.



   .. py:method:: _spawn_floor()

      Spawn the plane in the simulator.



   .. py:method:: pause_simulation() -> None

      Pause the simulation.



   .. py:method:: unpause_simulation() -> None

      Unpause the simulation.



   .. py:method:: load_generic_object_and_get_id(description: pycram.object_descriptors.generic.ObjectDescription, pose: typing_extensions.Optional[pycram.datastructures.pose.PoseStamped] = None) -> int


   .. py:method:: get_images_for_target(target_pose: pycram.datastructures.pose.PoseStamped, cam_pose: pycram.datastructures.pose.PoseStamped, size: int = 256, camera_min_distance: float = 0.1, camera_max_distance: int = 3, plot: bool = False) -> typing_extensions.List[numpy.ndarray]

      Uses ray test to get the images for the target object. (target_pose is currently not used)



   .. py:method:: get_joint_position_name(joint: pycram.description.Joint) -> pycram.datastructures.enums.MultiverseJointPosition
      :staticmethod:


      Get the attribute name of the joint position in the Multiverse from the pycram joint type.

      :param joint: The joint.



   .. py:method:: spawn_robot_with_controller(name: str, pose: pycram.datastructures.pose.PoseStamped) -> None

      Spawn the robot in the simulator.

      :param name: The name of the robot.
      :param pose: The pose of the robot.



   .. py:method:: load_object_and_get_id(name: typing_extensions.Optional[str] = None, pose: typing_extensions.Optional[pycram.datastructures.pose.PoseStamped] = None, obj_type: typing_extensions.Optional[typing_extensions.Type[pycrap.PhysicalObject]] = None) -> int

      Spawn the object in the simulator and return the object id. Object name has to be unique and has to be same as
      the name of the object in the description file.

      :param name: The name of the object to be loaded.
      :param pose: The pose of the object.
      :param obj_type: The type of the object.



   .. py:method:: spawn_object(name: str, object_type: typing_extensions.Type[pycrap.PhysicalObject], pose: pycram.datastructures.pose.PoseStamped) -> None

      Spawn the object in the simulator.

      :param name: The name of the object.
      :param object_type: The type of the object.
      :param pose: The pose of the object.



   .. py:method:: spawn_robot(name: str, pose: pycram.datastructures.pose.PoseStamped) -> None

      Spawn the robot in the simulator.

      :param name: The name of the robot.
      :param pose: The pose of the robot.



   .. py:method:: _update_object_id_name_maps_and_get_latest_id(name: str) -> int

      Update the object id name maps and return the latest object id.

      :param name: The name of the object.
      :return: The latest object id.



   .. py:method:: get_object_joint_names(obj: pycram.world_concepts.world_object.Object) -> typing_extensions.List[str]


   .. py:method:: get_object_link_names(obj: pycram.world_concepts.world_object.Object) -> typing_extensions.List[str]


   .. py:method:: get_link_position(link: pycram.description.Link) -> typing_extensions.List[float]


   .. py:method:: get_link_orientation(link: pycram.description.Link) -> typing_extensions.List[float]


   .. py:method:: get_multiple_link_positions(links: typing_extensions.List[pycram.description.Link]) -> typing_extensions.Dict[str, typing_extensions.List[float]]


   .. py:method:: get_multiple_link_orientations(links: typing_extensions.List[pycram.description.Link]) -> typing_extensions.Dict[str, typing_extensions.List[float]]


   .. py:method:: _reset_joint_position(joint: pycram.description.Joint, joint_position: float) -> bool


   .. py:method:: _reset_joint_position_using_controller(joint: pycram.description.Joint, joint_position: float) -> bool

      Reset the position of a joint in the simulator using the controller.

      :param joint: The joint.
      :param joint_position: The position of the joint.
      :return: True if the joint position is reset successfully.



   .. py:method:: _set_multiple_joint_positions(joint_positions: typing_extensions.Dict[pycram.description.Joint, float]) -> bool

      Set the positions of multiple joints in the simulator. Also check if the joint is controlled by an actuator
      and use the controller to set the joint position if the joint is controlled.

      :param joint_positions: The dictionary of joints and positions.
      :return: True if the joint positions are set successfully (this means that the joint positions are set without
       errors, but not necessarily that the joint positions are set to the specified values).



   .. py:method:: get_controlled_joints(joints: typing_extensions.Optional[typing_extensions.List[pycram.description.Joint]] = None) -> typing_extensions.List[pycram.description.Joint]

      Get the joints that are controlled by an actuator from the list of joints.

      :param joints: The list of joints to check.
      :return: The list of controlled joints.



   .. py:method:: _set_multiple_joint_positions_without_controller(joint_positions: typing_extensions.Dict[pycram.description.Joint, float]) -> None

      Set the positions of multiple joints in the simulator without using the controller.

      :param joint_positions: The dictionary of joints and positions.



   .. py:method:: _set_multiple_joint_positions_using_controller(joint_positions: typing_extensions.Dict[pycram.description.Joint, float]) -> bool

      Set the positions of multiple joints in the simulator using the controller.

      :param joint_positions: The dictionary of joints and positions.



   .. py:method:: _get_joint_position(joint: pycram.description.Joint) -> typing_extensions.Optional[float]


   .. py:method:: _get_multiple_joint_positions(joints: typing_extensions.List[pycram.description.Joint]) -> typing_extensions.Optional[typing_extensions.Dict[str, float]]


   .. py:method:: get_joint_cmd_name(joint_type: pycram.datastructures.enums.JointType) -> pycram.datastructures.enums.MultiverseJointCMD
      :staticmethod:


      Get the attribute name of the joint command in the Multiverse from the pycram joint type.

      :param joint_type: The pycram joint type.



   .. py:method:: get_link_pose(link: pycram.description.Link) -> typing_extensions.Optional[pycram.datastructures.pose.PoseStamped]


   .. py:method:: get_multiple_link_poses(links: typing_extensions.List[pycram.description.Link]) -> typing_extensions.Dict[str, pycram.datastructures.pose.PoseStamped]


   .. py:method:: get_object_pose(obj: pycram.world_concepts.world_object.Object) -> pycram.datastructures.pose.PoseStamped


   .. py:method:: get_multiple_object_poses(objects: typing_extensions.List[pycram.world_concepts.world_object.Object]) -> typing_extensions.Dict[str, pycram.datastructures.pose.PoseStamped]

      Set the poses of multiple objects in the simulator. If the object is of type environment, the pose will be
      the default pose.

      :param objects: The list of objects.
      :return: The dictionary of object names and poses.



   .. py:method:: reset_object_base_pose(obj: pycram.world_concepts.world_object.Object, pose: pycram.datastructures.pose.PoseStamped) -> bool


   .. py:method:: reset_multiple_objects_base_poses(objects: typing_extensions.Dict[pycram.world_concepts.world_object.Object, pycram.datastructures.pose.PoseStamped]) -> None

      Reset the poses of multiple objects in the simulator.

      :param objects: The dictionary of objects and poses.



   .. py:method:: _set_body_pose(body_name: str, pose: pycram.datastructures.pose.PoseStamped) -> None

      Reset the pose of a body (object, link, or joint) in the simulator.

      :param body_name: The name of the body.
      :param pose: The pose of the body.



   .. py:method:: _set_multiple_body_poses(body_poses: typing_extensions.Dict[str, pycram.datastructures.pose.PoseStamped]) -> None

      Reset the poses of multiple bodies in the simulator.

      :param body_poses: The dictionary of body names and poses.



   .. py:method:: _get_body_pose(body_name: str, wait: typing_extensions.Optional[bool] = True) -> typing_extensions.Optional[pycram.datastructures.pose.PoseStamped]

      Get the pose of a body in the simulator.

      :param body_name: The name of the body.
      :param wait: Whether to wait until the pose is received.
      :return: The pose of the body.



   .. py:method:: _get_multiple_body_poses(body_names: typing_extensions.List[str]) -> typing_extensions.Dict[str, pycram.datastructures.pose.PoseStamped]

      Get the poses of multiple bodies in the simulator.

      :param body_names: The list of body names.



   .. py:method:: get_multiple_object_positions(objects: typing_extensions.List[pycram.world_concepts.world_object.Object]) -> typing_extensions.Dict[str, typing_extensions.List[float]]


   .. py:method:: get_object_position(obj: pycram.world_concepts.world_object.Object) -> typing_extensions.List[float]


   .. py:method:: get_multiple_object_orientations(objects: typing_extensions.List[pycram.world_concepts.world_object.Object]) -> typing_extensions.Dict[str, typing_extensions.List[float]]


   .. py:method:: get_object_orientation(obj: pycram.world_concepts.world_object.Object) -> typing_extensions.List[float]


   .. py:method:: multiverse_reset_world()

      Reset the world using the Multiverse API.



   .. py:method:: disconnect_from_physics_server() -> None


   .. py:method:: join_threads() -> None


   .. py:method:: _remove_visual_object(obj_id: int) -> bool


   .. py:method:: remove_object_from_simulator(obj: pycram.world_concepts.world_object.Object) -> bool


   .. py:method:: add_constraint(constraint: pycram.world_concepts.constraints.Constraint) -> int


   .. py:method:: _update_constraint_collection_and_get_latest_id(constraint: pycram.world_concepts.constraints.Constraint) -> int

      Update the constraint collection and return the latest constraint id.

      :param constraint: The constraint to be added.
      :return: The latest constraint id.



   .. py:method:: remove_constraint(constraint_id) -> None


   .. py:method:: perform_collision_detection() -> None


   .. py:method:: get_body_contact_points(body: pycram.datastructures.world_entity.PhysicalBody) -> pycram.datastructures.dataclasses.ContactPointsList


   .. py:method:: get_object_contact_points(obj: pycram.world_concepts.world_object.Object, ignore_attached_objects: bool = True) -> pycram.datastructures.dataclasses.ContactPointsList

      Note: Currently Multiverse only gets one contact point per contact objects.

      :param obj: The object.
      :param ignore_attached_objects: Whether to ignore the attached objects or not.
      :return: The contact points of the object.



   .. py:method:: get_object_with_body_name(body_name: str) -> typing_extensions.Tuple[typing_extensions.Optional[pycram.world_concepts.world_object.Object], typing_extensions.Optional[pycram.description.Link]]

      Get the object with the body name in the simulator, the body name can be the name of the object or the link.

      :param body_name: The name of the body.
      :return: The object if found otherwise None, and the link if the body name is a link.



   .. py:method:: _get_normal_force_on_object_from_contact_force(obj: pycram.world_concepts.world_object.Object, contact_force: typing_extensions.List[float]) -> float
      :staticmethod:


      Get the normal force on an object from the contact force exerted by another object that is expressed in the
      world frame. Thus transforming the contact force to the object frame is necessary.

      :param obj: The object.
      :param contact_force: The contact force.
      :return: The normal force on the object.



   .. py:method:: get_contact_points_between_two_bodies(obj1: pycram.world_concepts.world_object.Object, obj2: pycram.world_concepts.world_object.Object) -> pycram.datastructures.dataclasses.ContactPointsList


   .. py:method:: _ray_test(from_position: typing_extensions.List[float], to_position: typing_extensions.List[float]) -> pycram.datastructures.dataclasses.RayResult


   .. py:method:: _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, return_distance: bool = False) -> typing_extensions.List[pycram.datastructures.dataclasses.RayResult]

      Note: Currently, num_threads is not used in Multiverse.



   .. py:method:: step(func: typing_extensions.Optional[typing_extensions.Callable[[], None]] = None, step_seconds: typing_extensions.Optional[float] = None) -> None

      Perform a simulation step in the simulator, this is useful when use_static_mode is True.

      :param func: A function to be called after the simulation step.
      :param step_seconds: The number of seconds to step the simulation.



   .. py:method:: save_physics_simulator_state(state_id: typing_extensions.Optional[int] = None, use_same_id: bool = False) -> int


   .. py:method:: remove_physics_simulator_state(state_id: int) -> None


   .. py:method:: restore_physics_simulator_state(state_id: int) -> None


   .. py:method:: set_link_color(link: pycram.description.Link, rgba_color: pycram.datastructures.dataclasses.Color)


   .. py:method:: get_link_color(link: pycram.description.Link) -> pycram.datastructures.dataclasses.Color


   .. py:method:: get_colors_of_object_links(obj: pycram.world_concepts.world_object.Object) -> typing_extensions.Dict[str, pycram.datastructures.dataclasses.Color]


   .. py:method:: set_realtime(real_time: bool) -> None


   .. py:method:: set_gravity(gravity_vector: typing_extensions.List[float]) -> None


   .. py:method:: check_object_exists(obj: pycram.world_concepts.world_object.Object) -> bool

      Check if the object exists in the Multiverse world.

      :param obj: The object.
      :return: True if the object exists, False otherwise.



