pycram.worlds.multiverse_communication.clients
==============================================

.. py:module:: pycram.worlds.multiverse_communication.clients


Classes
-------

.. autoapisummary::

   pycram.worlds.multiverse_communication.clients.MultiverseClient
   pycram.worlds.multiverse_communication.clients.MultiverseReader
   pycram.worlds.multiverse_communication.clients.MultiverseWriter
   pycram.worlds.multiverse_communication.clients.MultiverseController
   pycram.worlds.multiverse_communication.clients.MultiverseAPI


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

.. py:class:: MultiverseClient(name: str, port: int, is_prospection_world: bool = False, simulation_wait_time_factor: float = 1.0, **kwargs)

   Bases: :py:obj:`pycram.worlds.multiverse_communication.socket.MultiverseSocket`


   .. py:attribute:: is_prospection_world
      :value: False



   .. py:attribute:: simulation_wait_time_factor
      :value: 1.0



.. py:class:: MultiverseReader(name: str, port: int, is_prospection_world: bool = False, simulation_wait_time_factor: float = 1.0, **kwargs)

   Bases: :py:obj:`MultiverseClient`


   .. py:attribute:: MAX_WAIT_TIME_FOR_DATA
      :type:  datetime.timedelta

      The maximum wait time for the data in seconds.



   .. py:attribute:: data_lock


   .. py:attribute:: thread


   .. py:attribute:: stop_thread
      :value: False



   .. py:method:: get_body_pose(name: str, wait: bool = False) -> typing_extensions.Optional[typing_extensions.Dict[str, typing_extensions.List[float]]]

      Get the body pose from the multiverse server.

      :param name: The name of the body.
      :param wait: Whether to wait for the data.
      :return: The position and orientation of the body.



   .. py:method:: get_multiple_body_poses(body_names: typing_extensions.List[str], wait: bool = False) -> typing_extensions.Optional[typing_extensions.Dict[str, pycram.datastructures.pose.PoseStamped]]

      Get the body poses from the multiverse server for multiple bodies.

      :param body_names: The names of the bodies.
      :param wait: Whether to wait for the data.
      :return: The positions and orientations of the bodies as a dictionary.



   .. py:method:: get_body_position(name: str, wait: bool = False) -> typing_extensions.Optional[typing_extensions.List[float]]

      Get the body position from the multiverse server.

      :param name: The name of the body.
      :param wait: Whether to wait for the data.
      :return: The position of the body.



   .. py:method:: get_multiple_body_positions(body_names: typing_extensions.List[str], wait: bool = False) -> typing_extensions.Optional[typing_extensions.Dict[str, typing_extensions.List[float]]]

      Get the body positions from the multiverse server for multiple bodies.

      :param body_names: The names of the bodies.
      :param wait: Whether to wait for the data.
      :return: The positions of the bodies as a dictionary.



   .. py:method:: get_body_orientation(name: str, wait: bool = False) -> typing_extensions.Optional[typing_extensions.List[float]]

      Get the body orientation from the multiverse server.

      :param name: The name of the body.
      :param wait: Whether to wait for the data.
      :return: The orientation of the body.



   .. py:method:: get_multiple_body_orientations(body_names: typing_extensions.List[str], wait: bool = False) -> typing_extensions.Optional[typing_extensions.Dict[str, typing_extensions.List[float]]]

      Get the body orientations from the multiverse server for multiple bodies.

      :param body_names: The names of the bodies.
      :param wait: Whether to wait for the data.
      :return: The orientations of the bodies as a dictionary.



   .. py:method:: get_body_property(name: str, property_: pycram.datastructures.enums.MultiverseProperty, wait: bool = False) -> typing_extensions.Optional[typing_extensions.List[float]]

      Get the body property from the multiverse server.

      :param name: The name of the body.
      :param property_: The property of the body as a Property.
      :param wait: Whether to wait for the data.
      :return: The property of the body.



   .. py:method:: get_multiple_body_properties(body_names: typing_extensions.List[str], properties: typing_extensions.List[pycram.datastructures.enums.MultiverseProperty], wait: bool = False) -> typing_extensions.Optional[typing_extensions.Dict[str, typing_extensions.Dict[str, typing_extensions.List[float]]]]

      Get the body properties from the multiverse server for multiple bodies.

      :param body_names: The names of the bodies.
      :param properties: The properties of the bodies.
      :param wait: Whether to wait for the data.
      :return: The properties of the bodies as a dictionary.



   .. py:method:: get_body_data(name: str, properties: typing_extensions.Optional[typing_extensions.List[pycram.datastructures.enums.MultiverseProperty]] = None, wait: bool = False) -> typing_extensions.Optional[typing_extensions.Dict]

      Get the body data from the multiverse server.

      :param name: The name of the body.
      :param properties: The properties of the body.
      :param wait: Whether to wait for the data.
      :return: The body data as a dictionary.



   .. py:method:: get_multiple_body_data(body_names: typing_extensions.List[str], properties: typing_extensions.Optional[typing_extensions.Dict[str, typing_extensions.List[pycram.datastructures.enums.MultiverseProperty]]] = None, wait: bool = False) -> typing_extensions.Optional[typing_extensions.Dict]

      Get the body data from the multiverse server for multiple bodies.

      :param body_names: The names of the bodies.
      :param properties: The properties of the bodies.
      :param wait: Whether to wait for the data.
      :return: The body data as a dictionary.



   .. py:method:: wait_for_body_data(name: str, properties: typing_extensions.Optional[typing_extensions.List[pycram.datastructures.enums.MultiverseProperty]] = None) -> typing_extensions.Dict

      Wait for the body data from the multiverse server.

      :param name: The name of the body.
      :param properties: The properties of the body.
      :return: The body data as a dictionary.



   .. py:method:: wait_for_multiple_body_data(body_names: typing_extensions.List[str], properties: typing_extensions.Optional[typing_extensions.Dict[str, typing_extensions.List[pycram.datastructures.enums.MultiverseProperty]]] = None) -> typing_extensions.Dict

      Wait for the body data from the multiverse server for multiple bodies.

      :param body_names: The names of the bodies.
      :param properties: The properties of the bodies.
      :return: The body data as a dictionary.



   .. py:method:: _wait_for_body_data_template(body_names: typing_extensions.Union[str, typing_extensions.List[str]], check_func: typing_extensions.Callable[[typing_extensions.Union[str, typing_extensions.List[str]], typing_extensions.Dict, typing_extensions.Union[typing_extensions.Dict, typing_extensions.List]], bool], properties: typing_extensions.Optional[typing_extensions.Union[typing_extensions.Dict, typing_extensions.List]] = None) -> typing_extensions.Dict

      Wait for the body data from the multiverse server for multiple bodies.

      :param body_names: The names of the bodies.
      :param properties: The properties of the bodies.
      :param check_func: The function to check if the data is received.
      :return: The body data as a dictionary.



   .. py:method:: check_multiple_body_data(body_names: typing_extensions.List[str], data: typing_extensions.Dict, properties: typing_extensions.Optional[typing_extensions.Dict[str, typing_extensions.List[pycram.datastructures.enums.MultiverseProperty]]] = None) -> bool

      Check if the body data is received from the multiverse server for multiple bodies.

      :param body_names: The names of the bodies.
      :param data: The data received from the multiverse server.
      :param properties: The properties of the bodies.
      :return: Whether the body data is received.



   .. py:method:: check_for_body_data(name: str, data: typing_extensions.Dict, properties: typing_extensions.Optional[typing_extensions.List[pycram.datastructures.enums.MultiverseProperty]] = None) -> bool
      :staticmethod:


      Check if the body data is received from the multiverse server.

      :param name: The name of the body.
      :param data: The data received from the multiverse server.
      :param properties: The properties of the body.
      :return: Whether the body data is received.



   .. py:method:: get_received_data()

      Get the latest received data from the multiverse server.



   .. py:method:: receive_all_data_from_server()

      Get all data from the multiverse server.



   .. py:method:: join()


