From ca1eeadcf1f9f03a41b6fa4f63d0e1a144be0e8a Mon Sep 17 00:00:00 2001 From: Daniel Ordonez Date: Fri, 27 Oct 2023 12:55:50 +0200 Subject: [PATCH] Fix load robot cfg inheritance --- morpho_symm/cfg/robot/anymal_b-c2.yaml | 1 + morpho_symm/cfg/robot/anymal_c-c2.yaml | 1 + morpho_symm/cfg/robot/hyq-c2.yaml | 1 + morpho_symm/cfg/robot/mini_cheetah-c2.yaml | 1 + morpho_symm/cfg/robot/mini_cheetah-k4.yaml | 1 + morpho_symm/cfg/robot/solo-c2.yaml | 1 + morpho_symm/cfg/robot/solo-k4.yaml | 2 ++ morpho_symm/cfg/robot/ur10.yaml | 1 + morpho_symm/cfg/robot/ur3.yaml | 1 + morpho_symm/utils/robot_utils.py | 11 +++++------ 10 files changed, 15 insertions(+), 6 deletions(-) diff --git a/morpho_symm/cfg/robot/anymal_b-c2.yaml b/morpho_symm/cfg/robot/anymal_b-c2.yaml index c08cf69..6a77b15 100644 --- a/morpho_symm/cfg/robot/anymal_b-c2.yaml +++ b/morpho_symm/cfg/robot/anymal_b-c2.yaml @@ -1,5 +1,6 @@ defaults: - anymal_b + - _self_ name: anymal_b diff --git a/morpho_symm/cfg/robot/anymal_c-c2.yaml b/morpho_symm/cfg/robot/anymal_c-c2.yaml index 8876026..ac94f99 100644 --- a/morpho_symm/cfg/robot/anymal_c-c2.yaml +++ b/morpho_symm/cfg/robot/anymal_c-c2.yaml @@ -1,4 +1,5 @@ defaults: - anymal_c + - _self_ group_label: C2 \ No newline at end of file diff --git a/morpho_symm/cfg/robot/hyq-c2.yaml b/morpho_symm/cfg/robot/hyq-c2.yaml index 81ed22c..5d680b3 100644 --- a/morpho_symm/cfg/robot/hyq-c2.yaml +++ b/morpho_symm/cfg/robot/hyq-c2.yaml @@ -1,6 +1,7 @@ defaults: - hyq + - _self_ group_label: C2 diff --git a/morpho_symm/cfg/robot/mini_cheetah-c2.yaml b/morpho_symm/cfg/robot/mini_cheetah-c2.yaml index fcbe730..2c1a868 100644 --- a/morpho_symm/cfg/robot/mini_cheetah-c2.yaml +++ b/morpho_symm/cfg/robot/mini_cheetah-c2.yaml @@ -1,5 +1,6 @@ defaults: - mini_cheetah + - _self_ group_label: C2 \ No newline at end of file diff --git a/morpho_symm/cfg/robot/mini_cheetah-k4.yaml b/morpho_symm/cfg/robot/mini_cheetah-k4.yaml index 5d2689e..e2a56e2 100644 --- a/morpho_symm/cfg/robot/mini_cheetah-k4.yaml +++ b/morpho_symm/cfg/robot/mini_cheetah-k4.yaml @@ -1,5 +1,6 @@ defaults: - mini_cheetah + - _self_ group_label: K4 \ No newline at end of file diff --git a/morpho_symm/cfg/robot/solo-c2.yaml b/morpho_symm/cfg/robot/solo-c2.yaml index 7fecff4..627639c 100644 --- a/morpho_symm/cfg/robot/solo-c2.yaml +++ b/morpho_symm/cfg/robot/solo-c2.yaml @@ -1,6 +1,7 @@ defaults: - solo + - _self_ group_label: C2 diff --git a/morpho_symm/cfg/robot/solo-k4.yaml b/morpho_symm/cfg/robot/solo-k4.yaml index 202d69b..ab0f603 100644 --- a/morpho_symm/cfg/robot/solo-k4.yaml +++ b/morpho_symm/cfg/robot/solo-k4.yaml @@ -1,5 +1,7 @@ defaults: - solo + - _self_ + seed: 40 group_label: K4 diff --git a/morpho_symm/cfg/robot/ur10.yaml b/morpho_symm/cfg/robot/ur10.yaml index df054ce..319574a 100644 --- a/morpho_symm/cfg/robot/ur10.yaml +++ b/morpho_symm/cfg/robot/ur10.yaml @@ -1,5 +1,6 @@ defaults: - ur5 + - _self_ name: ur10 diff --git a/morpho_symm/cfg/robot/ur3.yaml b/morpho_symm/cfg/robot/ur3.yaml index 6155bba..ba2ac15 100644 --- a/morpho_symm/cfg/robot/ur3.yaml +++ b/morpho_symm/cfg/robot/ur3.yaml @@ -1,4 +1,5 @@ defaults: - ur5 + - _self_ name: ur3 diff --git a/morpho_symm/utils/robot_utils.py b/morpho_symm/utils/robot_utils.py index af2f002..280f625 100644 --- a/morpho_symm/utils/robot_utils.py +++ b/morpho_symm/utils/robot_utils.py @@ -84,13 +84,12 @@ def load_symmetric_system( assert robot_cfg is not None or robot_name is not None, \ "Either a robot configuration file or a robot name must be provided." if robot_cfg is None: + # Only robot name is provided. Load the robot configuration file using compose API from hydra. + # This allows to load the parent configuration files automatically. path_cfg = Path(morpho_symm.__file__).parent / 'cfg' / 'robot' - path_robot_cfg = path_cfg / f'{robot_name}.yaml' - assert path_robot_cfg.exists(), \ - f"Robot configuration {path_robot_cfg} does not exist." - base_cfg = OmegaConf.load(path_cfg / 'base_robot.yaml') - robot_cfg = OmegaConf.load(path_robot_cfg) - robot_cfg = OmegaConf.merge(base_cfg, robot_cfg) + from hydra import compose, initialize_config_dir + with initialize_config_dir(config_dir=str(path_cfg)): + robot_cfg = compose(config_name=robot_name) robot_name = str.lower(robot_cfg.name) # We allow symbolic expressions (e.g. `np.pi/2`) in the `q_zero` and `init_q`.