Skip to content

Commit f1a1086

Browse files
Merge pull request #76 from fabinsch/mj_load_scene_variants
Allow loading variants for MuJoCo descriptions
2 parents 1ef00c3 + 88480cb commit f1a1086

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
77
### Added
88

99
- Description: UFACTORY xArm7 (MJCF) (thanks to @kevinzakka)
10+
- Description: accept variant keyword for mujoco loader (thanks to @fabinsch)
1011

1112
### Changed
1213

robot_descriptions/loaders/mujoco.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
def load_robot_description(
1818
description_name: str,
1919
commit: Optional[str] = None,
20+
variant: Optional[str] = None,
2021
) -> mujoco.MjModel:
2122
"""Load a robot description in MuJoCo.
2223
2324
Args:
2425
description_name: Name of the robot description.
2526
commit: If specified, check out that commit from the cloned robot
2627
description repository.
28+
variant: If specified, load a specific variant of the robot model.
2729
2830
Returns:
2931
Robot model for MuJoCo.
@@ -36,4 +38,19 @@ def load_robot_description(
3638
if not hasattr(module, "MJCF_PATH"):
3739
raise ValueError(f"{description_name} is not an MJCF description")
3840

39-
return mujoco.MjModel.from_xml_path(module.MJCF_PATH)
41+
def load_model_from_path(path):
42+
try:
43+
return mujoco.MjModel.from_xml_path(path)
44+
except ValueError:
45+
print(f"{path} not found. Loading default robot model.")
46+
return None
47+
48+
model_path = module.MJCF_PATH
49+
if variant is not None:
50+
path_parts = model_path.split(os.sep)
51+
path_parts[-1] = f"{variant}.xml"
52+
variant_path = os.sep.join(path_parts)
53+
model = load_model_from_path(variant_path)
54+
if model:
55+
return model
56+
return load_model_from_path(model_path)

0 commit comments

Comments
 (0)