本帖最后由 十日无冬 于 2024-10-11 09:54 编辑
复杂地形之台阶
显然的,之前创建的jump_plat和jump_pit地形不足以满足地形训练的要求,为了能够加强机器人通过不同地形的能力,需要在更复杂的地形上进行训练。台阶地形是强化学习训练中一个重要的训练场景,可以有效的提升机器人的复杂地形适应性、平衡与协调能力、感知与决策精度,并增强策略的泛化能力,确保机器人在真实世界中的实用性和可靠性。
本节将会解析isaacgym/python/isaacgym路径下的terrain_utils.py文件中提供的台阶地形和金字塔形台阶地形。其中台阶地形的创建代码如下所示:
- def stairs_terrain(terrain, step_width, step_height):
- """
- Generate a stairs
- Parameters:
- terrain (terrain): the terrain
- step_width (float): the width of the step [meters]
- step_height (float): the height of the step [meters]
- Returns:
- terrain (SubTerrain): update terrain
- """
- # switch parameters to discrete units
- step_width = int(step_width / terrain.horizontal_scale)
- step_height = int(step_height / terrain.vertical_scale)
- num_steps = terrain.width // step_width
- height = step_height
- for i in range(num_steps):
- terrain.height_field_raw[i * step_width: (i + 1) * step_width, :] += height
- height += step_height
- return terrain
复制代码
和jump_plat类似,关键的部分就是对于height_field_raw的值进行修改。同样的,如果给定一个负的height,就可以创造一个下楼楼梯。
单个的台阶地形如下图:
复杂地形之金字塔台阶
在训练地形中直接使用台阶地形是不可取的,因为会出现地形不连续的情况,一块地形与其接壤的地形会出现非常大的高度差,导致机器人在训练中非常容易摔倒。这时我们就需要使用金字塔台阶来替代,多个金字塔地形接壤如下图所示:
金字塔形台阶的代码看起来似乎比较复杂,但是其内核还是对于height_field_raw的数值操作。
- def pyramid_stairs_terrain(terrain, step_width, step_height, platform_size=1.):
- """
- Generate stairs
- Parameters:
- terrain (terrain): the terrain
- step_width (float): the width of the step [meters]
- step_height (float): the step_height [meters]
- platform_size (float): size of the flat platform at the center of the terrain [meters]
- Returns:
- terrain (SubTerrain): update terrain
- """
- # switch parameters to discrete units
- step_width = int(step_width / terrain.horizontal_scale)
- step_height = int(step_height / terrain.vertical_scale)
- platform_size = int(platform_size / terrain.horizontal_scale)
- height = 0
- start_x = 0
- stop_x = terrain.width
- start_y = 0
- stop_y = terrain.length
- while (stop_x - start_x) > platform_size and (stop_y - start_y) > platform_size:
- start_x += step_width
- stop_x -= step_width
- start_y += step_width
- stop_y -= step_width
- height += step_height
- terrain.height_field_raw[start_x: stop_x, start_y: stop_y] = height
- return terrain
复制代码
可以看到,在每次while循环的迭代中:
start_x 和 start_y 增加 step_width,即从左下到中心(以上为x轴正方向,右为y轴正方向)。
stop_x 和 stop_y 减少 step_width,即从右上向中心。
height 增加 step_height,表示生成的阶梯高度不断增加。
最终生成一个阶梯状的金字塔结构。通过循环缩小地形的区域,并逐渐增加高度,最终形成一个中心为平台的阶梯状金字塔。逻辑图解如下:
|