Skip to content

Commit d8bc725

Browse files
Adds RayCaster rough terrain base height to reward (#1525)
# Description Enhance `base_height_l2` function to support rough terrain adjustments: - Added an optional `sensor_cfg` parameter to allow dynamic target height adjustments based on sensor readings (e.g., RayCaster). - Updated the function to calculate the L2 squared penalty using adjusted height values for rough terrain scenarios. - Preserved existing behavior for flat terrain by using the fixed `target_height`. - Improved compatibility for applications involving uneven terrain. Fixes #1524 ## Type of change - New feature (non-breaking change which adds functionality) ## Checklist - [x ] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [x ] I have made corresponding changes to the documentation - [x ] My changes generate no new warnings - [x ] I have added tests that prove my fix is effective or that my feature works - [x ] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file - [x ] I have added my name to the `CONTRIBUTORS.md` or my name already exists there --------- Signed-off-by: Kelly Guo <kellyg@nvidia.com> Signed-off-by: Kelly Guo <kellyguo123@hotmail.com> Co-authored-by: Kelly Guo <kellyg@nvidia.com> Co-authored-by: Kelly Guo <kellyguo123@hotmail.com>
1 parent c9f6ac5 commit d8bc725

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Guidelines for modifications:
4949
* Giulio Romualdi
5050
* Haoran Zhou
5151
* HoJin Jeon
52+
* Hongwei Xiong
5253
* Jan Kerner
5354
* Jean Tampon
5455
* Jia Lin Yuan

source/extensions/omni.isaac.lab/config/extension.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
# Note: Semantic Versioning is used: https://semver.org/
4-
version = "0.27.25"
4+
version = "0.27.26"
55

66
# Description
77
title = "Isaac Lab framework for Robot Learning"

source/extensions/omni.isaac.lab/docs/CHANGELOG.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Changelog
22
---------
33

4+
0.27.26 (2024-12-11)
5+
~~~~~~~~~~~~~~~~~~~~
6+
7+
Changed
8+
^^^^^^^
9+
10+
* Introduced an optional ``sensor_cfg`` parameter to the :meth:`~omni.isaac.lab.envs.mdp.rewards.base_height_l2` function, enabling the use of
11+
:class:`~omni.isaac.lab.sensors.RayCaster` for height adjustments. For flat terrains, the function retains its previous behavior.
12+
* Improved documentation to clarify the usage of the :meth:`~omni.isaac.lab.envs.mdp.rewards.base_height_l2` function in both flat and rough terrain settings.
13+
14+
415
0.27.25 (2024-12-11)
516
~~~~~~~~~~~~~~~~~~~~
617

source/extensions/omni.isaac.lab/omni/isaac/lab/envs/mdp/rewards.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from omni.isaac.lab.managers import SceneEntityCfg
1919
from omni.isaac.lab.managers.manager_base import ManagerTermBase
2020
from omni.isaac.lab.managers.manager_term_cfg import RewardTermCfg
21-
from omni.isaac.lab.sensors import ContactSensor
21+
from omni.isaac.lab.sensors import ContactSensor, RayCaster
2222

2323
if TYPE_CHECKING:
2424
from omni.isaac.lab.envs import ManagerBasedRLEnv
@@ -98,17 +98,28 @@ def flat_orientation_l2(env: ManagerBasedRLEnv, asset_cfg: SceneEntityCfg = Scen
9898

9999

100100
def base_height_l2(
101-
env: ManagerBasedRLEnv, target_height: float, asset_cfg: SceneEntityCfg = SceneEntityCfg("robot")
101+
env: ManagerBasedRLEnv,
102+
target_height: float,
103+
asset_cfg: SceneEntityCfg = SceneEntityCfg("robot"),
104+
sensor_cfg: SceneEntityCfg | None = None,
102105
) -> torch.Tensor:
103106
"""Penalize asset height from its target using L2 squared kernel.
104107
105108
Note:
106-
Currently, it assumes a flat terrain, i.e. the target height is in the world frame.
109+
For flat terrain, target height is in the world frame. For rough terrain,
110+
sensor readings can adjust the target height to account for the terrain.
107111
"""
108112
# extract the used quantities (to enable type-hinting)
109113
asset: RigidObject = env.scene[asset_cfg.name]
110-
# TODO: Fix this for rough-terrain.
111-
return torch.square(asset.data.root_pos_w[:, 2] - target_height)
114+
if sensor_cfg is not None:
115+
sensor: RayCaster = env.scene[sensor_cfg.name]
116+
# Adjust the target height using the sensor data
117+
adjusted_target_height = target_height + sensor.data.pos_w[:, 2]
118+
else:
119+
# Use the provided target height directly for flat terrain
120+
adjusted_target_height = target_height
121+
# Compute the L2 squared penalty
122+
return torch.square(asset.data.root_pos_w[:, 2] - adjusted_target_height)
112123

113124

114125
def body_lin_acc_l2(env: ManagerBasedRLEnv, asset_cfg: SceneEntityCfg = SceneEntityCfg("robot")) -> torch.Tensor:

0 commit comments

Comments
 (0)