align terrain settings to go2_rl_gym.

This commit is contained in:
wertyuilife
2026-04-14 21:10:13 +08:00
parent f011fcc9e5
commit a401337bb2
2 changed files with 41 additions and 102 deletions

View File

@@ -392,7 +392,9 @@ class Go2RLGymCommandCfg(CommandTermCfg):
terrain_max_command_ranges: dict[str, dict] = { terrain_max_command_ranges: dict[str, dict] = {
'wave': 'wave':
{'lin_vel_x': [-1.5, 1.5], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, {'lin_vel_x': [-1.5, 1.5], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]},
'slope': 'slope_up':
{'lin_vel_x': [-1.5, 1.5], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]},
'slope_down':
{'lin_vel_x': [-1.5, 1.5], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, {'lin_vel_x': [-1.5, 1.5], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]},
'rough_slope': 'rough_slope':
{'lin_vel_x': [-1.5, 1.5], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, {'lin_vel_x': [-1.5, 1.5], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]},
@@ -402,10 +404,10 @@ class Go2RLGymCommandCfg(CommandTermCfg):
{'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, {'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]},
'obstacles': 'obstacles':
{'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, {'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]},
# 'stepping_stones': 'stepping_stones':
# {'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, {'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]},
# 'gap': 'gap':
# {'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]}, {'lin_vel_x': [-1.0, 1.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-1.5, 1.5]},
'flat': 'flat':
{'lin_vel_x': [-2.0, 2.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-2.0, 2.0]}, {'lin_vel_x': [-2.0, 2.0], 'lin_vel_y': [-1.0, 1.0], 'ang_vel_yaw': [-2.0, 2.0]},
} }

View File

@@ -70,43 +70,6 @@ DEFAULT_TERRAIN_CFG = terrain_gen.TerrainGeneratorCfg(
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Gym-aligned terrain setup # Gym-aligned terrain setup
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
def _signed_pyramid_slope_height_field(
difficulty: float,
cfg: terrain_gen.HfPyramidSlopedTerrainCfg,
random_inverted: bool,
) -> np.ndarray:
"""Generate a pyramid slope with optional random sign."""
slope = cfg.slope_range[0] + difficulty * (cfg.slope_range[1] - cfg.slope_range[0])
if random_inverted and np.random.rand() < 0.5:
slope = -slope
width_pixels = int(cfg.size[0] / cfg.horizontal_scale)
length_pixels = int(cfg.size[1] / cfg.horizontal_scale)
height_max = int(slope * cfg.size[0] / 2 / cfg.vertical_scale)
center_x = int(width_pixels / 2)
center_y = int(length_pixels / 2)
x = np.arange(0, width_pixels)
y = np.arange(0, length_pixels)
xx, yy = np.meshgrid(x, y, sparse=True)
xx = (center_x - np.abs(center_x - xx)) / center_x
yy = (center_y - np.abs(center_y - yy)) / center_y
xx = xx.reshape(width_pixels, 1)
yy = yy.reshape(1, length_pixels)
hf_raw = height_max * xx * yy
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_raw[x_pf, y_pf]
hf_raw = np.clip(hf_raw, min(0, z_pf), max(0, z_pf))
return np.rint(hf_raw).astype(np.int16)
@height_field_to_mesh @height_field_to_mesh
def wave_terrain(difficulty: float, cfg) -> np.ndarray: def wave_terrain(difficulty: float, cfg) -> np.ndarray:
"""wave terrain: wave plus random uniform roughness.""" """wave terrain: wave plus random uniform roughness."""
@@ -115,22 +78,16 @@ def wave_terrain(difficulty: float, cfg) -> np.ndarray:
return np.rint(wave + rough).astype(np.int16) return np.rint(wave + rough).astype(np.int16)
@height_field_to_mesh
def slope_terrain(difficulty: float, cfg) -> np.ndarray:
"""slope terrain with 50/50 positive and negative slopes."""
return _signed_pyramid_slope_height_field(difficulty, cfg, random_inverted=True)
@height_field_to_mesh @height_field_to_mesh
def rough_slope_terrain(difficulty: float, cfg) -> np.ndarray: def rough_slope_terrain(difficulty: float, cfg) -> np.ndarray:
"""rough slope terrain: slope plus random uniform roughness.""" """rough slope terrain: slope plus random uniform roughness."""
slope = _signed_pyramid_slope_height_field(difficulty, cfg, random_inverted=False) slope = hf_terrains.pyramid_sloped_terrain.__wrapped__(difficulty, cfg)
rough = hf_terrains.random_uniform_terrain.__wrapped__(difficulty, cfg) rough = hf_terrains.random_uniform_terrain.__wrapped__(difficulty, cfg)
return np.rint(slope + rough).astype(np.int16) return np.rint(slope + rough).astype(np.int16)
@configclass @configclass
class WaveTerrainCfg(terrain_gen.HfTerrainBaseCfg): class WaveTerrainCfg(terrain_gen.HfWaveTerrainCfg):
function = wave_terrain function = wave_terrain
amplitude_range: tuple[float, float] = (0.1, 0.28) amplitude_range: tuple[float, float] = (0.1, 0.28)
num_waves: int = 5 num_waves: int = 5
@@ -140,14 +97,7 @@ class WaveTerrainCfg(terrain_gen.HfTerrainBaseCfg):
@configclass @configclass
class SlopeTerrainCfg(terrain_gen.HfTerrainBaseCfg): class RoughSlopeTerrainCfg(terrain_gen.HfPyramidSlopedTerrainCfg):
function = slope_terrain
slope_range: tuple[float, float] = (0.1, 0.568)
platform_width: float = 3.0
@configclass
class RoughSlopeTerrainCfg(terrain_gen.HfTerrainBaseCfg):
function = rough_slope_terrain function = rough_slope_terrain
slope_range: tuple[float, float] = (0.1, 0.568) slope_range: tuple[float, float] = (0.1, 0.568)
platform_width: float = 3.0 platform_width: float = 3.0
@@ -163,49 +113,42 @@ TERRAIN_CFG = terrain_gen.TerrainGeneratorCfg(
num_cols=20, num_cols=20,
horizontal_scale=0.1, horizontal_scale=0.1,
vertical_scale=0.005, vertical_scale=0.005,
slope_threshold=0.75, slope_threshold=2.0,
use_cache=False, use_cache=False,
sub_terrains={ sub_terrains={
"wave": WaveTerrainCfg( "wave": WaveTerrainCfg(
proportion=0.05, proportion=0.05,
border_width=0.0, border_width=0.5,
horizontal_scale=0.1,
vertical_scale=0.005,
slope_threshold=0.75,
), ),
"slope": SlopeTerrainCfg( "slope_up": terrain_gen.HfInvertedPyramidSlopedTerrainCfg(
proportion=0.20, proportion=0.10,
border_width=0.0, slope_range=(0.1, 0.568),
horizontal_scale=0.1, platform_width=3.0,
vertical_scale=0.005, border_width=0.5,
slope_threshold=0.75, ),
"slope_down": terrain_gen.HfPyramidSlopedTerrainCfg(
proportion=0.10,
slope_range=(0.1, 0.568),
platform_width=3.0,
border_width=0.5,
), ),
"rough_slope": RoughSlopeTerrainCfg( "rough_slope": RoughSlopeTerrainCfg(
proportion=0.05, proportion=0.05,
border_width=0.0, border_width=0.5,
horizontal_scale=0.1,
vertical_scale=0.005,
slope_threshold=0.75,
), ),
"stairs_up": terrain_gen.HfInvertedPyramidStairsTerrainCfg( "stairs_up": terrain_gen.HfInvertedPyramidStairsTerrainCfg(
proportion=0.25, proportion=0.25,
step_height_range=(0.05, 0.257), step_height_range=(0.05, 0.257),
step_width=0.31, step_width=0.31,
platform_width=3.0, platform_width=3.0,
border_width=0.0, border_width=0.5,
horizontal_scale=0.1,
vertical_scale=0.005,
slope_threshold=0.75,
), ),
"stairs_down": terrain_gen.HfPyramidStairsTerrainCfg( "stairs_down": terrain_gen.HfPyramidStairsTerrainCfg(
proportion=0.10, proportion=0.10,
step_height_range=(0.05, 0.257), step_height_range=(0.05, 0.257),
step_width=0.31, step_width=0.31,
platform_width=3.0, platform_width=3.0,
border_width=0.0, border_width=0.5,
horizontal_scale=0.1,
vertical_scale=0.005,
slope_threshold=0.75,
), ),
"obstacles": terrain_gen.HfDiscreteObstaclesTerrainCfg( "obstacles": terrain_gen.HfDiscreteObstaclesTerrainCfg(
proportion=0.20, proportion=0.20,
@@ -213,28 +156,22 @@ TERRAIN_CFG = terrain_gen.TerrainGeneratorCfg(
obstacle_height_range=(0.05, 0.275), obstacle_height_range=(0.05, 0.275),
num_obstacles=20, num_obstacles=20,
platform_width=3.0, platform_width=3.0,
border_width=0.0, border_width=0.5,
horizontal_scale=0.1, ),
vertical_scale=0.005, "stepping_stones": terrain_gen.HfSteppingStonesTerrainCfg(
slope_threshold=0.75, proportion=0.0,
stone_height_max=0.0,
stone_width_range=(0.075, 1.575),
stone_distance_range=(0.05, 0.10),
holes_depth=-10.0,
platform_width=4.0,
border_width=0.5,
),
"gap": terrain_gen.MeshGapTerrainCfg(
proportion=0.0,
gap_width_range=(0.0, 0.9),
platform_width=3.0,
), ),
# "stepping_stones": terrain_gen.HfSteppingStonesTerrainCfg(
# proportion=0.0,
# stone_height_max=0.0,
# stone_width_range=(0.075, 1.575),
# stone_distance_range=(0.05, 0.10),
# holes_depth=-10.0,
# platform_width=4.0,
# border_width=0.0,
# horizontal_scale=0.1,
# vertical_scale=0.005,
# slope_threshold=0.75,
# ),
# "gap": terrain_gen.MeshGapTerrainCfg(
# proportion=0.0,
# gap_width_range=(0.0, 0.9),
# platform_width=3.0,
# ),
"flat": terrain_gen.MeshPlaneTerrainCfg(proportion=0.15), "flat": terrain_gen.MeshPlaneTerrainCfg(proportion=0.15),
}, },
) )