Skip to content

[Bug Report] base_height_l2 for rough terrain is wrong! #1698

Open
@fan-ziqi

Description

@fan-ziqi

Describe the bug

The code added in #1525 is wrong!

Also marked in #1546

def base_height_l2(
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:
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]
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_link_pos_w[:, 2] - adjusted_target_height)

sensor.data.pos_w[:, 2] is the position of sensor origin in world frame, and it is equal to asset.data.root_link_pos_w[:, 2].

In rough terrain, the func return

torch.square(asset.data.root_link_pos_w[:, 2] - adjusted_target_height)
= torch.square(asset.data.root_link_pos_w[:, 2] - target_height - sensor.data.pos_w[:, 2])
= torch.square(- target_height)

This is meaningless.

I think we should take the height of the center point as the reference height, but this cannot be achieved with the current API.

Checklist

  • I have checked that there is no similar issue in the repo (required)
  • I have checked that the issue is not in running Isaac Sim itself and is related to the repo

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions