Skip to content

feat(go2):optimize the go2 Walk gait and increase the maximum command velocity. - #122

Open
daifawo wants to merge 15 commits into
Motphys:mainfrom
daifawo:feature/go2-walk-flat-improve
Open

daifawo wants to merge 15 commits into
Motphys:mainfrom
daifawo:feature/go2-walk-flat-improve

Conversation

@daifawo

@daifawo daifawo commented Oct 13, 2026 •

Copy link
Copy Markdown

Related to #118

摘要

将 Go2 平地行走任务从初始的通用 reward 配置,调整为面向步态稳定性、站立行为和足端横向摆动的可配置训练方案。

主要改动

1. 调整 Go2 平地任务的 reward 组合

最终 Go2 平地配置中显式调整或新增了以下 reward:

  • tracking_lin_vel=2.0
    • 改善速度跟踪性能,使策略更重视实际速度与指令速度之间的误差。
  • flat_orientation=-2.5
    • 根据机身重力方向在水平面的分量惩罚机身倾斜,抑制行走过程中的横滚和俯仰。
  • stand_still=-1.0
    • 当速度指令接近零时,惩罚关节姿态偏离默认站立姿态,避免机器人停止时保持异常姿态。
  • rear_swing_width
    • 对后足摆动期增加足端横向位置约束。
    • go2目标是后足在机身坐标系中的横向绝对位置约 0.145 m。
    • 使用容差 0.02 m,对于粗糙地形任务,显式关闭 foot_lateral_terms,避免限制机器人在不平地形上进行必要的足端落点调整。对偏离目标的横向摆动宽度施加惩罚。
    • 该项主要用于减少后足摆动时外扩的问题。

同时,reward 系统新增了以下可配置项,在后续真机部署时可能会用到:

  • feet_slide
    • 惩罚支撑期足端相对地面的滑动速度。
  • dof_acc
    • 惩罚关节加速度,减少高频关节抖动和不必要的冲击。
  • action_smoothness
    • 惩罚动作序列的二阶差分,减少控制输出突变。

这些 reward 已加入通用 QuadrupedWalkTask,但当前 Go2 平地最终配置中仅启用了实际需要的项;未启用的项保持零权重,不会改变当前训练目标。

2. 将足端横向约束做成通用配置

新增 FootLateralRewardCfg,支持:

  • 指定参与约束的足端;
  • 选择摆动期或支撑期;
  • 使用目标横向位置,或使用允许的横向宽度区间;
  • 配置横向位置容差和惩罚权重;
  • 可选配置足端横向速度惩罚。

这样足端横向约束位于通用四足行走任务中,具体机器人只需要在配置中声明需要的足端和目标范围。

3. 速度指令采样

在原有随机平面速度和站立指令之外,新增:

  • single_axis_probability
    • 以一定概率只采样一个运动轴,分别覆盖纯前进、纯侧向或纯旋转。
  • boundary_probability
    • 以一定概率直接采样速度范围边界,用于加强对速度上限和转向边界的训练。

这使训练数据同时覆盖一般随机运动、单轴运动、站立状态和指令边界。

4. 评估脚本

新增 scripts/play_walk.py,用于在关闭观测噪声和随机指令后,对策略进行固定指令评估。

评估指标主要包括:

  • vx、vy 和 yaw_rate 跟踪误差;
  • MAE、RMSE 和 P95 误差;
  • 机身姿态、高度变化和横向漂移;
  • 提前终止次数;
  • 四足足端横向位置、横向速度和摆动宽度;

当前仿真结果

在平地固定指令短窗口评估中,最终策略相较初始策略表现为:

  • vx=0.5 m/s:实际平均速度由约 0.251 m/s 提升到约 0.501 m/s;
  • vx=1.0 m/s:实际平均速度由约 0.415 m/s 提升到约 0.946 m/s;
  • vy=0.5 m/s:实际平均速度由约 0.132 m/s 提升到约 0.471 m/s;
  • yaw_rate=0.5 rad/s:在当前测试窗口内保持可跟踪;
  • 原训练指令范围内未观察到提前终止。

