From db01a64f72efdea8e04581cedab12eb0ec89a838 Mon Sep 17 00:00:00 2001 From: xuxin <747302550@qq.com> Date: Tue, 27 Jan 2026 15:11:49 +0800 Subject: [PATCH] Adds rough slope terrain --- CONTRIBUTORS.md | 1 + .../terrains/height_field/__init__.py | 4 +++- .../terrains/height_field/hf_terrains.py | 20 ++++++++++++++++++- .../terrains/height_field/hf_terrains_cfg.py | 16 ++++++++++++++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index b906922b291..54330358d01 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -145,6 +145,7 @@ Guidelines for modifications: * Xavier Nal * Xinjie Yao * Xinpeng Liu +* Xin Xu * Yang Jin * Yanzi Zhu * Yijie Guo diff --git a/source/isaaclab/isaaclab/terrains/height_field/__init__.py b/source/isaaclab/isaaclab/terrains/height_field/__init__.py index 589798cf25b..cabe219e66b 100644 --- a/source/isaaclab/isaaclab/terrains/height_field/__init__.py +++ b/source/isaaclab/isaaclab/terrains/height_field/__init__.py @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2025, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). +# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause @@ -29,9 +29,11 @@ HfDiscreteObstaclesTerrainCfg, HfInvertedPyramidSlopedTerrainCfg, HfInvertedPyramidStairsTerrainCfg, + HfInvertedRoughSlopeTerrainCfg, HfPyramidSlopedTerrainCfg, HfPyramidStairsTerrainCfg, HfRandomUniformTerrainCfg, + HfRoughSlopeTerrainCfg, HfSteppingStonesTerrainCfg, HfTerrainBaseCfg, HfWaveTerrainCfg, diff --git a/source/isaaclab/isaaclab/terrains/height_field/hf_terrains.py b/source/isaaclab/isaaclab/terrains/height_field/hf_terrains.py index d9ff255c3b5..07b893fc40e 100644 --- a/source/isaaclab/isaaclab/terrains/height_field/hf_terrains.py +++ b/source/isaaclab/isaaclab/terrains/height_field/hf_terrains.py @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2025, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). +# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause @@ -148,6 +148,24 @@ def pyramid_sloped_terrain(difficulty: float, cfg: hf_terrains_cfg.HfPyramidSlop return np.rint(hf_raw).astype(np.int16) +@height_field_to_mesh +def rough_slope_terrain(difficulty: float, cfg: hf_terrains_cfg.HfRoughSlopeTerrainCfg) -> np.ndarray: + # combine the two methods + terrain1 = pyramid_sloped_terrain.__wrapped__(difficulty, cfg) + terrain2 = random_uniform_terrain.__wrapped__(difficulty, cfg) + hf = terrain1 + terrain2 + + # the platform at center do not need to be rough + width_pixels = int(cfg.size[0] / cfg.horizontal_scale) + length_pixels = int(cfg.size[1] / cfg.horizontal_scale) + platform_width = int(cfg.platform_width / cfg.horizontal_scale / 2) + x_pf = width_pixels // 2 - platform_width + y_pf = length_pixels // 2 - platform_width + z_pf = hf[x_pf, y_pf] + hf = np.clip(hf, min(0, z_pf), max(0, z_pf)) + return hf + + @height_field_to_mesh def pyramid_stairs_terrain(difficulty: float, cfg: hf_terrains_cfg.HfPyramidStairsTerrainCfg) -> np.ndarray: """Generate a terrain with a pyramid stair pattern. diff --git a/source/isaaclab/isaaclab/terrains/height_field/hf_terrains_cfg.py b/source/isaaclab/isaaclab/terrains/height_field/hf_terrains_cfg.py index 8fd49077aa2..5213fb4849a 100644 --- a/source/isaaclab/isaaclab/terrains/height_field/hf_terrains_cfg.py +++ b/source/isaaclab/isaaclab/terrains/height_field/hf_terrains_cfg.py @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2025, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). +# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause @@ -91,6 +91,20 @@ class HfInvertedPyramidSlopedTerrainCfg(HfPyramidSlopedTerrainCfg): inverted: bool = True +@configclass +class HfRoughSlopeTerrainCfg(HfRandomUniformTerrainCfg, HfPyramidSlopedTerrainCfg): + "rough slope cfg, combine the cfg of random terrain and smooth slope terrain" + + function = hf_terrains.rough_slope_terrain + + +@configclass +class HfInvertedRoughSlopeTerrainCfg(HfRandomUniformTerrainCfg, HfInvertedPyramidSlopedTerrainCfg): + "rough slope cfg, combine the cfg of random terrain and smooth slope terrain" + + function = hf_terrains.rough_slope_terrain + + @configclass class HfPyramidStairsTerrainCfg(HfTerrainBaseCfg): """Configuration for a pyramid stairs height field terrain."""