返回列表 发布新帖

青龙机器人训练地形详解(三):复杂地形精讲之台阶

417 0
发表于 2024-10-11 09:35:48 | 查看全部 阅读模式
本帖最后由 十日无冬 于 2024-10-11 09:54 编辑

复杂地形之台阶
显然的,之前创建的jump_plat和jump_pit地形不足以满足地形训练的要求,为了能够加强机器人通过不同地形的能力,需要在更复杂的地形上进行训练。台阶地形是强化学习训练中一个重要的训练场景,可以有效的提升机器人的复杂地形适应性、平衡与协调能力、感知与决策精度,并增强策略的泛化能力,确保机器人在真实世界中的实用性和可靠性。

本节将会解析isaacgym/python/isaacgym路径下的terrain_utils.py文件中提供的台阶地形和金字塔形台阶地形。其中台阶地形的创建代码如下所示:
  1. def stairs_terrain(terrain, step_width, step_height):
  2.     """
  3.     Generate a stairs

  4.     Parameters:
  5.         terrain (terrain): the terrain
  6.         step_width (float):  the width of the step [meters]
  7.         step_height (float):  the height of the step [meters]
  8.     Returns:
  9.         terrain (SubTerrain): update terrain
  10.     """
  11.     # switch parameters to discrete units
  12.     step_width = int(step_width / terrain.horizontal_scale)
  13.     step_height = int(step_height / terrain.vertical_scale)

  14.     num_steps = terrain.width // step_width
  15.     height = step_height
  16.     for i in range(num_steps):
  17.         terrain.height_field_raw[i * step_width: (i + 1) * step_width, :] += height
  18.         height += step_height
  19.     return terrain
复制代码


和jump_plat类似,关键的部分就是对于height_field_raw的值进行修改。同样的,如果给定一个负的height,就可以创造一个下楼楼梯。
单个的台阶地形如下图:



复杂地形之金字塔台阶
在训练地形中直接使用台阶地形是不可取的,因为会出现地形不连续的情况,一块地形与其接壤的地形会出现非常大的高度差,导致机器人在训练中非常容易摔倒。这时我们就需要使用金字塔台阶来替代,多个金字塔地形接壤如下图所示:



金字塔形台阶的代码看起来似乎比较复杂,但是其内核还是对于height_field_raw的数值操作。
  1. def pyramid_stairs_terrain(terrain, step_width, step_height, platform_size=1.):
  2.     """
  3.     Generate stairs

  4.     Parameters:
  5.         terrain (terrain): the terrain
  6.         step_width (float):  the width of the step [meters]
  7.         step_height (float): the step_height [meters]
  8.         platform_size (float): size of the flat platform at the center of the terrain [meters]
  9.     Returns:
  10.         terrain (SubTerrain): update terrain
  11.     """
  12.     # switch parameters to discrete units
  13.     step_width = int(step_width / terrain.horizontal_scale)
  14.     step_height = int(step_height / terrain.vertical_scale)
  15.     platform_size = int(platform_size / terrain.horizontal_scale)

  16.     height = 0
  17.     start_x = 0
  18.     stop_x = terrain.width
  19.     start_y = 0
  20.     stop_y = terrain.length
  21.     while (stop_x - start_x) > platform_size and (stop_y - start_y) > platform_size:
  22.         start_x += step_width
  23.         stop_x -= step_width
  24.         start_y += step_width
  25.         stop_y -= step_width
  26.         height += step_height
  27.         terrain.height_field_raw[start_x: stop_x, start_y: stop_y] = height
  28.     return terrain
复制代码


可以看到,在每次while循环的迭代中:
    start_x 和 start_y 增加 step_width,即从左下到中心(以上为x轴正方向,右为y轴正方向)。
    stop_x 和 stop_y 减少 step_width,即从右上向中心。
    height 增加 step_height,表示生成的阶梯高度不断增加。
最终生成一个阶梯状的金字塔结构。通过循环缩小地形的区域,并逐渐增加高度,最终形成一个中心为平台的阶梯状金字塔。逻辑图解如下:


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Copyright © 2025 OPENLOONG. All Rights Reserved. Powered by Discuz!
  • 关注B站
  • 关注抖音
  • 关注微信公众号
Copyright © 2025 开发者论坛 - OpenLoong 版权所有 All Rights Reserved.
关灯 在本版发帖 返回顶部
快速回复 返回顶部 返回列表