.. py:class:: MultiverseWriter(name: str, port: int, simulation: typing_extensions.Optional[str] = None, is_prospection_world: bool = False, simulation_wait_time_factor: float = 1.0, **kwargs)

   Bases: :py:obj:`MultiverseClient`


   .. py:attribute:: simulation
      :value: None



   .. py:attribute:: lock


   .. py:method:: spawn_robot_with_actuators(robot_name: str, actuator_joint_commands: typing_extensions.Optional[typing_extensions.Dict[str, typing_extensions.List[str]]] = None) -> None

      Spawn the robot with controlled actuators in the simulation.

      :param robot_name: The name of the robot.
      :param actuator_joint_commands: A dictionary mapping actuator names to joint command names.



   .. py:method:: _reset_request_meta_data(set_simulation_name: bool = True)

      Reset the request metadata.

      :param set_simulation_name: Whether to set the simulation name to the value of self.simulation_name.



   .. py:method:: set_body_pose(body_name: str, position: typing_extensions.List[float], orientation: typing_extensions.List[float]) -> None

      Set the body pose in the simulation.

      :param body_name: The name of the body.
      :param position: The position of the body.
      :param orientation: The orientation of the body.



   .. py:method:: set_multiple_body_poses(body_data: typing_extensions.Dict[str, typing_extensions.Dict[pycram.datastructures.enums.MultiverseBodyProperty, typing_extensions.List[float]]]) -> None

      Set the body poses in the simulation for multiple bodies.

      :param body_data: The data to be sent for multiple bodies.



   .. py:method:: set_body_position(body_name: str, position: typing_extensions.List[float]) -> None

      Set the body position in the simulation.

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



   .. py:method:: set_body_orientation(body_name: str, orientation: typing_extensions.List[float]) -> None

      Set the body orientation in the simulation.

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



   .. py:method:: set_body_property(body_name: str, property_: pycram.datastructures.enums.MultiverseProperty, value: typing_extensions.List[float]) -> None

      Set the body property in the simulation.

      :param body_name: The name of the body.
      :param property_: The property of the body.
      :param value: The value of the property.



   .. py:method:: remove_body(body_name: str) -> None

      Remove the body from the simulation.

      :param body_name: The name of the body.



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

      Reset the world in the simulation.



   .. py:method:: send_body_data_to_server(body_name: str, body_data: typing_extensions.Dict[pycram.datastructures.enums.MultiverseProperty, typing_extensions.List[float]]) -> typing_extensions.Dict

      Send data to the multiverse server.

      :param body_name: The name of the body.
      :param body_data: The data to be sent.
      :return: The response from the server.



   .. py:method:: send_multiple_body_data_to_server(body_data: typing_extensions.Dict[str, typing_extensions.Dict[pycram.datastructures.enums.MultiverseProperty, typing_extensions.List[float]]]) -> typing_extensions.Dict

      Send data to the multiverse server for multiple bodies.

      :param body_data: The data to be sent for multiple bodies.
      :return: The response from the server.



   .. py:method:: send_meta_data_and_get_response(send_meta_data: typing_extensions.Dict) -> typing_extensions.Dict

      Send metadata to the multiverse server and get the response.

      :param send_meta_data: The metadata to be sent.
      :return: The response from the server.



   .. py:method:: send_data_to_server(data: typing_extensions.List, send_meta_data: typing_extensions.Optional[typing_extensions.Dict] = None, receive_meta_data: typing_extensions.Optional[typing_extensions.Dict] = None, set_simulation_name: bool = True) -> typing_extensions.Dict

      Send data to the multiverse server.

      :param data: The data to be sent.
      :param send_meta_data: The metadata to be sent.
      :param receive_meta_data: The metadata to be received.
      :param set_simulation_name: Whether to set the simulation name to the value of self.simulation.
      :return: The response from the server.



