From 411236eb3c4d565cea851914dfdf9fc58706fbfa Mon Sep 17 00:00:00 2001 From: wertyuilife Date: Tue, 28 Apr 2026 14:10:04 +0800 Subject: [PATCH] replace joint_pos_limits reward with isaaclabs'; clean code; update readme. --- README.md | 3 +- .../robot_lab/robot_lab/tasks/go2/env_cfg.py | 6 ++-- .../robot_lab/tasks/go2/mdp/commands.py | 30 +++++++++---------- .../robot_lab/tasks/go2/mdp/rewards.py | 17 ----------- .../robot_lab/tasks/go2/mdp/terrains.py | 2 +- 5 files changed, 20 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 456e1b6..5166200 100644 --- a/README.md +++ b/README.md @@ -182,9 +182,10 @@ xml_path: "{ROOT_DIR}/resources/go2/your-custom-scene.xml" - Different tracking reward formulation (fixed sigma vs. dynamic sigma) - Different rewards: - - lower dof_acc_l2 weight in Lab due to physics-step level implementation and sensitivity to outliers + - lower joint_acc_l2 weight in Lab due to physics-step level implementation and sensitivity to outliers - extra joint_pos_penalty_l1 reward in Lab due to better performance - Lack domain_rand: randomize_motor_strength +- Extra domain_rand: randomize_com_positions_other (lead to better performance) --- diff --git a/source/robot_lab/robot_lab/tasks/go2/env_cfg.py b/source/robot_lab/robot_lab/tasks/go2/env_cfg.py index 225152c..30ff781 100644 --- a/source/robot_lab/robot_lab/tasks/go2/env_cfg.py +++ b/source/robot_lab/robot_lab/tasks/go2/env_cfg.py @@ -403,10 +403,10 @@ class RewardsCfg: weight=-1.0, params={"sensor_cfg": SceneEntityCfg("contact_forces", body_names=".*_thigh|.*_calf"), "threshold": 5.0}, ) - dof_pos_limits = RewTerm( - func=mdp.dof_pos_limits, + joint_pos_limits = RewTerm( + func=mdp.joint_pos_limits, weight=-2.0, - params={"asset_cfg": SceneEntityCfg("robot")}, + params={"asset_cfg": SceneEntityCfg("robot", joint_names=JOINT_NAMES)}, ) feet_regulation = RewTerm( func=mdp.feet_regulation, diff --git a/source/robot_lab/robot_lab/tasks/go2/mdp/commands.py b/source/robot_lab/robot_lab/tasks/go2/mdp/commands.py index 1ff2d1b..009473d 100644 --- a/source/robot_lab/robot_lab/tasks/go2/mdp/commands.py +++ b/source/robot_lab/robot_lab/tasks/go2/mdp/commands.py @@ -373,23 +373,8 @@ class Go2RLGymCommandCfg(CommandTermCfg): 'ang_vel_yaw': [-2.0, 2.0], # min max [rad/s] }] """List for command range curriculums at specific training iterations""" - # terrain_max_command_ranges: dict[str, dict] = { - # 'random_rough': - # {'lin_vel_x': [-1.5, 1.5], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, - # 'hf_pyramid_slope': - # {'lin_vel_x': [-1.5, 1.5], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, - # 'hf_pyramid_slope_inv': - # {'lin_vel_x': [-1.5, 1.5], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, - # 'pyramid_stairs': - # {'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, - # 'pyramid_stairs_inv': - # {'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, - # 'boxes': - # {'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, - # 'flat': - # {'lin_vel_x': [-2.0, 2.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-2.0, 2.0]}, - # } terrain_max_command_ranges: dict[str, dict] = { + #### go2 terrains #### 'wave': {'lin_vel_x': [-1.5, 1.5], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, 'slope_up': @@ -410,6 +395,19 @@ class Go2RLGymCommandCfg(CommandTermCfg): {'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, 'flat': {'lin_vel_x': [-2.0, 2.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-2.0, 2.0]}, + #### robotlab default terrains #### + 'random_rough': + {'lin_vel_x': [-1.5, 1.5], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, + 'hf_pyramid_slope': + {'lin_vel_x': [-1.5, 1.5], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, + 'hf_pyramid_slope_inv': + {'lin_vel_x': [-1.5, 1.5], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, + 'pyramid_stairs': + {'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, + 'pyramid_stairs_inv': + {'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, + 'boxes': + {'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, } resampling_time: float = 5.0 resampling_time_range: tuple[float, float] = (5.0, 5.0) diff --git a/source/robot_lab/robot_lab/tasks/go2/mdp/rewards.py b/source/robot_lab/robot_lab/tasks/go2/mdp/rewards.py index db979c9..2a248ee 100644 --- a/source/robot_lab/robot_lab/tasks/go2/mdp/rewards.py +++ b/source/robot_lab/robot_lab/tasks/go2/mdp/rewards.py @@ -605,20 +605,3 @@ def feet_regulation( reward = (feet_xy_vel_w.pow(2).sum(dim=-1) * torch.exp(-feet_height / (0.025 * base_height_target))).sum(dim=-1) return reward - -def dof_pos_limits( - env: ManagerBasedRLEnv, - asset_cfg: SceneEntityCfg = SceneEntityCfg("robot"), -) -> torch.Tensor: - asset = env.scene[asset_cfg.name] - - joint_pos = asset.data.joint_pos - joint_limits = asset.data.soft_joint_pos_limits - - lower = joint_limits[..., 0] - upper = joint_limits[..., 1] - - out_of_limits = -(joint_pos - lower).clamp(max=0.0) - out_of_limits += (joint_pos - upper).clamp(min=0.0) - - return torch.sum(out_of_limits, dim=1) diff --git a/source/robot_lab/robot_lab/tasks/go2/mdp/terrains.py b/source/robot_lab/robot_lab/tasks/go2/mdp/terrains.py index b09a4d9..c1b7651 100644 --- a/source/robot_lab/robot_lab/tasks/go2/mdp/terrains.py +++ b/source/robot_lab/robot_lab/tasks/go2/mdp/terrains.py @@ -92,7 +92,7 @@ DEFAULT_TERRAIN_CFG = terrain_gen.TerrainGeneratorCfg( # ----------------------------------------------------------------------------- -# Gym-aligned terrain setup +# Go2 Terrain setup # ----------------------------------------------------------------------------- @height_field_to_mesh def wave_terrain(difficulty: float, cfg) -> np.ndarray: