pycram.object_descriptors.mjcf
==============================

.. py:module:: pycram.object_descriptors.mjcf


Classes
-------

.. autoapisummary::

   pycram.object_descriptors.mjcf.LinkDescription
   pycram.object_descriptors.mjcf.JointDescription
   pycram.object_descriptors.mjcf.ObjectFactory
   pycram.object_descriptors.mjcf.PrimitiveObjectFactory
   pycram.object_descriptors.mjcf.ObjectDescription


Functions
---------

.. autoapisummary::

   pycram.object_descriptors.mjcf.parse_pose_from_body_element


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

.. py:class:: LinkDescription(mjcf_description: dm_control.mjcf.Element, mesh_dir: typing_extensions.Optional[str] = None)

   Bases: :py:obj:`pycram.description.LinkDescription`


   A class that represents a link description of an object.


   .. py:attribute:: mesh_dir
      :value: None



   .. py:property:: geometry
      :type: typing_extensions.Union[typing_extensions.List[pycram.datastructures.dataclasses.VisualShape], pycram.datastructures.dataclasses.VisualShape, None]


      :return: The geometry type of the collision element of this link.



   .. py:method:: _get_visual_shape(mjcf_geometry) -> typing_extensions.Union[pycram.datastructures.dataclasses.VisualShape, None]

      :param mjcf_geometry: The MJCFGeometry to get the visual shape for.
      :return: The VisualShape of the given MJCFGeometry object.



   .. py:method:: look_for_file_in_mesh_dir(file_name: str) -> str

      Look for a file in the mesh directory of the object.

      :param file_name: The name of the file.
      :return: The path to the file.



   .. py:property:: origin
      :type: typing_extensions.Union[pycram.datastructures.pose.PoseStamped, None]


      :return: The origin of this link.



   .. py:property:: name
      :type: str


      :return: the name of this entity.



.. py:class:: JointDescription(mjcf_description: dm_control.mjcf.Element, is_virtual: typing_extensions.Optional[bool] = False)

   Bases: :py:obj:`pycram.description.JointDescription`


   A class that represents the description of a joint.


   .. py:attribute:: mjcf_type_map

      A dictionary mapping the MJCF joint types to the PyCRAM joint types.



   .. py:attribute:: pycram_type_map

      A dictionary mapping the PyCRAM joint types to the MJCF joint types.



   .. py:property:: origin
      :type: pycram.datastructures.pose.PoseStamped


      :return: the origin of this entity.



   .. py:property:: name
      :type: str


      :return: the name of this entity.



   .. py:property:: has_limits
      :type: bool


      :return: True if the joint has limits, False otherwise.



   .. py:property:: type
      :type: pycram.datastructures.enums.JointType


      :return: The type of this joint.



   .. py:property:: axis
      :type: pycram.datastructures.pose.Point


      :return: The axis of this joint, for example the rotation axis for a revolute joint.



   .. py:property:: lower_limit
      :type: typing_extensions.Union[float, None]


      :return: The lower limit of this joint, or None if the joint has no limits.



   .. py:property:: upper_limit
      :type: typing_extensions.Union[float, None]


      :return: The upper limit of this joint, or None if the joint has no limits.



   .. py:property:: parent
      :type: str


      :return: The name of the parent link of this joint.



   .. py:property:: child
      :type: str


      :return: The name of the child link of this joint.



   .. py:property:: _parent_link_element
      :type: dm_control.mjcf.Element



   .. py:property:: damping
      :type: float


      :return: The damping of this joint.



   .. py:property:: friction
      :type: float

      :abstractmethod:


      :return: The friction of this joint.



.. py:class:: ObjectFactory(file_path: str, config: multiverse_parser.Configuration)

   Bases: :py:obj:`multiverse_parser.Factory`


   Create MJCF object descriptions from mesh files.


   .. py:method:: from_mesh_file(object_name: str, texture_type: str = 'png')


   .. py:method:: add_material_with_texture(geom_builder: multiverse_parser.GeomBuilder, material_name: str, texture_file_path: str)
      :staticmethod:


      Add a material with a texture to the geom builder.

      :param geom_builder: The geom builder to add the material to.
      :param material_name: The name of the material.
      :param texture_file_path: The path to the texture file.



   .. py:method:: export_to_mjcf(output_file_path: str)

      Export the object to a MJCF file.

      :param output_file_path: The path to the output file.