.. py:class:: MultiverseController(name: str, port: int, is_prospection_world: bool = False, **kwargs)

   Bases: :py:obj:`MultiverseWriter`


   .. py:method:: init_controller(actuator_joint_commands: typing_extensions.Dict[str, typing_extensions.List[str]]) -> None

      Initialize the controller by sending the controller data to the multiverse server.

      :param actuator_joint_commands: A dictionary mapping actuator names to joint command names.



.. py:class:: MultiverseAPI(name: str, port: int, simulation: str, is_prospection_world: bool = False, simulation_wait_time_factor: float = 1.0)

   Bases: :py:obj:`MultiverseClient`


   .. py:attribute:: API_REQUEST_WAIT_TIME
      :type:  datetime.timedelta

      The wait time for the API request in seconds.



   .. py:attribute:: APIs_THAT_NEED_WAIT_TIME
      :type:  typing_extensions.List[pycram.datastructures.enums.MultiverseAPIName]


   .. py:attribute:: simulation


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



   .. py:method:: get_body_bounding_box(body_name: str, with_children: bool = False) -> typing_extensions.Union[pycram.datastructures.dataclasses.AxisAlignedBoundingBox, typing_extensions.List[pycram.datastructures.dataclasses.AxisAlignedBoundingBox]]

      Get the body bounding box from the multiverse server, they are with respect to the body's frame.



   .. py:method:: _get_bounding_box(body_name: str, with_children: bool = False) -> typing_extensions.List[typing_extensions.List[float]]

      Get the body bounding box from the multiverse server.



   .. py:method:: save(save_name: str, save_directory: typing_extensions.Optional[str] = None) -> str

      Save the current state of the simulation.

      :param save_name: The name of the save.
      :param save_directory: The path to save the simulation, can be relative or absolute. If the path is relative,
       it will be saved in the saved folder in multiverse.
      :return: The save path.



   .. py:method:: load(save_name: str, save_directory: typing_extensions.Optional[str] = None) -> None

      Load the saved state of the simulation.

      :param save_name: The name of the save.
      :param save_directory: The path to load the simulation, can be relative or absolute. If the path is relative,
       it will be loaded from the saved folder in multiverse.



   .. py:method:: get_save_path(save_name: str, save_directory: typing_extensions.Optional[str] = None) -> str
      :staticmethod:


      Get the save path.

      :param save_name: The save name.
      :param save_directory: The save directory.
      :return: The save path.



   .. py:method:: attach(constraint: pycram.world_concepts.constraints.Constraint) -> None

      Request to attach the child link to the parent link.

      :param constraint: The constraint.



   .. py:method:: _attach(child_link_name: str, parent_link_name: str, attachment_pose: str) -> None

      Attach the child link to the parent link.

      :param child_link_name: The name of the child link.
      :param parent_link_name: The name of the parent link.
      :param attachment_pose: The attachment pose.



   .. py:method:: get_constraint_link_names(constraint: pycram.world_concepts.constraints.Constraint) -> typing_extensions.Tuple[str, str]

      Get the link names of the constraint.

      :param constraint: The constraint.
      :return: The link names of the constraint.



   .. py:method:: get_parent_link_name(constraint: pycram.world_concepts.constraints.Constraint) -> str

      Get the parent link name of the constraint.

      :param constraint: The constraint.
      :return: The parent link name of the constraint.



   .. py:method:: get_constraint_child_link_name(constraint: pycram.world_concepts.constraints.Constraint) -> str

      Get the child link name of the constraint.

      :param constraint: The constraint.
      :return: The child link name of the constraint.



   .. py:method:: get_link_name_for_constraint(link: pycram.world_concepts.world_object.Link) -> str
      :staticmethod:


      Get the link name from link object, if the link belongs to a one link object, return the object name.

      :param link: The link.
      :return: The link name.



   .. py:method:: detach(constraint: pycram.world_concepts.constraints.Constraint) -> None

      Request to detach the child link from the parent link.

      :param constraint: The constraint.



   .. py:method:: _detach(child_link_name: str, parent_link_name: str) -> None

      Detach the child link from the parent link.

      :param child_link_name: The name of the child link.
      :param parent_link_name: The name of the parent link.



   .. py:method:: _get_attachment_pose_as_string(constraint: pycram.world_concepts.constraints.Constraint) -> str

      Get the attachment pose as a string.

      :param constraint: The constraint.
      :return: The attachment pose as a string.



   .. py:method:: _pose_to_string(pose: pycram.datastructures.pose.PoseStamped) -> str
      :staticmethod:


      Convert the pose to a string.

      :param pose: The pose.
      :return: The pose as a string.



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

      Check if the object exists in the simulation.

      :param obj: The object.
      :return: Whether the object exists in the simulation.



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

      Get the resultant force and torque on the object.

      :param obj: The object.
      :return: The resultant force and torque on the object.



   .. py:method:: get_contact_points_between_bodies(body_1_name: str, body_2_name: str) -> typing_extensions.List[pycram.datastructures.dataclasses.MultiverseContactPoint]

      Request the contact points between two bodies.

      :param body_1_name: The name of the first body.
      :param body_2_name: The name of the second body.
      :return: The contact points between the bodies as a list of MultiverseContactPoint.



   .. py:method:: get_objects_intersected_with_rays(from_positions: typing_extensions.List[typing_extensions.List[float]], to_positions: typing_extensions.List[typing_extensions.List[float]]) -> typing_extensions.List[pycram.datastructures.dataclasses.MultiverseRayResult]

      Get the rays intersections with the objects from the from_positions to the to_positions.

      :param from_positions: The starting positions of the rays.
      :param to_positions: The ending positions of the rays.
      :return: The rays intersections with the objects as a list of MultiverseRayResult.



   .. py:method:: _get_rays(from_positions: typing_extensions.List[typing_extensions.List[float]], to_positions: typing_extensions.List[typing_extensions.List[float]]) -> typing_extensions.List[str]

      Get the rays intersections with the objects from the from_positions to the to_positions.

      :param from_positions: The starting positions of the rays.
      :param to_positions: The ending positions of the rays.
      :return: The rays intersections with the objects as a dictionary.



   .. py:method:: _parse_get_rays_response(response: typing_extensions.List[str]) -> typing_extensions.List[pycram.datastructures.dataclasses.MultiverseRayResult]
      :staticmethod:


      Parse the response of the get rays API.

      :param response: The response of the get rays API as a list of strings.
      :return: The rays as a list of lists of floats.



   .. py:method:: list_of_positions_to_string(positions: typing_extensions.List[typing_extensions.List[float]]) -> str
      :staticmethod:


      Convert the list of positions to a string.

      :param positions: The list of positions.
      :return: The list of positions as a string.



   .. py:method:: _parse_constraint_effort(contact_effort: typing_extensions.List[str]) -> typing_extensions.Tuple[typing_extensions.List[float], typing_extensions.List[float]]
      :staticmethod:


      Parse the contact effort of an object.

      :param contact_effort: The contact effort of the object as a list of strings.
      :return: The contact effort of the object as a list of floats.



   .. py:method:: _parse_contact_points(body_1, body_2, contact_points: typing_extensions.List[str]) -> typing_extensions.List[pycram.datastructures.dataclasses.MultiverseContactPoint]
      :staticmethod:


      Parse the contact points of an object.

      :param body_1: The name of the first body.
      :param body_2: The name of the second body.
      :param contact_points: The contact points of the object as a list of strings.
      :return: The contact positions, and normal vectors as a list of MultiverseContactPoint.



   .. py:method:: get_contact_points(body_name: str) -> typing_extensions.List[pycram.datastructures.dataclasses.MultiverseContactPoint]

      Get the contact points of a body from the multiverse server.

      :param body_name: The name of the body.



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

      Pause the simulation.



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

      Unpause the simulation.



   .. py:method:: _request_single_api_callback(api_name: pycram.datastructures.enums.MultiverseAPIName, *params) -> typing_extensions.List[str]

      Request a single API callback from the server.

      :param api_data: The API data to request the callback.
      :return: The API response as a list of strings.



   .. py:method:: _request_apis_callbacks(api_data: typing_extensions.Dict[pycram.datastructures.enums.MultiverseAPIName, typing_extensions.List]) -> typing_extensions.Dict[pycram.datastructures.enums.MultiverseAPIName, typing_extensions.List[str]]

      Request the API callbacks from the server.

      :param api_data: The API data to add to the request metadata.
      :return: The API response as a list of strings.



   .. py:method:: validate_apis_response(api_data: typing_extensions.Dict[pycram.datastructures.enums.MultiverseAPIName, typing_extensions.List], responses: typing_extensions.Dict[pycram.datastructures.enums.MultiverseAPIName, typing_extensions.List[str]])
      :staticmethod:


      Validate the responses from the multiverse server and raise error if an api request failed.

      :param api_data: The data of the api request which has the api name and the arguments.
      :param responses: The responses of the given api requests.
      :raises FailedAPIResponse: when one of the responses reports that the request failed.



   .. py:method:: _get_all_apis_responses() -> typing_extensions.Dict[pycram.datastructures.enums.MultiverseAPIName, typing_extensions.List[str]]

      Get all the API responses from the server.

      :return: The API responses as a list of APIData.



   .. py:method:: _add_api_request(api_name: str, *params)

      Add an API request to the request metadata.

      :param api_name: The name of the API.
      :param params: The parameters of the API.



   .. py:method:: _send_api_request()

      Send the API request to the server.



   .. py:method:: _reset_api_callback()

      Initialize the API callback in the request metadata.