尚未完成

  • vx=1.25 m/s 和 vx=1.5 m/s 尚未通过当前跟踪门限;
  • 粗糙地形下的完整步态质量评估仍需补充;
  • 尚未完成Sim2Real 验证。

@daifawo daifawo changed the title feature(go2):optimize the go2 Walk gait and increase the maximum command velocity. feat(go2):optimize the go2 Walk gait and increase the maximum command velocity. Oct 13, 2026
Comment thread motrix_rl_rslrl/src/motrix_rl_rslrl/torch/wrap_np.py Outdated
Comment thread configs/play_walk.yaml Outdated
Comment thread scripts/play_walk.py Outdated

@wlgys8 wlgys8 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

静态代码审查:以下 4 项需要处理。未运行测试、训练或仿真。

Comment thread tests/test_play_walk_metrics.py Outdated
raise ImportError(f"Unable to load {SCRIPT}")
play_walk = importlib.util.module_from_spec(SPEC)
sys.modules[SPEC.name] = play_walk
SPEC.loader.exec_module(play_walk)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 补交评估脚本或同步移除对应测试

当前提交中已不存在 scripts/play_walk.py,但这里仍在模块顶层执行该文件。运行包含本测试的 pytest 时,会在 collection 阶段抛出 FileNotFoundError,导致测试收集失败,而不是仅跳过这几个测试。如果评估脚本已决定从本 PR 移除,请同步移除对应测试;否则需把脚本一并提交。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已移除scripts/play_walk.py及相关测试文件

"front_swing_width",
"front_stance_width",
} <= state.reward_terms.keys()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 移除对未配置前足 reward 的断言

当前 Go2 平地配置的 foot_lateral_terms 只有 rear_swing_width,运行时也只遍历已配置项生成 reward 键,因此这里要求的 front_swing_width 和 front_stance_width 不会出现,该测试会失败。建议通过显式构造 lateral reward 配置来测试通用计算和 phase mask,而不是绑定已经移除的任务 reward 组合。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前暂只使用rear_swing_width,已在测试文件中将front_swing_width 和 front_stance_width删除


_, _, _, extras = wrapped.step(torch.zeros((_NUM_ENVS, _ACT_DIM)))

assert extras["log"]["Tracking/vx_mae"].item() == pytest.approx(0.2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 将指标转发测试与实际 wrapper 行为保持一致

当前 RslrlNpEnvWrap.step() 只在 extras 中返回 time_outs,没有读取 state.metrics 或生成 log;本 PR 当前版本也没有对应 wrapper 修改。因此安装 RSLRL 后,此处会抛出 KeyError: 'log',Tracking 指标也不会经此 wrapper 进入日志。如果指标转发已决定不纳入本 PR,请同步移除本测试;否则需补上归约和转发实现,并保持张量 device 一致。

def _reward_feet_slide(self, linvel, gyro, dof_pos) -> np.ndarray:
del linvel, gyro, dof_pos
support = self.feet_contact
speed = np.linalg.norm((self.feet_pos - self._previous_feet_pos) / self.cfg.ctrl_dt, axis=2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 使用地面参考系速度计算 feet_slide

feet_pos 保存的是机身相对坐标(已有 swing-height 实现也明确说明这一点),它的差分不是足端相对地面的速度。机器人正常前进、支撑脚固定在地面时,脚在机身坐标系中仍向后移动,因此启用该项会惩罚正常无滑动支撑;脚与机身一起滑动时,相对坐标可能不变,实际滑动反而漏罚。建议使用世界坐标足端位置或速度计算接地足的地面切向速度,并覆盖“机身移动、脚的世界位置不变时不应罚滑动”的测试。当前默认零权重暂不影响默认训练,但启用此新增 reward 后会计算错误。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在cfg.py里为四个足端加入世界系 framepos 传感器,更改walk_np.py中feet_slide仅惩罚接触足的世界 XY 位移速度,并同步配置了 anymalc.py的自定义传感器,防止环境初始化错误

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants