tools_mjcf
Helpers for inspecting and editing MuJoCo MJCF specifications.
This module contains utility functions for traversing MJCF body trees, querying actuator-to-joint relationships, attaching gripper specifications to robot models, and performing attribute replacements on serialized MJCF.
- robotblockset.mujoco.tools_mjcf.actuators_for_joint(joint: Any) List[Any][source]
Find all actuators in the same MJCF spec that are associated with a given joint.
- Parameters:
joint (Any) – A joint element from an MJCF Python spec (e.g. created via mjcf.RootElement() or loaded with mjcf.from_xml_path / MjSpec.from_file).
- Returns:
List of actuator elements (e.g. <motor>, <position>, <velocity>, <general>, …) that reference this joint.
- Return type:
list of mjcf.Element
- robotblockset.mujoco.tools_mjcf.print_body_tree_simple(parent: mujoco.MjsBody, level: int = 0) None[source]
Print the body tree starting from the given parent body.
Note that parent must be mjcf Python spec objects (MjcfElement / MjBody)
- Parameters:
parent (mujoco.MjsBody) – The parent body from which to start printing the body tree.
level (int, optional) – The current level in the body tree (used for indentation).
- Return type:
None
- robotblockset.mujoco.tools_mjcf.print_body_tree(parent: mujoco.MjsBody, spec: mujoco.MjSpec, level: int = 0) None[source]
Print the body tree starting from the given parent body, including joint types and associated actuator names (if any).
Note that parent must be an mjcf Python spec body object (MjBody from MjSpec).
- Parameters:
parent (mujoco.MjsBody) – The parent body from which to start printing the body tree.
spec (mujoco.MjSpec) – The full MJCF spec (used to search actuators).
level (int, optional) – The current level in the body tree (used for indentation).
- Return type:
None
- robotblockset.mujoco.tools_mjcf.attach_gripper_to_robot(robot_spec: mujoco.MjSpec, gripper_spec: mujoco.MjSpec, robot_site_name: str = 'gripper_mount', prefix: str = 'gripper-') Any | None[source]
Attach a gripper spec to a robot spec at a given mount site.
- Parameters:
robot_spec (mujoco.MjSpec) – Robot MJCF specification.
gripper_spec (mujoco.MjSpec) – Gripper MJCF specification.
robot_site_name (str, optional) – Name of the mounting site on the robot.
prefix (str, optional) – Prefix applied to gripper names to avoid clashes.
- Returns:
Attachment frame created at the mount site, or None if the site is missing.
- Return type:
object or None
- robotblockset.mujoco.tools_mjcf.replace_in_mjcf_file(spec: mujoco._specs.MjSpec, old: str, new: str, substring: bool = False) mujoco.MjSpec[source]
Replace attribute values in an MJCF specification and return a new spec.
- Parameters:
spec (mujoco.MjSpec) – Source MJCF specification to serialize and modify.
old (str) – Attribute value to replace.
new (str) – Replacement attribute value.
substring (bool, optional) – If True, replace matching substrings inside attribute values; otherwise require an exact match.
- Returns:
New MuJoCo specification parsed from the updated XML text.
- Return type:
mujoco.MjSpec
Functions
|
Find all actuators in the same MJCF spec that are associated with a given joint. |
|
Attach a gripper spec to a robot spec at a given mount site. |
|
Print the body tree starting from the given parent body, including joint types and associated actuator names (if any). |
|
Print the body tree starting from the given parent body. |
|
Replace attribute values in an MJCF specification and return a new spec. |