前言
本文解读基于宇树 G1 人形机器人的 VR 遥操作及模仿学习开发流程。涉及开源库 unitree_IL_lerobot 及遥操程序 xr_teleoperate(前身为 avp_teleoperate)。无论使用傅利叶集成的 idp3 还是宇树集成的 pi0,均可通过宇树开源的摇操代码收集数据。
第一部分 基于宇树开源的 avp(xr 以前的版本) 摇操程序
1.1 Ubuntu、双臂 inverse kinematics 环境配置、unitree_sdk2_python 配置
- 操作系统:Ubuntu 20.04 和 Ubuntu 22.04。
- 通信库:原
unitree_dds_wrapper已更新为 Python 版控制通信库unitree_sdk2_python。git clone https://github.com/unitreerobotics/unitree_sdk2_python.git
cd unitree_sdk2_python
pip install -e .
3. **逆运动学环境**:使用 pinocchio 和 CasADi 库加载 URDF 并进行逆运动学计算,meshcat 用于可视化调试。 bash
conda create -n tv python=3.8
conda activate tv
确保 pinocchio 版本为 3.1.0
conda install pinocchio -c conda-forge pip install meshcat pip install casadi ```
1.2 TeleVision 环境配置和 Apple Vision Pro 通信配置
1.2.1 基本环境配置和 Isaac Gym 安装
git clone https://github.com/unitreerobotics/avp_teleoperate.git
cd avp_teleoperate
pip install -r requirements.txt
下载 Isaac Gym 安装包并解压,在 isaacgym/python 目录下执行:
pip install -e .
1.2.2 证书生成相关配置
由于苹果不允许在非 HTTPS 连接上使用 WebXR,需创建自签名证书。
- 安装 mkcert:
brew install mkcert eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" sudo apt-get install build-essential procps curl file git - 生成证书:
mkcert -CAROOT # 将 rootCA.pem 发送到 Apple Vision Pro sudo ufw allow 8012 mkcert -install && mkcert -cert-file cert.pem -key-file key.pem <本机 IP> localhost 127.0.0.1 cp cert.pem key.pem ~/avp_teleoperate/teleop/
1.2.3 启用 Apple Vision Pro 的 WebXR 相关功能
设置 >> Apps >> Safari 浏览器 >> 高级 >> 功能标志 >> 启用 WebXR 相关功能。 启动 VR:
cd ~/avp_teleoperate/teleop
python teleop_hand.py
浏览器输入 https://<主机 IP>:8012?ws=wss://<主机 IP>:8012,点击 Enter VR。
1.3 硬件清单
| 物品名称 | 数量 | 说明 |
|---|---|---|
| Apple Vision Pro | 1 | 参考 Apple 官方网址 |
| 计算机 | 1 | x86_64 架构 |
| 人形机器人 H1/G1 | 1 | 具体型号 |
| 灵巧手 | 1 | Inspire Robotics (RH56DFX) 或 Unitree Dex3 |
| 头部双目相机 | 1 | USB 免驱动双目相机 |
| 手腕深度相机 D405 | 2 | Intel RealSense D405 |
1.4 启动程序
1.4.1 开启灵巧手服务
下载灵巧手控制接口程序,拷贝至机器人 PC2 中编译运行。
sudo ./inspire_hand -s /dev/ttyUSB0
./h1_hand_example
1.4.2 开启图像推流服务 image_server
将 image_server.py 拷贝到机器人 PC2 并执行:
python image_server.py
注意检查 OpenCV 读取参数及端口可用性。
1.4.3 启动遥操作程序
确保 G1 进入调试模式(L2+R2)。操作员 A 佩戴 XR 设备访问网页,操作员 B 在终端按 r 键启动。
# G1(29DoF) + Dex3-1
python teleop_hand_and_arm.py --arm=G1_29 --hand=dex3
# 开启录制
python teleop_hand_and_arm.py --arm=G1_23 --record
1.5 avp_teleoperate 与 OpenTeleVision 的差异对比
| 特性 | avp_teleoperate | OpenTeleVision |
|---|---|---|
| 定位 | 宇树专用,专注 VR 控制 | 学术研究,通用远程操作框架 |
| 架构 | 分层设计(图像、姿态、控制) | 模块化(模仿学习、远程操作) |
| 依赖 | 基于 OpenTeleVision 构建 | 原始项目 |
第二部分 xr_teleoperate:avp_teleoperate 的升级版
2.1 安装
conda create -n tv python=3.10 pinocchio=3.1.0 numpy=1.26.4 -c conda-forge
conda activate tv
git clone https://github.com/unitreerobotics/xr_teleoperate.git
cd xr_teleoperate
git submodule update --init --depth 1
cd teleop/televuer
pip install -e .
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout key.pem -out cert.pem
cd ../robot_control/dex-retargeting/
pip install -e .
cd ../../../
pip install -r requirements.txt
安装 unitree_sdk2_python 库。
2.2 仿真部署
安装 unitree_sim_isaaclab 并启动仿真环境:
conda activate unitree_sim_env
cd ~/unitree_sim_isaaclab
python sim_main.py --device cpu --enable_cameras --task Isaac-PickPlace-Cylinder-G129-Dex3-Joint --enable_dex3_dds --robot_type g129
启动遥操命令示例:
python teleop_hand_and_arm.py --xr-mode=hand --arm=G1_29 --ee=dex3 --sim --record
2.3 真机部署
- 图像服务:复制
image_server.py至 PC2 并运行。 - BrainCo 手部服务:手动启动两个巧手的服务。
sudo ./brainco_hand --id 126 --serial /dev/ttyUSB1 sudo ./brainco_hand --id 127 --serial /dev/ttyUSB2 - 启动遥操:确保机器人处于调试模式或运控模式,按 r 键启动。
第三部分 unitree_IL_lerobot 的安装与运行
3.1 环境安装与数据采集、转换
3.1.1 环境安装
git clone --recurse-submodules https://github.com/unitreerobotics/unitree_IL_lerobot.git
git submodule update --init --recursive
conda create -y -n unitree_lerobot python=3.10
conda activate unitree_lerobot
cd lerobot && pip install -e .
cd .. && pip install -e .
3.1.2 数据采集
可使用 avp/xr 现采数据,或从 HuggingFace 加载数据集:
from lerobot.common.datasets.lerobot_dataset import LeRobotDataset
dataset = LeRobotDataset(repo_id="unitreerobotics/G1_ToastedBread_Dataset")
3.1.3 数据转换
将 json 格式转换为 lerobot 格式:
python unitree_lerobot/utils/convert_unitree_json_to_lerobot.py \
--raw-dir $HOME/datasets/g1_grabcube_double_hand \
--repo-id your_name/g1_grabcube_double_hand \
--robot_type Unitree_G1_Dex3 \
--push_to_hub true
3.2 训练与测试
3.2.1 训练
# 训练 pi0
cd unitree_lerobot/lerobot
python lerobot/scripts/train.py --dataset.repo_id=unitreerobotics/G1_ToastedBread_Dataset --policy.type=pi0
# 训练 diffusion policy
python lerobot/scripts/train.py --dataset.repo_id=unitreerobotics/G1_ToastedBread_Dataset --policy.type=diffusion
# 训练 ACT
python lerobot/scripts/train.py --dataset.repo_id=unitreerobotics/G1_ToastedBread_Dataset --policy.type=act
3.2.2 真机测试
python unitree_lerobot/eval_robot/eval_g1/eval_g1.py \
--policy.path=<模型路径> \
--repo_id=unitreerobotics/G1_ToastedBread_Dataset


