MuJoCo Utils#
Gymnasium-Planar-Robotics offers various MuJoCo utility functions that can help to develop your custom MuJoCo environments.
- gymnasium_planar_robotics.utils.mujoco_utils.set_actuator_ctrl(model: MjModel, data: MjData, actuator_name: str, value: float) None [source]
Set the control inputs for the desired actuator.
- Parameters:
model – the MuJoCo model (MjModel)
data – the MuJoCo data structure (MjData)
actuator_name – the name of the actuator for which to set the control input
value – the control input of the actuator
- gymnasium_planar_robotics.utils.mujoco_utils.get_joint_qacc(model: MjModel, data: MjData, name: str) ndarray [source]
Return the joint’s linear and angular acceleration (qacc) depending on the type of joint.
- Parameters:
model – mjModel of the MuJoCo environment
data – mjData of the MuJoCo environment
name – the name of the joint
- Returns:
the qacc of the joint
- gymnasium_planar_robotics.utils.mujoco_utils.get_mujoco_type_names(model: MjModel, obj_type: str, name_pattern: str = '') list[str] [source]
Return a list of names of the current model that belong to objects of the specified type and whose names match the given name_pattern.
- Parameters:
model – mjModel of the MuJoCo environment
obj_type – mjData of the MuJoCo environment
name_pattern – the pattern to search for in the object names, defaults to ‘’
- Returns:
a list of object names matching the name_pattern and the obj_type
Note
The following functions and classes are completely or at least partially adopted from gymnasium-robotics: Farama-Foundation/Gymnasium-Robotics
- gymnasium_planar_robotics.utils.mujoco_utils.set_joint_qpos(model: MjModel, data: MjData, name: str, value: float | ndarray) None [source]
Set the joint positions (qpos) of the model.
- Parameters:
model – mjModel of the MuJoCo environment
data – mjData of the MuJoCo environment
name – the name of the joint
value – the new qpos
- gymnasium_planar_robotics.utils.mujoco_utils.get_joint_qpos(model: MjModel, data: MjData, name: str) ndarray [source]
Return the joint’s position and orientation (qpos) depending on the type of the joint.
- Parameters:
model – mjModel of the MuJoCo environment
data – mjData of the MuJoCo environment
name – the name of the joint
- Returns:
the qpos of the joint
- gymnasium_planar_robotics.utils.mujoco_utils.set_joint_qvel(model: MjModel, data: MjData, name: str, value: float | ndarray) None [source]
Set the joints linear and angular (qvel) of the model.
- Parameters:
model – mjModel of the MuJoCo environment
data – mjData of the MuJoCo environment
name – the name of the joint
value – the new qvel
- gymnasium_planar_robotics.utils.mujoco_utils.get_joint_qvel(model: MjModel, data: MjData, name: str) ndarray [source]
Return the joint’s linear and angular velocities (qvel) depending on the type of the joint.
- Parameters:
model – mjModel of the MuJoCo environment
data – mjData of the MuJoCo environment
name – the name of the joint
- Returns:
the qvel of the joint
- gymnasium_planar_robotics.utils.mujoco_utils.extract_mj_names(model: MjModel, obj_type: mjtObj) tuple[tuple[str, ...] | tuple[()], dict[str, int], dict[int, str]] [source]
Extract the names and ids of the given object type from the current MuJoCo model.
- Raises:
ValueError – if the object type is not supported
- Returns:
the names, name2id and id2name dictionaries for the current object type
- class gymnasium_planar_robotics.utils.mujoco_utils.MujocoModelNames(model: MjModel)[source]
Access mjtObj object names and ids of the current MuJoCo model.
This class supports access to the names and ids of the following mjObj types:
mjOBJ_BODY
mjOBJ_JOINT
mjOBJ_GEOM
mjOBJ_SITE
mjOBJ_CAMERA
mjOBJ_ACTUATOR
mjOBJ_SENSOR
The properties provided for each
mjObj
are:mjObj
names: list of the mjObj names in the model of type mjOBJ_FOOmjObj
name2id: dictionary with name of the mjObj as keys and id of the mjObj as valuesmjObj
id2name: dictionary with id of the mjObj as keys and name of the mjObj as values
- property actuator_id2name: dict[int, str]
Return a dict containing id-name pairs of the actuators in the MuJoCo model.
- Returns:
dict with id-name pairs
- property actuator_name2id: dict[str, int]
Return a dict containing name-id pairs of the actuators in the MuJoCo model.
- Returns:
dict with name-id pairs
- property actuator_names: tuple[str, ...] | tuple[()]
Return a tuple of actuator names in the MuJoCo model.
- Returns:
actuator names
- property body_id2name: dict[int, str]
Return a dict containing id-name pairs of the bodies in the MuJoCo model.
- Returns:
dict with id-name pairs
- property body_name2id: dict[str, int]
Return a dict containing name-id pairs of the bodies in the MuJoCo model.
- Returns:
dict with name-id pairs
- property body_names: tuple[str, ...] | tuple[()]
Return a tuple of body names in the MuJoCo model.
- Returns:
body names
- property camera_id2name: dict[int, str]
Return a dict containing id-name pairs of the cameras in the MuJoCo model.
- Returns:
dict with id-name pairs
- property camera_name2id: dict[str, int]
Return a dict containing name-id pairs of the cameras in the MuJoCo model.
- Returns:
dict with name-id pairs
- property camera_names: tuple[str, ...] | tuple[()]
Return a tuple of camera names in the MuJoCo model.
- Returns:
camera names
- property geom_id2name: dict[int, str]
Return a dict containing id-name pairs of the geoms in the MuJoCo model.
- Returns:
dict with id-name pairs
- property geom_name2id: dict[str, int]
Return a dict containing name-id pairs of the geoms in the MuJoCo model.
- Returns:
dict with name-id pairs
- property geom_names: tuple[str, ...] | tuple[()]
Return a tuple of geom names in the MuJoCo model.
- Returns:
geom names
- property joint_id2name: dict[int, str]
Return a dict containing id-name pairs of the joints in the MuJoCo model.
- Returns:
dict with id-name pairs
- property joint_name2id: dict[str, int]
Return a dict containing name-id pairs of the joints in the MuJoCo model.
- Returns:
dict with name-id pairs
- property joint_names: tuple[str, ...] | tuple[()]
Return a tuple of joint names in the MuJoCo model.
- Returns:
joint names
- property sensor_id2name: dict[int, str]
Return a dict containing id-name pairs of the sensors in the MuJoCo model.
- Returns:
dict with id-name pairs
- property sensor_name2id: dict[str, int]
Return a dict containing name-id pairs of the sensors in the MuJoCo model.
- Returns:
dict with name-id pairs
- property sensor_names: tuple[str, ...] | tuple[()]
Return a tuple of sensor names in the MuJoCo model.
- Returns:
sensor names
- property site_id2name: dict[int, str]
Return a dict containing id-name pairs of the sites in the MuJoCo model.
- Returns:
dict with id-name pairs
- property site_name2id: dict[str, int]
Return a dict containing name-id pairs of the sites in the MuJoCo model.
- Returns:
dict with name-id pairs
- property site_names: tuple[str, ...] | tuple[()]
Return the site names in the MuJoCo model.
- Returns:
tuple of model site names