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 actuators associated with an MJCF joint.
- Parameters:
joint (Any) – Joint element from an MJCF Python specification. The object is expected to provide
rootandnameattributes, as MuJoCo MJCF spec joint objects do.- Returns:
Actuator elements that reference
joint. MuJoCo actuator tags such asmotor,position,velocity, andgeneralare checked.- Return type:
list[Any]
- robotblockset.mujoco.tools_mjcf.print_body_tree_simple(parent: mujoco.MjsBody, level: int = 0) None[source]
Print a compact MJCF body tree.
- Parameters:
parent (mujoco.MjsBody) – MJCF body at which tree traversal starts.
level (int, optional) – Current indentation level. This is used internally during recursion.
- Returns:
The tree is written to standard output.
- Return type:
None
Notes
This helper prints body names and joint type suffixes only. Use
print_body_tree()when actuator names should also be included.
- robotblockset.mujoco.tools_mjcf.print_body_tree(parent: mujoco.MjsBody, spec: mujoco.MjSpec, level: int = 0) None[source]
Print an MJCF body tree with joint and actuator information.
- Parameters:
parent (mujoco.MjsBody) – MJCF body at which tree traversal starts.
spec (mujoco.MjSpec) – MJCF specification that owns
parent. Its actuators are searched to identify the actuator targeting each joint.level (int, optional) – Current indentation level. This is used internally during recursion.
- Returns:
The tree is written to standard output.
- 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 MJCF specification to a robot mount site.
- Parameters:
robot_spec (mujoco.MjSpec) – Robot MJCF specification to modify.
gripper_spec (mujoco.MjSpec) – Gripper MJCF specification to attach.
robot_site_name (str, optional) – Name of the site in
robot_specused as the attachment point.prefix (str, optional) – Prefix applied by MuJoCo to names imported from
gripper_spec.
- Returns:
Attachment frame returned by
mujoco.MjSpec.attach(), orNoneifrobot_site_nameis not found.- Return type:
Any or None
Notes
robot_specis modified in place by MuJoCo’s attach operation.
- robotblockset.mujoco.tools_mjcf.replace_in_mjcf_file(spec: mujoco.MjSpec, old: str, new: str, substring: bool = False) mujoco.MjSpec[source]
Replace XML attribute values in an MJCF specification.
- Parameters:
spec (mujoco.MjSpec) – Source MJCF specification to serialize before replacement.
old (str) – Attribute value to search for.
new (str) – Replacement attribute value.
substring (bool, optional) – If
True, replace matching substrings inside attribute values. IfFalse, replace only exact attribute-value matches.
- Returns:
New MJCF specification parsed from the updated XML text.
- Return type:
mujoco.MjSpec
- robotblockset.mujoco.tools_mjcf.add_polyline_to_scene(scene: mujoco_scene, name: str, points: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], radius: float = 0.004, rgba: Tuple[float, float, float, float] = (0.0, 1.0, 0.0, 1.0), group: int = 0, contype: int = 0, conaffinity: int = 0) mujoco_scene[source]
Add a polyline to a MuJoCo scene as capsule geoms.
The scene must have been loaded from XML so that
scene.specis available. The function copies the current specification, appends a named body containing one unnamed capsule geom per segment, recompiles the model, and replacesscene.modelandscene.data.- Parameters:
scene (mujoco_scene) – Scene object whose
spec,model, anddataattributes will be updated.name (str) – Name of the body that contains the generated capsule geoms.
points (ArrayLike) – Polyline vertices with shape
(N, 3). At least two points are required.radius (float, optional) – Capsule radius.
rgba (tuple[float, float, float, float], optional) – RGBA color applied to each capsule.
group (int, optional) – MuJoCo geom visualization group.
contype (int, optional) – MuJoCo collision type bitmask.
conaffinity (int, optional) – MuJoCo collision affinity bitmask.
- Returns:
The same scene object with updated specification, model, and data.
- Return type:
- Raises:
ValueError – If
scene.specis unavailable, ifnameis empty, or ifpointsis not an(N, 3)array withN >= 2.
Functions
|
Find actuators associated with an MJCF joint. |
|
Add a polyline to a MuJoCo scene as capsule geoms. |
|
Attach a gripper MJCF specification to a robot mount site. |
|
Print an MJCF body tree with joint and actuator information. |
|
Print a compact MJCF body tree. |
|
Replace XML attribute values in an MJCF specification. |