Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug of base_height_l2 reward function #1931

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Guidelines for modifications:
* Yujian Zhang
* Zhengyu Zhang
* Ziqi Fan
* Xu Liu

## Acknowledgements

Expand Down
16 changes: 15 additions & 1 deletion source/isaaclab/isaaclab/envs/mdp/rewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,21 @@ def base_height_l2(
if sensor_cfg is not None:
sensor: RayCaster = env.scene[sensor_cfg.name]
# Adjust the target height using the sensor data
adjusted_target_height = target_height + torch.mean(sensor.data.ray_hits_w[..., 2], dim=1)
ray_hits = sensor.data.ray_hits_w[..., 2]
if torch.isnan(ray_hits).any() or torch.isinf(ray_hits).any() or torch.max(torch.abs(ray_hits)) > 1e6:
num_nan = torch.sum(torch.isnan(ray_hits),dim=-1)
ray_hits[torch.isnan(ray_hits)] = 0.0
num_inf = torch.sum(torch.isinf(ray_hits),dim=-1)
ray_hits[torch.isinf(ray_hits)] = 0.0
num_outlier = torch.sum(torch.abs(ray_hits) > 1e6,dim=-1)
ray_hits[torch.abs(ray_hits) > 1e6] = 0.0
# Use the average of the valid ray hits to adjust the target height
adjusted_target_height = target_height + torch.sum(ray_hits,dim=-1) / (ray_hits.shape[1]-num_nan-num_inf-num_outlier)
# If all the ray hits are illegal, use the root link position
all_illegal_env = ((num_nan+num_inf+num_outlier)==ray_hits.shape[1])
adjusted_target_height[all_illegal_env] = asset.data.root_link_pos_w[all_illegal_env, 2]
else:
adjusted_target_height = target_height + torch.mean(ray_hits, dim=1)
else:
# Use the provided target height directly for flat terrain
adjusted_target_height = target_height
Expand Down