本指南介绍在使用 LeRobot 框架进行人在回路(HIL)强化学习时,如何使用 gym_hil simulation environment 作为真实机器人的替代方案。
gym_hil 是一个提供与 Gymnasium 兼容的 simulation environment 的软件包,专为人在回路强化学习设计。这些环境让你能够:
在 simulation 中训练 policy,以便在真实机器人上训练之前先测试 RL 技术栈
使用游戏手柄或键盘等外部设备在 simulation 中采集 demonstration
在 policy learning 过程中执行人工干预
目前主要环境是基于 MuJoCo 的 Franka Panda 机器人 simulation,任务包括抓取方块等。
首先,在 LeRobot 环境中安装 gym_hil 软件包:
pip install -e ".[hilserl]"要配合 LeRobot 使用 gym_hil,你需要创建一个配置文件。示例见此处。关键配置部分包括:
{
"env": {
"type": "gym_manipulator",
"name": "gym_hil",
"task": "PandaPickCubeGamepad-v0",
"fps": 10
},
"device": "cuda"
}可用任务:
PandaPickCubeBase-v0:基础环境PandaPickCubeGamepad-v0:带游戏手柄控制PandaPickCubeKeyboard-v0:带键盘控制{
"env": {
"processor": {
"control_mode": "gamepad",
"gripper": {
"use_gripper": true,
"gripper_penalty": -0.02
},
"reset": {
"control_time_s": 15.0,
"fixed_reset_joint_positions": [
0.0, 0.195, 0.0, -2.43, 0.0, 2.62, 0.785
]
},
"inverse_kinematics": {
"end_effector_step_sizes": {
"x": 0.025,
"y": 0.025,
"z": 0.025
}
}
}
}
}重要参数:
gripper.gripper_penalty:gripper 过度移动的惩罚gripper.use_gripper:是否启用 gripper 控制inverse_kinematics.end_effector_step_sizes:end-effector 在 x、y、z 轴上的步长大小control_mode:设为 "gamepad" 以使用游戏手柄控制器要运行环境,将 mode 设为 null:
python -m lerobot.rl.gym_manipulator --config_path path/to/gym_hil_env.json
要采集 dataset,将 mode 设为 record,同时定义 repo_id 和要录制的 episode 数:
{
"env": {
"type": "gym_manipulator",
"name": "gym_hil",
"task": "PandaPickCubeGamepad-v0"
},
"dataset": {
"repo_id": "username/sim_dataset",
"root": null,
"task": "pick_cube",
"num_episodes_to_record": 10,
"replay_episode": null,
"push_to_hub": true
},
"mode": "record"
}python -m lerobot.rl.gym_manipulator --config_path path/to/gym_hil_env.json
要训练 policy,请查看此处的配置示例,并运行 actor 和 learner 服务器:
python -m lerobot.rl.actor --config_path path/to/train_gym_hil_env.json
在另一个终端中,运行 learner 服务器:
python -m lerobot.rl.learner --config_path path/to/train_gym_hil_env.json
simulation environment 提供了一种安全且可重复的方式,让你在部署到真实机器人之前开发和测试人在回路强化学习组件。
恭喜 🎉,你已完成本教程!
如有任何问题或需要帮助,请在 Discord 上联系我们。
论文引用:
@article{luo2024precise,
title={Precise and Dexterous Robotic Manipulation via Human-in-the-Loop Reinforcement Learning},
author={Luo, Jianlan and Xu, Charles and Wu, Jeffrey and Levine, Sergey},
journal={arXiv preprint arXiv:2410.21845},
year={2024}
}