File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
robot_descriptions/loaders Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1717def 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 )
You can’t perform that action at this time.
0 commit comments