Object Model
The MujocoObject
class serves as a catch-all base class that is used to capture individual simulation objects to
instantiate within a given simulation. This is done in one of two ways via extended classes – the MujocoXMLObject
reads in information from a corresponding object XML file, whereas the MujocoGeneratedObject
proecedurally generates a
custom object using a suite of utility mj modeling functions. In conjunction with the RobotModel
, and
Arena
classes, these classes serve as the basis for forming the higher level Task
class which is used to
ultimately generate the MjSim
simulation object.
Base Object Model
- class robosuite.models.objects.objects.MujocoObject(obj_type='all', duplicate_collision_geoms=True)
Base class for all objects.
We use Mujoco Objects to implement all objects that:
may appear for multiple times in a task
can be swapped between different tasks
Typical methods return copy so the caller can all joints/attributes as wanted
- Parameters
obj_type (str) –
Geom elements to generate / extract for this object. Must be one of:
- ’collision’
Only collision geoms are returned (this corresponds to group 0 geoms)
- ’visual’
Only visual geoms are returned (this corresponds to group 1 geoms)
- ’all’
All geoms are returned
duplicate_collision_geoms (bool) – If set, will guarantee that each collision geom has a visual geom copy
- __init__(obj_type='all', duplicate_collision_geoms=True)
- merge_assets(other)
Merges @other’s assets in a custom logic.
- Parameters
other (MujocoXML or MujocoObject) – other xml file whose assets will be merged into this one
- get_obj()
Returns the generated / extracted object, in XML ElementTree form.
- Returns
Object in XML form.
- Return type
ET.Element
- exclude_from_prefixing(inp)
A function that should take in either an ET.Element or its attribute (str) and return either True or False, determining whether the corresponding name / str to @inp should have naming_prefix added to it. Must be defined by subclass.
- Parameters
inp (ET.Element or str) – Element or its attribute to check for prefixing.
- Returns
True if we should exclude the associated name(s) with @inp from being prefixed with naming_prefix
- Return type
bool
- _get_object_subtree()
Returns a ET.Element It is a <body/> subtree that defines all collision and / or visualization related fields of this object. Return should be a copy. Must be defined by subclass.
- Returns
body
- Return type
ET.Element
- _get_object_properties()
Helper function to extract relevant object properties (bodies, joints, contact/visual geoms, etc…) from this object’s XML tree. Assumes the self._obj attribute has already been filled.
- property important_geoms
Returns: dict: (Default is no important geoms; i.e.: empty dict)
- property important_sites
Returns: dict:
- obj
Object default site
- property important_sensors
Returns: dict: (Default is no sensors; i.e.: empty dict)
- property get_site_attrib_template
Returns attribs of spherical site used to mark body origin
- Returns
Dictionary of default site attributes
- Return type
dict
- property get_joint_attrib_template
Returns attribs of free joint
- Returns
Dictionary of default joint attributes
- Return type
dict
XML Object Model
- class robosuite.models.objects.objects.MujocoXMLObject(fname, name, joints='default', obj_type='all', duplicate_collision_geoms=True)
MujocoObjects that are loaded from xml files (by default, inherit all properties (e.g.: name) from MujocoObject class first!)
- Parameters
fname (str) – XML File path
name (str) – Name of this MujocoXMLObject
joints (None or str or list of dict) – each dictionary corresponds to a joint that will be created for this object. The dictionary should specify the joint attributes (type, pos, etc.) according to the MuJoCo xml specification. If “default”, a single free-joint will be automatically generated. If None, no joints will be created.
obj_type (str) –
Geom elements to generate / extract for this object. Must be one of:
- ’collision’
Only collision geoms are returned (this corresponds to group 0 geoms)
- ’visual’
Only visual geoms are returned (this corresponds to group 1 geoms)
- ’all’
All geoms are returned
duplicate_collision_geoms (bool) – If set, will guarantee that each collision geom has a visual geom copy
- __init__(fname, name, joints='default', obj_type='all', duplicate_collision_geoms=True)
- static _duplicate_visual_from_collision(element)
Helper function to duplicate a geom element to be a visual element. Namely, this corresponds to the following attribute requirements: group=1, conaffinity/contype=0, no mass, name appended with “_visual”
- Parameters
element (ET.Element) – element to duplicate as a visual geom
- Returns
duplicated element
- Return type
element (ET.Element)
- _get_geoms(root, _parent=None)
Helper function to recursively search through element tree starting at @root and returns a list of (parent, child) tuples where the child is a geom element
- Parameters
root (ET.Element) – Root of xml element tree to start recursively searching through
_parent (ET.Element) – Parent of the root element tree. Should not be used externally; only set during the recursive call
- Returns
array of (parent, child) tuples where the child element is a geom type
- Return type
list
Generated Object Model
- class robosuite.models.objects.objects.MujocoGeneratedObject(obj_type='all', duplicate_collision_geoms=True)
Base class for all procedurally generated objects.
- Parameters
obj_type (str) –
Geom elements to generate / extract for this object. Must be one of:
- ’collision’
Only collision geoms are returned (this corresponds to group 0 geoms)
- ’visual’
Only visual geoms are returned (this corresponds to group 1 geoms)
- ’all’
All geoms are returned
duplicate_collision_geoms (bool) – If set, will guarantee that each collision geom has a visual geom copy
- __init__(obj_type='all', duplicate_collision_geoms=True)
- sanity_check()
Checks if data provided makes sense. Called in __init__() For subclasses to inherit from
- static get_collision_attrib_template()
Generates template with collision attributes for a given geom
- Returns
Initial template with ‘pos’ and ‘group’ already specified
- Return type
dict
- static get_visual_attrib_template()
Generates template with visual attributes for a given geom
- Returns
Initial template with ‘conaffinity’, ‘contype’, and ‘group’ already specified
- Return type
dict
- append_material(material)
Adds a new texture / material combination to the assets subtree of this XML Input is expected to be a CustomMaterial object
See http://www.mujoco.org/book/XMLreference.html#asset for specific details on attributes expected for Mujoco texture / material tags, respectively
Note that the “file” attribute for the “texture” tag should be specified relative to the textures directory located in robosuite/models/assets/textures/
- Parameters
material (CustomMaterial) – Material to add to this object