Skip to content

Commit

Permalink
Adds RayCaster rough terrain base height to reward (#1525)
Browse files Browse the repository at this point in the history
# 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 <[email protected]>
Signed-off-by: Kelly Guo <[email protected]>
Co-authored-by: Kelly Guo <[email protected]>
Co-authored-by: Kelly Guo <[email protected]>
  • Loading branch information
3 people authored Dec 13, 2024
1 parent c9f6ac5 commit d8bc725
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Guidelines for modifications:
* Giulio Romualdi
* Haoran Zhou
* HoJin Jeon
* Hongwei Xiong
* Jan Kerner
* Jean Tampon
* Jia Lin Yuan
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/omni.isaac.lab/config/extension.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

# Note: Semantic Versioning is used: https://semver.org/
version = "0.27.25"
version = "0.27.26"

# Description
title = "Isaac Lab framework for Robot Learning"
Expand Down
11 changes: 11 additions & 0 deletions source/extensions/omni.isaac.lab/docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Changelog
---------

0.27.26 (2024-12-11)
~~~~~~~~~~~~~~~~~~~~

Changed
^^^^^^^

* Introduced an optional ``sensor_cfg`` parameter to the :meth:`~omni.isaac.lab.envs.mdp.rewards.base_height_l2` function, enabling the use of
:class:`~omni.isaac.lab.sensors.RayCaster` for height adjustments. For flat terrains, the function retains its previous behavior.
* 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.


0.27.25 (2024-12-11)
~~~~~~~~~~~~~~~~~~~~

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from omni.isaac.lab.managers import SceneEntityCfg
from omni.isaac.lab.managers.manager_base import ManagerTermBase
from omni.isaac.lab.managers.manager_term_cfg import RewardTermCfg
from omni.isaac.lab.sensors import ContactSensor
from omni.isaac.lab.sensors import ContactSensor, RayCaster

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


def base_height_l2(
env: ManagerBasedRLEnv, target_height: float, asset_cfg: SceneEntityCfg = SceneEntityCfg("robot")
env: ManagerBasedRLEnv,
target_height: float,
asset_cfg: SceneEntityCfg = SceneEntityCfg("robot"),
sensor_cfg: SceneEntityCfg | None = None,
) -> torch.Tensor:
"""Penalize asset height from its target using L2 squared kernel.
Note:
Currently, it assumes a flat terrain, i.e. the target height is in the world frame.
For flat terrain, target height is in the world frame. For rough terrain,
sensor readings can adjust the target height to account for the terrain.
"""
# extract the used quantities (to enable type-hinting)
asset: RigidObject = env.scene[asset_cfg.name]
# TODO: Fix this for rough-terrain.
return torch.square(asset.data.root_pos_w[:, 2] - target_height)
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 + sensor.data.pos_w[:, 2]
else:
# Use the provided target height directly for flat terrain
adjusted_target_height = target_height
# Compute the L2 squared penalty
return torch.square(asset.data.root_pos_w[:, 2] - adjusted_target_height)


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

0 comments on commit d8bc725

Please sign in to comment.