.. py:class:: PrimitiveObjectFactory(object_name: str, shape_data: pycram.datastructures.dataclasses.VisualShapeUnion, save_path: str, orientation: typing_extensions.Optional[typing_extensions.List[float]] = None)

   Bases: :py:obj:`ObjectFactory`


   Create MJCF object descriptions from mesh files.


   .. py:attribute:: shape_data
      :type:  pycram.datastructures.dataclasses.VisualShapeUnion


   .. py:attribute:: orientation
      :type:  typing_extensions.List[float]
      :value: [0, 0, 0, 1]



   .. py:method:: build_shape()


.. py:class:: ObjectDescription

   Bases: :py:obj:`pycram.description.ObjectDescription`


   A class that represents an object description of an object.


   .. py:attribute:: COMPILER_TAG
      :value: 'compiler'


      The tag of the compiler element in the MJCF file.



   .. py:attribute:: MESH_DIR_ATTR
      :value: 'meshdir'



   .. py:attribute:: TEXTURE_DIR_ATTR
      :value: 'texturedir'


      The attributes of the compiler element in the MJCF file. The meshdir attribute is the directory where the mesh files
      are stored and the texturedir attribute is the directory where the texture files are stored.



   .. py:class:: Link(_id: int, link_description: LinkDescription, obj: pycram.world_concepts.world_object.Object, concept: typing_extensions.Type[pycrap.ontologies.Base] = pycrap.ontologies.Link, parse_name: bool = True)

      Bases: :py:obj:`pycram.description.ObjectDescription.Link`, :py:obj:`LinkDescription`


      A link of an Object in the World.



   .. py:class:: RootLink(obj: pycram.world_concepts.world_object.Object)

      Bases: :py:obj:`pycram.description.ObjectDescription.RootLink`, :py:obj:`Link`


      The root link of an Object in the World.
      This differs from the normal AbstractLink class in that the pose and the tf_frame is the same as that of the object.



   .. py:class:: Joint(_id: int, joint_description: JointDescription, obj: pycram.world_concepts.world_object.Object, is_virtual: typing_extensions.Optional[bool] = False, concept: typing_extensions.Type[pycrap.ontologies.Base] = pycrap.ontologies.Joint)

      Bases: :py:obj:`pycram.description.ObjectDescription.Joint`, :py:obj:`JointDescription`


      Represent a joint of an Object in the World.



   .. py:attribute:: _link_map
      :value: None



   .. py:attribute:: _joint_map
      :value: None



   .. py:attribute:: _child_map
      :value: None



   .. py:attribute:: _parent_map
      :value: None



   .. py:attribute:: _links
      :value: None



   .. py:attribute:: _joints
      :value: None



   .. py:attribute:: virtual_joint_names
      :value: []



   .. py:attribute:: _meshes_dir
      :type:  typing_extensions.Optional[str]
      :value: None



   .. py:method:: merge_description(other: ObjectDescription, parent_link: typing_extensions.Optional[str] = None, child_link: typing_extensions.Optional[str] = None, joint_type: pycram.datastructures.enums.JointType = JointType.FIXED, axis: typing_extensions.Optional[pycram.datastructures.pose.Point] = None, lower_limit: typing_extensions.Optional[float] = None, upper_limit: typing_extensions.Optional[float] = None, child_pose_wrt_parent: typing_extensions.Optional[pycram.datastructures.pose.PoseStamped] = None, in_place: bool = False, new_description_file: typing_extensions.Optional[str] = None) -> typing_extensions.Union[ObjectDescription, typing_extensions.Self]
      :abstractmethod:


      Merge the description of this object with the description of the other object.

      :param other: The object description to merge with this one.
      :param parent_link: The name of the parent link of the joint connecting the two objects.
      :param child_link: The name of the child link of the joint connecting the two objects.
      :param joint_type: The type of the joint connecting the two objects.
      :param axis: The axis of the joint connecting the two objects.
      :param lower_limit: The lower limit of the joint connecting the two objects.
      :param upper_limit: The upper limit of the joint connecting the two objects.
      :param child_pose_wrt_parent: The pose of the child link with respect to the parent link.
      :param in_place: True if the merge should be done in place, False otherwise.
      :param new_description_file: If given, the new description will be saved to this file, otherwise the new
          description will be saved in place of the original file.
      :return: The merged object description, could be a new object description if in_place is False else self.



   .. py:property:: mesh_dir
      :type: typing_extensions.Optional[str]



   .. py:property:: child_map
      :type: typing_extensions.Dict[str, typing_extensions.List[typing_extensions.Tuple[str, str]]]


      :return: A dictionary mapping the name of a link to its children which are represented as a tuple of the child
          joint name and the link name.



   .. py:method:: _construct_child_map() -> typing_extensions.Dict[str, typing_extensions.List[typing_extensions.Tuple[str, str]]]

      Construct the child map of the object.



   .. py:property:: parent_map
      :type: typing_extensions.Dict[str, typing_extensions.Tuple[str, str]]


      :return: A dictionary mapping the name of a link to its parent joint and link as a tuple.



   .. py:method:: _construct_parent_map() -> typing_extensions.Dict[str, typing_extensions.Tuple[str, str]]

      Construct the parent map of the object.



   .. py:property:: link_map
      :type: typing_extensions.Dict[str, LinkDescription]


      :return: A dictionary mapping the name of a link to its description.



   .. py:property:: joint_map
      :type: typing_extensions.Dict[str, JointDescription]


      :return: A dictionary mapping the name of a joint to its description.



   .. py:method:: add_joint(name: str, child: str, joint_type: pycram.datastructures.enums.JointType, axis: pycram.datastructures.pose.Point, parent: typing_extensions.Optional[str] = None, origin: typing_extensions.Optional[pycram.datastructures.pose.PoseStamped] = None, lower_limit: typing_extensions.Optional[float] = None, upper_limit: typing_extensions.Optional[float] = None, is_virtual: typing_extensions.Optional[bool] = False) -> None

      Finds the child link and adds a joint to it in the object description.
      for arguments documentation see :meth:`pycram.description.ObjectDescription.add_joint`



   .. py:method:: load_description(path) -> dm_control.mjcf.RootElement

      Load the description from the file at the given path.

      :param path: The path to the source file, if only a filename is provided then the resources directories will be
       searched.



   .. py:method:: load_description_from_string(description_string: str) -> dm_control.mjcf.RootElement

      Load the description from the given string.

      :param description_string: The description string to load from.



   .. py:method:: generate_from_mesh_file(path: str, name: str, color: typing_extensions.Optional[pycram.datastructures.dataclasses.Color] = Color(), save_path: typing_extensions.Optional[str] = None) -> None

      Generate a mjcf xml file with the given .obj or .stl file as mesh. In addition, use the given rgba_color
       to create a material tag in the xml.

      :param path: The path to the mesh file.
      :param name: The name of the object.
      :param color: The color of the object.
      :param save_path: The path to save the generated xml file.



   .. py:method:: generate_from_description_file(path: str, save_path: str, make_mesh_paths_absolute: bool = True) -> None

      Preprocess the given file and return the preprocessed description string. The preprocessed description will be
      saved at the given save_path.

      :param path: The path of the file to preprocess.
      :param save_path: The path to save the preprocessed description file.
      :param make_mesh_paths_absolute: Whether to make the mesh paths absolute.



   .. py:method:: replace_relative_paths_with_absolute_paths(model_path: str) -> str

      Replace the relative paths in the xml file to be absolute paths.

      :param model_path: The path to the xml file.



   .. py:method:: generate_from_parameter_server(name: str, save_path: str) -> None

      Preprocess the description from the ROS parameter server and return the preprocessed description string.
      The preprocessed description will be saved at the given save_path.

      :param name: The name of the description on the parameter server.
      :param save_path: The path to save the preprocessed description file.



   .. py:property:: joints
      :type: typing_extensions.List[JointDescription]


      :return: A list of joints descriptions of this object.



   .. py:property:: links
      :type: typing_extensions.List[LinkDescription]


      :return: A list of link descriptions of this object.



   .. py:method:: get_root() -> str

      :return: the name of the root link of this object.



   .. py:method:: get_tip() -> str

      :return: the name of the tip link of this object.
      :raises MultiplePossibleTipLinks: If there are multiple possible tip links.



   .. py:method:: get_chain(start_link_name: str, end_link_name: str, joints: typing_extensions.Optional[bool] = True, links: typing_extensions.Optional[bool] = True, fixed: typing_extensions.Optional[bool] = True) -> typing_extensions.List[str]

      :param start_link_name: The name of the start link of the chain.
      :param end_link_name: The name of the end link of the chain.
      :param joints: Whether to include joints in the chain.
      :param links: Whether to include links in the chain.
      :param fixed: Whether to include fixed joints in the chain (Note: not used in MJCF).
      :return: the chain of links from 'start_link_name' to 'end_link_name'.



   .. py:method:: get_file_extension() -> str
      :staticmethod:


      :return: The file extension of the URDF file.



   .. py:property:: origin
      :type: pycram.datastructures.pose.PoseStamped


      :return: the origin of this entity.



   .. py:property:: name
      :type: str


      :return: the name of this entity.



.. py:function:: parse_pose_from_body_element(body: dm_control.mjcf.Element) -> pycram.datastructures.pose.PoseStamped

   Parse the pose from a body element.

   :param body: The body element.
   :return: The pose of the body.


