add joint_pos_penalty_l1 for better performance.

This commit is contained in:
wertyuilife
2026-04-20 14:59:34 +08:00
parent ee962954cb
commit 34ba7465a9
2 changed files with 14 additions and 4 deletions

View File

@@ -366,7 +366,7 @@ class RewardsCfg:
# Thus, we need to use a smaller weight for the dof_acc_l2 term in Lab compared to Gym. # Thus, we need to use a smaller weight for the dof_acc_l2 term in Lab compared to Gym.
dof_acc_l2 = RewTerm( dof_acc_l2 = RewTerm(
func=mdp.joint_acc_l2, func=mdp.joint_acc_l2,
weight=-1.0e-7, # gym和lab的dof_acc reward实现尺度不一样lab是physic step level的由于l2对于离群值的敏感性会导致更大的惩罚 weight=-1.0e-7,
params={"asset_cfg": SceneEntityCfg("robot", joint_names=JOINT_NAMES)} params={"asset_cfg": SceneEntityCfg("robot", joint_names=JOINT_NAMES)}
) )
joint_power = RewTerm( joint_power = RewTerm(
@@ -419,6 +419,17 @@ class RewardsCfg:
"command_threshold": 0.1, "command_threshold": 0.1,
}, },
) )
joint_pos_penalty_l1 = RewTerm(
func=mdp.joint_pos_penalty_l1,
weight=-0.02,
params={
"command_name": "base_velocity",
"asset_cfg": SceneEntityCfg("robot", joint_names=".*_(thigh|calf)_joint"),
"stand_still_scale": 1.0,
"velocity_threshold": 0.1,
"command_threshold": 0.1,
},
)
@configclass @configclass
class TerminationsCfg: class TerminationsCfg:

View File

@@ -109,7 +109,7 @@ def stand_still(
return reward return reward
def joint_pos_penalty( def joint_pos_penalty_l1(
env: ManagerBasedRLEnv, env: ManagerBasedRLEnv,
command_name: str, command_name: str,
asset_cfg: SceneEntityCfg, asset_cfg: SceneEntityCfg,
@@ -123,14 +123,13 @@ def joint_pos_penalty(
cmd = torch.linalg.norm(env.command_manager.get_command(command_name), dim=1) cmd = torch.linalg.norm(env.command_manager.get_command(command_name), dim=1)
body_vel = torch.linalg.norm(asset.data.root_lin_vel_b[:, :2], dim=1) body_vel = torch.linalg.norm(asset.data.root_lin_vel_b[:, :2], dim=1)
running_reward = torch.linalg.norm( running_reward = torch.linalg.norm(
(asset.data.joint_pos[:, asset_cfg.joint_ids] - asset.data.default_joint_pos[:, asset_cfg.joint_ids]), dim=1 (asset.data.joint_pos[:, asset_cfg.joint_ids] - asset.data.default_joint_pos[:, asset_cfg.joint_ids]), dim=1, ord=1
) )
reward = torch.where( reward = torch.where(
torch.logical_or(cmd > command_threshold, body_vel > velocity_threshold), torch.logical_or(cmd > command_threshold, body_vel > velocity_threshold),
running_reward, running_reward,
stand_still_scale * running_reward, stand_still_scale * running_reward,
) )
reward *= torch.clamp(-env.scene["robot"].data.projected_gravity_b[:, 2], 0, 0.7) / 0.7
return reward return reward