Repository navigation
Feat/g1 native deploy - #142
Open
MrH-creater wants to merge 8 commits into
Open
MrH-creater wants to merge 8 commits into
MrH-creater wants to merge 8 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
G1 29-DOF Deployment Guide / 部署操作手册
Expand your preferred language below. / 请展开所需语言。
中文 — sim2sim / sim2real 部署操作手册
适用:MotrixLab
0.4.0,分支feat/g1-native-deploy。以下使用已经准备好的代码及两份 artifact,不包含大文件下载步骤。sim2sim 使用开发机现有环境;sim2real 包含机器人首次配置环境的步骤。仓库内命令均从仓库根目录执行,默认策略路径为
artifacts/g1-flat.deploy和artifacts/g1-wbt-dance.deploy。1. sim2sim:开发机运行
进入本地仓库,激活已安装
mxlab的环境。例如使用现有的motrix-lab环境:如果使用仓库内的
.venv,将激活环境的命令换成source .venv/bin/activate。需要指定策略路径时:
仿真窗口获得焦点后,使用以下按键:
1230或xW/S、A/D、Q/E在终端按
Ctrl+C结束运行。2. sim2real:配置 DDS 并运行
登录并进入代码目录
在开发机上,将变量替换为机器人的实际 SSH 地址后登录:
ROBOT_HOST=REPLACE_WITH_ROBOT_SSH_ADDRESS ssh "unitree@$ROBOT_HOST"在机器人上进入代码目录;路径不同的,替换为实际位置:
首次配置机器人环境
已完成下列安装并通过验证的,可以直接跳到“以后每次运行”。真机部署所需的主要依赖如下,Python 包由后面的安装命令统一处理:
aarch64或x86_64uv、git、支持 C++17 的编译器、CMake ≥ 3.18numpy>=1.26、onnxruntime==1.23.2、pydantic==2.12.5、hydra-core、omegaconf、gymnasium等,由仓库声明自动安装unitree-sdk2py,及其依赖cyclonedds==0.10.2、opencv-python真机控制配置使用
native_cpp。当前包依赖和下文的 DDS 只读检查仍需要 Python SDK,因此一并安装。机器人仅运行 sim2real 时,无需安装训练环境、Torch/CUDA 或仿真后端。1)准备工具和 Python 3.10 环境
安装系统工具:
若尚未安装
uv,执行:仅在尚未创建
.venv时,执行以下命令;已有可用的 Python 3.10 环境则直接激活:激活环境并安装编译工具:
确认 Python 输出为
3.10.x。如果复用系统 Python 创建的环境,编译时提示缺少Python.h,还需安装匹配的python3.10-dev;上述 uv 托管环境不需要另装此包。2)指定 Unitree C++ SDK2 路径
优先复用机器人上已经安装并验证过的 SDK2。例如已安装在
/usr/local:将
/usr/local替换为实际 SDK2 根目录。若尚未准备 SDK2,也可以取得完整 SDK2 目录后直接使用:使用 SDK2 源码目录时,须保留其中的
include、lib和thirdparty,并包含本机架构对应的库;无需构建 SDK 示例程序。3)安装仓库部署包
在已激活的环境中,从仓库根目录执行:
uv pip install \ -e ./motrix_env_core \ -e ./motrix_robots \ -e ./motrix_deploy \ -e ./motrix_deploy_tasks \ -e ./motrix_deploy_unitree \ "unitree-sdk2py @ git+https://github.com/motphys-developers/unitree_sdk2_python@ff87e731174f7258e0d09980897c55116634939a" uv pip install --no-deps -e ./motrixlab这里的 Python SDK 使用仓库指定提交。
motrixlab的--no-deps用于安装mxlab命令入口,所需部署依赖已在上一条命令中安装。构建所需的pybind11、scikit-build-core等会在构建扩展时自动安装,无需逐个手动配置。如果安装成功,继续下一步。如果提示
Could not locate cyclonedds,按下面的方法准备 CycloneDDS,然后重新执行本小节的安装命令;ARM 机器人尤其需要检查这一项。缺少 CycloneDDS 时的处理方法
若已有 CycloneDDS 0.10.2 安装目录,直接将
CYCLONEDDS_HOME指向该目录。否则构建并安装到用户目录:使用已有安装时,将最后两条命令中的安装路径换成实际位置。采用此方法后,每次重新打开终端也应执行这两条
export。4)构建 native 扩展并验证
保持
UNITREE_SDK2_ROOT指向上面确认过的 SDK2 目录:应看到
native backend OK、Python SDK OK、ONNX Runtime1.23.2和mxlab 0.4.0。仅看到安装成功还不够,必须通过 native 导入检查,之后再进行 DDS 网卡检查。若之前在缺少 SDK2 的情况下安装过 native 包,确认 SDK2 路径后重新构建:
uv pip install --no-deps --reinstall -e ./motrix_unitree_native \ -C "cmake.define.UNITREE_SDK2_ROOT=$UNITREE_SDK2_ROOT"以后每次运行
无需重复安装依赖。登录机器人后进入目录并激活环境:
若使用上面的独立 CycloneDDS 安装,还需执行对应的两条
export,再继续下面的网卡检查和运行步骤。选择并检查 DDS 网卡
查看运行程序的这台机器上的网卡和 IPv4 地址:
ip -br addr DDS_IFACE=eth0 ip -br addr show dev "$DDS_IFACE"将
eth0替换为连接机器人控制网络的实际网卡名。它应处于启用状态,并具有控制网段的地址;常见网段为192.168.123.0/24,以现场配置为准。SSH 使用的无线网卡与 DDS 网卡可以不同。只读检查是否能够收到机器人状态:
motrix-deploy-unitree read-lowstate "$DDS_IFACE" \ --robot g1-29dof --duration-s 5结尾
Summary中应有valid > 0。如果没有有效数据,先检查网卡、网段、网线及机器人状态。本流程直接使用 DDS,无需 ROS master。检查配置并启动
先查看启动配置;此命令不会启动机器人控制:
mxlab deploy deploy=g1-real \ runtime.network_interface="$DDS_IFACE" --cfg job确认网卡名称正确,且配置中包含
backend: unitree、transport: native_cpp和initial_state: passive。完成机器人低层控制准备,确认没有其他程序同时发送电机命令。首次验证使用吊装或支架保护,并准备好急停,然后启动:
mxlab deploy deploy=g1-real runtime.network_interface="$DDS_IFACE"需要指定策略路径时,在上述命令后添加
program.walk_artifact=实际路径和program.wbt_artifact=实际路径。LT,再按↑RB,再按XRB,再按YLT,再按Bselect在终端按
Ctrl+C结束程序。若直接从开发机连接机器人运行,也使用同一条真机命令,但应激活开发机的部署环境,并将DDS_IFACE设置为开发机上连接机器人的网卡。English — sim2sim / sim2real Deployment Guide
Applies to MotrixLab
0.4.0, branchfeat/g1-native-deploy.This guide assumes that the code and both deployment artifacts are already available. It does not include large asset downloads. sim2sim uses the existing environment on the development computer; sim2real includes the initial environment setup on the robot. Run repository commands from the repository root. The default policy paths are
artifacts/g1-flat.deployandartifacts/g1-wbt-dance.deploy.1. sim2sim: Run on the development computer
Enter the local repository and activate an environment with
mxlabinstalled. For example, using the existingmotrix-labenvironment:If you use the repository's
.venv, replace the activation command withsource .venv/bin/activate.To specify the policy paths explicitly:
Give the simulation window keyboard focus, then use these keys:
1230orxW/S,A/D,Q/EPress
Ctrl+Cin the terminal to stop the run.2. sim2real: Configure DDS and run
Log in and enter the code directory
On the development computer, replace the placeholder with the robot's actual SSH address, then log in:
ROBOT_HOST=REPLACE_WITH_ROBOT_SSH_ADDRESS ssh "unitree@$ROBOT_HOST"On the robot, enter the code directory. Adjust the path if your checkout is elsewhere:
Set up the robot environment for the first time
If the following installation and verification steps are already complete, skip to “For subsequent runs.” The main dependencies for hardware deployment are listed below. The installation commands handle the Python packages together.
aarch64orx86_64uv,git, a compiler supporting C++17, and CMake ≥ 3.18numpy>=1.26,onnxruntime==1.23.2,pydantic==2.12.5,hydra-core,omegaconf,gymnasium, and other dependencies installed automatically from the repository declarationsunitree-sdk2py, plus its dependenciescyclonedds==0.10.2andopencv-pythonThe hardware control configuration uses
native_cpp. The current package dependencies and the read-only DDS check below still require the Python SDK, so it is installed as well. A robot running only sim2real does not need the training environment, Torch/CUDA, or a simulation backend.1) Prepare the tools and Python 3.10 environment
Install the system tools:
If
uvis not installed, run:Run the following commands only if
.venvdoes not already exist. If you already have a working Python 3.10 environment, activate it instead:Activate the environment and install the build tools:
Confirm that Python reports
3.10.x. If you reuse an environment created from system Python and the build reports a missingPython.h, install the matchingpython3.10-devpackage. The uv-managed environment above does not require that additional package.2) Set the Unitree C++ SDK2 path
Prefer the SDK2 installation already verified on the robot. For example, if it is installed under
/usr/local:Replace
/usr/localwith the actual SDK2 root directory. If SDK2 is not available yet, you can obtain a complete SDK2 checkout and use it directly:When using an SDK2 source checkout, keep its
include,lib, andthirdpartydirectories, including the libraries for your machine's architecture. You do not need to build the SDK examples.3) Install the repository deployment packages
With the environment activated, run the following from the repository root:
uv pip install \ -e ./motrix_env_core \ -e ./motrix_robots \ -e ./motrix_deploy \ -e ./motrix_deploy_tasks \ -e ./motrix_deploy_unitree \ "unitree-sdk2py @ git+https://github.com/motphys-developers/unitree_sdk2_python@ff87e731174f7258e0d09980897c55116634939a" uv pip install --no-deps -e ./motrixlabThe Python SDK is pinned to the commit specified by the repository. Installing
motrixlabwith--no-depsprovides themxlabcommand; the required deployment dependencies are installed by the preceding command. Build dependencies such aspybind11andscikit-build-coreare installed automatically when building the extension.If installation succeeds, continue to the next step. If it reports
Could not locate cyclonedds, prepare CycloneDDS as described below, then rerun the installation commands in this subsection. Check this dependency particularly on ARM robots.If CycloneDDS is missing
If CycloneDDS 0.10.2 is already installed, point
CYCLONEDDS_HOMEto its installation directory. Otherwise, build and install it under your user directory:For an existing installation, use its actual path in the last two commands. After using this setup, also run these two
exportcommands whenever you open a new terminal.4) Build and verify the native extension
Keep
UNITREE_SDK2_ROOTset to the SDK2 directory verified above:Expected output includes
native backend OK,Python SDK OK, ONNX Runtime1.23.2, andmxlab 0.4.0. A successful installation alone is insufficient: the native import check must pass before you proceed to the DDS network interface check.If the native package was previously installed without SDK2, confirm the SDK2 path and rebuild:
uv pip install --no-deps --reinstall -e ./motrix_unitree_native \ -C "cmake.define.UNITREE_SDK2_ROOT=$UNITREE_SDK2_ROOT"For subsequent runs
You do not need to reinstall the dependencies. Log in to the robot, enter the directory, and activate the environment:
If you use the separate CycloneDDS installation described above, also run its two
exportcommands before continuing with the network checks and launch steps below.Select and check the DDS network interface
List the network interfaces and IPv4 addresses on the machine that will run the program:
ip -br addr DDS_IFACE=eth0 ip -br addr show dev "$DDS_IFACE"Replace
eth0with the actual interface connected to the robot's control network. It must be enabled and have an address on the control subnet. A common subnet is192.168.123.0/24; use your actual network configuration. The Wi-Fi interface used for SSH may differ from the DDS interface.Run this read-only check to confirm that robot state messages are received:
motrix-deploy-unitree read-lowstate "$DDS_IFACE" \ --robot g1-29dof --duration-s 5The final
Summaryshould reportvalid > 0. If no valid data is received, check the interface, subnet, cable, and robot status first. This workflow uses DDS directly and does not require a ROS master.Check the configuration and launch
Inspect the launch configuration first. This command does not start robot control:
mxlab deploy deploy=g1-real \ runtime.network_interface="$DDS_IFACE" --cfg jobConfirm that the interface name is correct and the configuration contains
backend: unitree,transport: native_cpp, andinitial_state: passive.Prepare the robot for low-level control and confirm that no other program is publishing motor commands. For the first test, support the robot with a harness or stand and have the emergency stop ready. Then launch:
mxlab deploy deploy=g1-real runtime.network_interface="$DDS_IFACE"To override the policy paths, append
program.walk_artifact=YOUR_WALK_PATHandprogram.wbt_artifact=YOUR_WBT_PATHto the command above.LT, then press↑RB, then pressXRB, then pressYLT, then pressBselectPress
Ctrl+Cin the terminal to stop the program. If you run it on a development computer connected directly to the robot, use the same hardware launch command, activate that computer's deployment environment, and setDDS_IFACEto its interface connected to the robot.