概述
本文介绍基于宇树 G1 人形机器人的 VR 遥操作(XR Teleoperation)与 LeRobot 框架集成的开发流程。内容涵盖环境配置、遥操作程序部署、数据采集、格式转换及策略训练。
一、基于宇树开源的 XR 遥操作程序
1.1 Ubuntu、双臂逆运动学环境配置、unitree_sdk2_python 配置
在 Ubuntu 20.04 或 22.04 操作系统下进行测试。
安装 unitree_sdk2_python 库:
git clone https://github.com/unitreerobotics/unitree_sdk2_python.git
cd unitree_sdk2_python
pip install -e .
双臂逆运动学环境配置:
conda create -n tv python=3.8
conda activate tv
conda install pinocchio -c conda-forge
pip install meshcat
pip install casadi
注意:使用 pip 安装的 pinocchio 需确保版本为 3.1.0。
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 安装包并解压,执行 pip install -e .。
1.2.2 证书生成相关配置
由于苹果不允许在非 HTTPS 连接上使用 WebXR,需要创建自签名证书。
brew install mkcert
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
sudo apt-get install build-essential procps curl file git
cd ~
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> $HOME/.bash_profile
生成证书:
mkcert -CAROOT
sudo ufw allow 8012
mkcert -install && mkcert -cert-file cert.pem -key-file key.pem 192.168.123.2 localhost 127.0.0.1
cp cert.pem key.pem ~/avp_teleoperate/teleop/
1.2.3 启用 Apple Vision Pro 的 WebXR 相关功能
设置 >> Apps >> Safari 浏览器 >> 高级 >> 功能标志 >> 启用 WebXR 相关功能。 启动程序:
cd ~/avp_teleoperate/teleop
python teleop_hand.py
打开浏览器输入 https://192.168.123.2:8012?ws=wss://192.168.123.2: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 开启灵巧手服务
下载灵巧手控制接口程序并编译:
sudo apt install libboost-all-dev libspdlog-dev
cd h1_inspire_service & mkdir build & cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
sudo ./inspire_hand -s /dev/ttyUSB0
./h1_hand_example
1.4.2 开启图像推流服务 image_server
将 image_server.py 拷贝到机器人 PC2 中执行:
python image_server.py
1.4.3 启动遥操作程序
确保 G1 进入调试模式(阻尼:长按 L2 + 单击 B)。
python teleop_hand_and_arm.py --arm=G1_29 --hand=dex3 --record
根据机器人配置选择不同的启动参数。
1.5 avp_teleoperate 与 OpenTeleVision 的差异对比
| 特性 | avp_teleoperate | OpenTeleVision |
|---|---|---|
| 项目定位 | Unitree 专用,支持 G1/H1 等机型 | 学术研究,通用远程操作框架 |
| 核心架构 | 分层设计(图像、姿态、控制) | 模块化(模仿学习、远程操作) |
| 技术实现 | Pinocchio IK,专用控制器 | WebRTC,ACT/DETR 模型 |
二、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:
git clone https://github.com/unitreerobotics/unitree_sdk2_python.git
cd unitree_sdk2_python
pip install -e .
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
启动遥操:
cd ~/xr_teleoperate/teleop
python teleop_hand_and_arm.py --xr-mode=hand --arm=G1_29 --ee=dex3 --sim --record
2.3 真机部署
2.3.1 图像服务
将 image_server.py 复制到机器人 PC2 并执行。
2.3.2 BrainCo 手部服务
sudo ./brainco_hand --id 126 --serial /dev/ttyUSB1
sudo ./brainco_hand --id 127 --serial /dev/ttyUSB2
2.3.3 启动遥操
确保机器人进入调试模式(L2+R2)。开启运动控制模式时需注意手柄按键定义。
三、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 数据采集
加载 HuggingFace 数据集:
from lerobot.common.datasets.lerobot_dataset import LeRobotDataset
dataset = LeRobotDataset(repo_id="unitreerobotics/G1_ToastedBread_Dataset")
可视化:
cd unitree_lerobot/lerobot
python lerobot/scripts/visualize_dataset.py \
--repo-id unitreerobotics/G1_ToastedBread_Dataset \
--episode-index 0
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 或 ACT 类似。
3.2.2 真机测试
python unitree_lerobot/eval_robot/eval_g1/eval_g1.py \
--policy.path=unitree_lerobot/lerobot/outputs/train/... \
--repo_id=unitreerobotics/G1_ToastedBread_Dataset


