Skip to content

Add keyboard control for MuJoCo humanoid robot with PD stabilization - #7652

Merged
donghaiwang merged 1 commit into
OpenHUTB:mainfrom
HaiLang47:feature/mujoco01_keyboard_control
Oct 1, 2026
Merged

donghaiwang merged 1 commit into
OpenHUTB:mainfrom
HaiLang47:feature/mujoco01_keyboard_control

Conversation

@HaiLang47

Copy link
Copy Markdown
Contributor
  • main_keyboard_control.py: pygame keyboard control with PD controller
  • Use home keyframe qpos as target, keyboard input as offset
  • Pin root pose/velocity each step to keep robot stably standing
  • demo_keyboard.gif: screen recording showing keyboard control of all joints
  • README.md: add keyboard control section with operation table and PD principle

修改概述:

修改内容

为 src/mujoco01 模块添加基于 pygame 的键盘实时控制脚本,使用 PD 控制器保持人形机器人稳定姿态。

新增文件

  • main_keyboard_control.py:pygame 键盘监听 + MuJoCo 被动视图 + PD 力矩控制
  • demo_keyboard.gif:演示动图(键盘控制全身关节)

修改文件

  • README.md:新增"键盘控制"章节,包含操作说明表、PD 控制原理公式、演示动图

技术要点

  • PD 控制律:tau = Kp * (target - q) - Kd * q_dot,其中 target = home_qpos + keyboard_offset
  • 参数:Kp = 40.0,Kd = 4.0
  • 姿态稳定:MuJoCo humanoid 为纯力矩控制(motor actuator),双足站立本身不稳定。脚本每步仿真前强制重置 root 的 6 自由度位姿和速度为 home 关键帧值,使机器人悬空稳定站立,便于观察各关节响应
  • 键盘映射:
    • W/S:躯干前倾/后仰
    • A/D:躯干左转/右转
    • Q/E:抬右臂/抬左臂
    • R/F:屈右肘/屈左肘
    • Space:全部复位
    • ESC:退出

运行环境

  • Ubuntu 20.04 + conda 环境 carla(Python 3.10.21)
  • MuJoCo + pygame 2.6.1

运行方式

python main_keyboard_control.py

运行效果

demo

相关 PR

- main_keyboard_control.py: pygame keyboard control with PD controller
- Use home keyframe qpos as target, keyboard input as offset
- Pin root pose/velocity each step to keep robot stably standing
- demo_keyboard.gif: screen recording showing keyboard control of all joints
- README.md: add keyboard control section with operation table and PD principle
@donghaiwang
donghaiwang merged commit 6e8d8a1 into OpenHUTB:main Oct 1, 2026
1 check passed
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