Skip to content

Commit d7a158e

Browse files
fabinschstephane-caron
authored andcommitted
Load scene by default for mj models and allow variants
1 parent 1ef00c3 commit d7a158e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
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: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
def load_robot_description(
1818
description_name: str,
1919
commit: Optional[str] = None,
20+
variant: Optional[str] = "scene",
2021
) -> mujoco.MjModel:
2122
"""Load a robot description in MuJoCo.
2223
@@ -35,5 +36,19 @@ def load_robot_description(
3536
os.environ.pop("ROBOT_DESCRIPTION_COMMIT", None)
3637
if not hasattr(module, "MJCF_PATH"):
3738
raise ValueError(f"{description_name} is not an MJCF description")
38-
39-
return mujoco.MjModel.from_xml_path(module.MJCF_PATH)
39+
40+
def load_model_from_path(path):
41+
try:
42+
return mujoco.MjModel.from_xml_path(path)
43+
except ValueError:
44+
print(f"{path} not found. Loading default robot model.")
45+
return None
46+
model_path = module.MJCF_PATH
47+
if variant is not None:
48+
path_parts = model_path.split(os.sep)
49+
path_parts[-1] = f"{variant}.xml"
50+
variant_path = os.sep.join(path_parts)
51+
model = load_model_from_path(variant_path)
52+
if model:
53+
return model
54+
return load_model_from_path(model_path)

0 commit comments

Comments
 (0)