pycram.object_descriptors.mjcf#
Classes#
A class that represents a link description of an object. |
|
A class that represents the description of a joint. |
|
Create MJCF object descriptions from mesh files. |
|
Create MJCF object descriptions from mesh files. |
|
A class that represents an object description of an object. |
Functions#
Parse the pose from a body element. |
Module Contents#
- class pycram.object_descriptors.mjcf.LinkDescription(mjcf_description: dm_control.mjcf.Element, mesh_dir: typing_extensions.Optional[str] = None)#
Bases:
pycram.description.LinkDescriptionA class that represents a link description of an object.
- mesh_dir = None#
- property geometry: typing_extensions.Union[typing_extensions.List[pycram.datastructures.dataclasses.VisualShape], pycram.datastructures.dataclasses.VisualShape, None]#
- Returns:
The geometry type of the collision element of this link.
- _get_visual_shape(mjcf_geometry) typing_extensions.Union[pycram.datastructures.dataclasses.VisualShape, None]#
- Parameters:
mjcf_geometry – The MJCFGeometry to get the visual shape for.
- Returns:
The VisualShape of the given MJCFGeometry object.
- look_for_file_in_mesh_dir(file_name: str) str#
Look for a file in the mesh directory of the object.
- Parameters:
file_name – The name of the file.
- Returns:
The path to the file.
- property origin: typing_extensions.Union[pycram.datastructures.pose.PoseStamped, None]#
- Returns:
The origin of this link.
- property name: str#
- Returns:
the name of this entity.
- class pycram.object_descriptors.mjcf.JointDescription(mjcf_description: dm_control.mjcf.Element, is_virtual: typing_extensions.Optional[bool] = False)#
Bases:
pycram.description.JointDescriptionA class that represents the description of a joint.
- mjcf_type_map#
A dictionary mapping the MJCF joint types to the PyCRAM joint types.
- pycram_type_map#
A dictionary mapping the PyCRAM joint types to the MJCF joint types.
- property origin: pycram.datastructures.pose.PoseStamped#
- Returns:
the origin of this entity.
- property name: str#
- Returns:
the name of this entity.
- property has_limits: bool#
- Returns:
True if the joint has limits, False otherwise.
- property type: pycram.datastructures.enums.JointType#
- Returns:
The type of this joint.
- property axis: pycram.datastructures.pose.Point#
- Returns:
The axis of this joint, for example the rotation axis for a revolute joint.
- property lower_limit: typing_extensions.Union[float, None]#
- Returns:
The lower limit of this joint, or None if the joint has no limits.
- property upper_limit: typing_extensions.Union[float, None]#
- Returns:
The upper limit of this joint, or None if the joint has no limits.
- property parent: str#
- Returns:
The name of the parent link of this joint.
- property child: str#
- Returns:
The name of the child link of this joint.
- property _parent_link_element: dm_control.mjcf.Element#
- property damping: float#
- Returns:
The damping of this joint.
- property friction: float#
- Abstractmethod:
- Returns:
The friction of this joint.
- class pycram.object_descriptors.mjcf.ObjectFactory(file_path: str, config: multiverse_parser.Configuration)#
Bases:
multiverse_parser.FactoryCreate MJCF object descriptions from mesh files.
- from_mesh_file(object_name: str, texture_type: str = 'png')#
- static add_material_with_texture(geom_builder: multiverse_parser.GeomBuilder, material_name: str, texture_file_path: str)#
Add a material with a texture to the geom builder.
- Parameters:
geom_builder – The geom builder to add the material to.
material_name – The name of the material.
texture_file_path – The path to the texture file.
- export_to_mjcf(output_file_path: str)#
Export the object to a MJCF file.
- Parameters:
output_file_path – The path to the output file.
- class pycram.object_descriptors.mjcf.PrimitiveObjectFactory(object_name: str, shape_data: pycram.datastructures.dataclasses.VisualShapeUnion, save_path: str, orientation: typing_extensions.Optional[typing_extensions.List[float]] = None)#
Bases:
ObjectFactoryCreate MJCF object descriptions from mesh files.
- shape_data: pycram.datastructures.dataclasses.VisualShapeUnion#
- orientation: typing_extensions.List[float] = [0, 0, 0, 1]#
- build_shape()#
- class pycram.object_descriptors.mjcf.ObjectDescription#
Bases:
pycram.description.ObjectDescriptionA class that represents an object description of an object.
- COMPILER_TAG = 'compiler'#
The tag of the compiler element in the MJCF file.
- MESH_DIR_ATTR = 'meshdir'#
- TEXTURE_DIR_ATTR = '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.
- 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:
pycram.description.ObjectDescription.Link,LinkDescriptionA link of an Object in the World.
- class RootLink(obj: pycram.world_concepts.world_object.Object)#
Bases:
pycram.description.ObjectDescription.RootLink,LinkThe 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.
- 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:
pycram.description.ObjectDescription.Joint,JointDescriptionRepresent a joint of an Object in the World.
- _link_map = None#
- _joint_map = None#
- _child_map = None#
- _parent_map = None#
- _links = None#
- _joints = None#
- virtual_joint_names = []#
- _meshes_dir: typing_extensions.Optional[str] = None#
- abstract 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]#
Merge the description of this object with the description of the other object.
- Parameters:
other – The object description to merge with this one.
parent_link – The name of the parent link of the joint connecting the two objects.
child_link – The name of the child link of the joint connecting the two objects.
joint_type – The type of the joint connecting the two objects.
axis – The axis of the joint connecting the two objects.
lower_limit – The lower limit of the joint connecting the two objects.
upper_limit – The upper limit of the joint connecting the two objects.
child_pose_wrt_parent – The pose of the child link with respect to the parent link.
in_place – True if the merge should be done in place, False otherwise.
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.
- Returns:
The merged object description, could be a new object description if in_place is False else self.
- property mesh_dir: typing_extensions.Optional[str]#
- property child_map: typing_extensions.Dict[str, typing_extensions.List[typing_extensions.Tuple[str, str]]]#
- Returns:
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.
- _construct_child_map() typing_extensions.Dict[str, typing_extensions.List[typing_extensions.Tuple[str, str]]]#
Construct the child map of the object.
- property parent_map: typing_extensions.Dict[str, typing_extensions.Tuple[str, str]]#
- Returns:
A dictionary mapping the name of a link to its parent joint and link as a tuple.
- _construct_parent_map() typing_extensions.Dict[str, typing_extensions.Tuple[str, str]]#
Construct the parent map of the object.
- property link_map: typing_extensions.Dict[str, LinkDescription]#
- Returns:
A dictionary mapping the name of a link to its description.
- property joint_map: typing_extensions.Dict[str, JointDescription]#
- Returns:
A dictionary mapping the name of a joint to its description.
- 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
pycram.description.ObjectDescription.add_joint()
- load_description(path) dm_control.mjcf.RootElement#
Load the description from the file at the given path.
- Parameters:
path – The path to the source file, if only a filename is provided then the resources directories will be searched.
- load_description_from_string(description_string: str) dm_control.mjcf.RootElement#
Load the description from the given string.
- Parameters:
description_string – The description string to load from.
- 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.
- Parameters:
path – The path to the mesh file.
name – The name of the object.
color – The color of the object.
save_path – The path to save the generated xml file.
- 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.
- Parameters:
path – The path of the file to preprocess.
save_path – The path to save the preprocessed description file.
make_mesh_paths_absolute – Whether to make the mesh paths absolute.
- replace_relative_paths_with_absolute_paths(model_path: str) str#
Replace the relative paths in the xml file to be absolute paths.
- Parameters:
model_path – The path to the xml file.
- 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.
- Parameters:
name – The name of the description on the parameter server.
save_path – The path to save the preprocessed description file.
- property joints: typing_extensions.List[JointDescription]#
- Returns:
A list of joints descriptions of this object.
- property links: typing_extensions.List[LinkDescription]#
- Returns:
A list of link descriptions of this object.
- get_root() str#
- Returns:
the name of the root link of this object.
- get_tip() str#
- Returns:
the name of the tip link of this object.
- Raises:
MultiplePossibleTipLinks – If there are multiple possible tip links.
- 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]#
- Parameters:
start_link_name – The name of the start link of the chain.
end_link_name – The name of the end link of the chain.
joints – Whether to include joints in the chain.
links – Whether to include links in the chain.
fixed – Whether to include fixed joints in the chain (Note: not used in MJCF).
- Returns:
the chain of links from ‘start_link_name’ to ‘end_link_name’.
- static get_file_extension() str#
- Returns:
The file extension of the URDF file.
- property origin: pycram.datastructures.pose.PoseStamped#
- Returns:
the origin of this entity.
- property name: str#
- Returns:
the name of this entity.
- pycram.object_descriptors.mjcf.parse_pose_from_body_element(body: dm_control.mjcf.Element) pycram.datastructures.pose.PoseStamped#
Parse the pose from a body element.
- Parameters:
body – The body element.
- Returns:
The pose of the body.