diff --git a/sites/en/docs/Robotics/Robot_Kits/Lerobot/Lerobot_SO100Arm_New.md b/sites/en/docs/Robotics/Robot_Kits/Lerobot/Lerobot_SO100Arm_New.md index 42c459bc25c6c..bc630c4f3a7a7 100644 --- a/sites/en/docs/Robotics/Robot_Kits/Lerobot/Lerobot_SO100Arm_New.md +++ b/sites/en/docs/Robotics/Robot_Kits/Lerobot/Lerobot_SO100Arm_New.md @@ -10,7 +10,7 @@ image: https://files.seeedstudio.com/wiki/robotics/projects/lerobot/Arm_kit.webp slug: /lerobot_so100m_new sku: 114993666,114993667,114993668,101090144 last_update: - date: 3/2/2026 + date: 3/11/2026 author: ZhangJiaQuan translation: skip: @@ -814,7 +814,6 @@ If you have more cameras, you can change `--robot.cameras` to add cameras. You s Images in the `fourcc: "MJPG"` format are compressed. You can try higher resolutions, and you may also attempt the `YUYV` format. However, the latter will reduce the image resolution and FPS, leading to lag in the robotic arm's operation. Currently, under the `MJPG` format, it can support 3 cameras at a resolution of `1920*1080` while maintaining `30FPS`. That said, connecting 2 cameras to a computer via the same USB HUB is still not recommended. ::: - For example, you want to add a side camera: ```bash @@ -833,7 +832,6 @@ lerobot-teleoperate \ Images in the `fourcc: "MJPG"` format are compressed. You can try higher resolutions, and you may also attempt the `YUYV` format. However, the latter will reduce the image resolution and FPS, leading to lag in the robotic arm's operation. Currently, under the `MJPG` format, it can support 3 cameras at a resolution of `1920*1080` while maintaining `30FPS`. That said, connecting 2 cameras to a computer via the same USB HUB is still not recommended. ::: - :::tip If you find bug like this. @@ -1049,18 +1047,16 @@ Your robot should replicate movements similar to those you recorded. ## Train And Evaluate -
[ACT](https://huggingface.co/docs/lerobot/act) Refer to[ACT](https://huggingface.co/docs/lerobot/act) -To train a policy to control your robot, use the [lerobot-train](https://github.com/huggingface/lerobot/blob/main/src/lerobot/scripts/train.py) script. +To train a policy to control your robot, use the [lerobot-train](https://github.com/huggingface/lerobot/blob/main/src/lerobot/scripts/train.py) script. **Train** - ```bash lerobot-train \ --dataset.repo_id=${HF_USER}/so101_test \ @@ -1094,7 +1090,6 @@ Let's explain it: - **Device selection**: We provide `policy.device=cuda` because we are training on an Nvidia GPU, but you can use `policy.device=mps` for training on Apple Silicon. - **Visualization tool**: We provide `wandb.enable=true` to visualize training charts using [Weights and Biases](https://docs.wandb.ai/quickstart). This is optional, but if you use it, ensure you have logged in by running `wandb login`. - **Evaluate** :::tip @@ -1141,10 +1136,8 @@ lerobot-record \ -
-
SmolVLA @@ -1288,17 +1281,17 @@ LeRobot uses MuJoCo for simulation. You need to set the rendering backend before
-
[Pi0](https://huggingface.co/docs/lerobot/pi0) -Refer to [Pi0](https://huggingface.co/docs/lerobot/pi0) +Refer to [Pi0](https://huggingface.co/docs/lerobot/pi0) ```bash pip install -e ".[pi]" ``` **Train** + ```bash lerobot-train \ --policy.type=pi0 \ @@ -1329,20 +1322,19 @@ lerobot-record \ --policy.path=outputs/pi0_training/checkpoints/last/pretrained_model ``` -
-
[Pi0.5](https://huggingface.co/docs/lerobot/pi05) -Refer to [Pi0.5](https://huggingface.co/docs/lerobot/pi05) +Refer to [Pi0.5](https://huggingface.co/docs/lerobot/pi05) ```bash pip install -e ".[pi]" ``` **Train** + ```bash lerobot-train \ --dataset.repo_id=seeed/eval_test123 \ @@ -1373,11 +1365,8 @@ lerobot-record \ --policy.path=outputs/pi05_training/checkpoints/last/pretrained_model ``` -
- -
[GR00T N1.5](https://huggingface.co/docs/lerobot/groot) @@ -1683,7 +1672,335 @@ For advanced configuration and troubleshooting, see the Accelerate documentation
+
+ +(Optional) Asynchronous Inference + +When asynchronous inference is not enabled, LeRobot’s control flow can be understood as **conventional sequential / synchronous inference**: the policy first predicts a segment of actions, then executes that segment, and only after that waits for the next prediction. + +For larger models, this can cause the robot to noticeably pause while waiting for the next action chunk. + +The goal of asynchronous inference is to let the robot execute the current action chunk while computing the next one in advance, thereby reducing idle time and improving responsiveness. + +Asynchronous inference is applicable to policies supported by LeRobot, including **chunk-based action policies** such as **ACT, OpenVLA, Pi0, and SmolVLA**. + +Since inference is decoupled from actual control, asynchronous inference also helps leverage machines with stronger compute resources to perform inference for the robot. + +You can read more about asynchronous inference in the [blog by Hugging Face](https://huggingface.co/blog/async-robot-inference) + +Let us first introduce some basic concepts: + +- **Client**: connects to the robotic arm and cameras, collects observation data (such as images and robot poses), sends these observations to the server, and receives the action chunks returned by the server and executes them in order. + +- **Server**: the device that provides compute resources. It receives camera data and robotic arm data, performs inference (that is, computation) to produce action chunks, and sends them back to the client. It can be the same device connected to the robotic arm and cameras, another computer on the same local network, or a rented cloud server on the Internet. + +- **Action chunk**: a sequence of robotic arm action commands obtained by policy inference on the server side. + +Three deployment scenarios for asynchronous inference + +1. Single-machine deployment + +The robot, cameras, client, and server are all on the same device. + +This is the simplest case: the server can listen on 127.0.0.1, and the client can also connect to 127.0.0.1:port. The command example in the official documentation is for this scenario. + +2. LAN deployment + +The robot and cameras are connected to a lightweight device, while the policy server runs on another high-compute machine in the same local network. + +In this case, the server must listen on an address that is accessible by other machines, and the client must also connect to the server’s LAN IP, rather than 127.0.0.1. + +3. Cross-network / cloud deployment + +The policy server runs on a publicly accessible cloud host, and the client connects to it over the public Internet. + +This approach can use the stronger GPU of the cloud host. When network conditions are good, the round-trip network time (network latency) can sometimes be relatively small compared with inference time, but this depends on your actual network environment. + +Security note: the LeRobot async inference pipeline has a risk related to unauthenticated gRPC + pickle deserialization. If there is important information or important services on the server, it is not recommended to expose the service directly to the Internet in a public deployment. A safer approach is to use VPN or SSH tunneling, or at least restrict the allowed source IPs in the security group to your own client public IP. + +### Getting started with asynchronous inference deployment + +#### Step 1: Environment setup + +First, use pip to install the additional dependencies required for asynchronous inference. Both the client and the server need to have lerobot installed along with the extra dependencies: + +```bash +pip install -e ".[async]" +``` + +#### Step 2: Network configuration and checks + +1. **Proxy issues** + +If your current terminal is configured to use a proxy and the connection behaves abnormally, you can temporarily unset the proxy environment variables: + +```bash +unset http_proxy https_proxy ftp_proxy all_proxy HTTP_PROXY HTTPS_PROXY FTP_PROXY ALL_PROXY +``` + +Note: the command above only affects the current terminal session. If you open another terminal window, you need to run it again. + +2. **Open the port in the firewall / security group** + +Single-machine deployment: this can usually be skipped. + +LAN deployment: you need to open the listening port on the server side. + +Example for opening the listening port on a LAN setup (run on the server side): + +```bash +sudo ufw allow 8080/tcp +``` + +Cloud deployment: you need to open this port in the cloud server security group, and it is recommended to restrict the source IPs as much as possible. + +If you are running on a cloud server: + +Open port 8080 in the server management console’s security group, or use another port that is already open. Different cloud service platforms handle this differently; refer to your cloud provider’s documentation. + +3. **Confirm the IP address** + +This step can be skipped for single-machine deployment (the IP address for a single machine is always 127.0.0.1). + +If this is a LAN deployment: + +You need to confirm and remember the LAN IP address of the server side. When the client connects, what should be filled in is the LAN IP of the machine running policy_server, not the client’s own IP. + +Linux / Jetson / Raspberry Pi: + +```bash +hostname -I +``` + +If multiple addresses are shown, generally choose the one corresponding to the current LAN network interface, for example 192.168.x.x. + +You can also use: + +```bash +ip addr +``` + +to view the inet field under the currently connected network interface. + +Windows: + +```shell +ipconfig +``` + +Find a field like IPv4 Address . . . . . . . . . . . : 192.168.14.140; that is the LAN IP address of that machine. + +macOS: + +```bash +ifconfig +``` + +Find the inet field corresponding to the currently connected network interface; that is the LAN IP address. + +We need to remember the server-side LAN IP address. We will use `` to refer to it. + +If this is a cloud server deployment: + +Look for the public IP in the server control panel. It is usually called one of the following: + +Public IPv4 + +External IP + +Public IP address + +EIP + +Public IP +We need to remember the public IP address. We will use` `to refer to it. + +4. **Connection test** + +Single-machine deployment: this step can be skipped + +LAN / cloud deployment: it is recommended to test from the client side whether the server port is reachable. Example tests are as follows: + +LAN example: run on the client side + +```bash +nc -vz 8080 +``` + +Cloud example: run on the client side + +```bash +nc -vz 8080 +``` + +#### Step 3: Start the service + +**Scenario A: Single-machine deployment** + +Start the local service in one terminal: + +```bash +python -m lerobot.async_inference.policy_server \ +--host=127.0.0.1 \ +--port=8080 +``` + +After it starts successfully, you need to keep this terminal open. You will need to open a new terminal to run other commands. + +**Scenario B: LAN deployment** + +Run on the server side: + +```bash +python -m lerobot.async_inference.policy_server \ +--host=0.0.0.0 \ +--port=8080 +``` + +In this case, when the client connects, the --server_address should be the server-side LAN IP address, that is,`:8080`. + +**Scenario C: Cloud server deployment** + +Run on the server side: + +```bash +python -m lerobot.async_inference.policy_server \ +--host=0.0.0.0 \ +--port=8080 +``` + +In this case, when the client connects, the --server_address should be the server’s public IP address, that is, `:8080`. + +#### Step 4: Choose inference parameters + +Run on the client side: + +```bash +python -m lerobot.async_inference.robot_client \ +--server_address=:8080 \ +--robot.type=so100_follower \ +--robot.port=/dev/tty.usbmodem585A0076841 \ +--robot.id=follower_so100 \ +--robot.cameras="{ laptop: {type: opencv, index_or_path: 0, width: 1920, height: 1080, fps: 30}, phone: {type: opencv, index_or_path: 0, width: 1920, height: 1080, fps: 30}}" \ +--task="dummy" \ +--policy_type=your_policy_type \ +--pretrained_name_or_path=user/model \ +--policy_device=cuda \ +--actions_per_chunk=50 \ +--chunk_size_threshold=0.5 \ +--aggregate_fn_name=weighted_average \ +--debug_visualize_queue_size=True +``` + +Parameter explanations: + +- `--server_address` + +Specifies the address and port of the policy server. `` should be replaced with 127.0.0.1 (local machine), ``(LAN), or`` (cloud server). + +- `--robot.type, --robot.port, --robot.id, --robot.cameras` + +Hardware device parameters. These should be kept consistent with the parameters used during dataset collection. + +- `--task` + +The task description. Vision-language policies such as SmolVLA can determine the action target based on the task text. + +- `--policy_type` + +Replace this with the specific policy name, for example: + +- smolvla + +- act + +- `--pretrained_name_or_path` + +This value should be replaced with the model path on the server side, or a model path on Hugging Face. + +- `--policy_device` + +Specifies the inference device used on the server side. + +It can be cuda, mps, or cpu. + +- `--actions_per_chunk=50` + +Specifies how many actions are output in each inference. + +The larger this value is: + +Advantage: the action buffer is more sufficient, making it less likely to run out +Disadvantage: the prediction horizon is longer, so control error may accumulate more noticeably + +- `--chunk_size_threshold=0.5` + +Specifies when to request the next action chunk from the server. + +This is a threshold, usually in the range 0 to 1. + +It can be understood as: when the remaining proportion of the current action queue falls below this threshold, the client will send a new observation in advance and request the next action chunk. + +Setting it to 0.5 here means: + +when the current action chunk is about half consumed + +the client starts requesting the next action chunk + +The larger this value is, the more frequently requests are sent, and the more responsive the system becomes, but the load on the server also increases. + +The smaller this value is, the closer the behavior gets to synchronous inference. + +- `--aggregate_fn_name=weighted_average` + +Specifies the aggregation method for overlapping action intervals. + +In asynchronous inference, when the old action chunk has not yet been fully executed, the new action chunk may already have arrived. + +In that case, the two chunks overlap over part of the time interval, and an aggregation function is needed to combine them into the final executed action. + +The meaning of weighted_average is: + +use a weighted average to fuse the overlapping part. + +This usually makes action switching smoother and reduces abrupt changes. + +- `--debug_visualize_queue_size=True` + +Whether to visualize the action queue size at runtime. + +When enabled, it allows you to see more directly whether the queue frequently hits the bottom, which helps you tune actions_per_chunk and chunk_size_threshold. + +#### Step 5: Adjust parameters based on robot behavior + +In asynchronous inference, there are two additional parameters that need adjustment which do not exist in synchronous inference: + +Parameter Suggested initial value Description + +actions_per_chunk 50 How many actions the policy outputs at one time. Typical values: 10–50. + +chunk_size_threshold 0.5 When the remaining proportion of the action queue is ≤ chunk_size_threshold, the client sends a new action chunk request. The value range is [0, 1]. + +When --debug_visualize_queue_size=True, the change in action queue size will be plotted at runtime. + +What asynchronous inference needs to balance is: the speed at which the server generates action chunks must be greater than or equal to the speed at which the client consumes action chunks. Otherwise, the action queue will empty, and the robot will begin to stutter again (this can be seen as the curve hitting the bottom in the queue visualization). + +The speed at which the server generates action chunks is affected by factors such as model size, device type, VRAM / memory, and GPU compute power. + +The speed at which the client consumes action chunks is affected by the configured execution fps. + +If the queue frequently runs empty, you need to increase actions_per_chunk, increase chunk_size_threshold, or reduce fps. + +If the queue curve fluctuates frequently but the remaining actions in the queue are always sufficient, you can appropriately decrease chunk_size_threshold. + +In general: + +the empirical range for actions_per_chunk is 10–50 + +the empirical range for chunk_size_threshold is 0.5–0.7; when tuning, it is recommended to start from 0.5 and gradually increase it + +
If you encounter the following error: @@ -1725,8 +2042,6 @@ huggingface-cli upload ${HF_USER}/act_so101_test${CKPT} \ outputs/train/act_so101_test/checkpoints/${CKPT}/pretrained_model ``` - - ## FAQ - If you are following this documentation/tutorial, please git clone the recommended GitHub repository `https://github.com/Seeed-Projects/lerobot.git`. The repository recommended in this documentation is a verified stable version; the official Lerobot repository is continuously updated to the latest version, which may cause unforeseen issues such as different dataset versions, different commands, etc. diff --git a/sites/zh-CN/docs/Robotics/Robot_Kits/Lerobot/cn_Lerobot_SO100Arm_New.md b/sites/zh-CN/docs/Robotics/Robot_Kits/Lerobot/cn_Lerobot_SO100Arm_New.md index ea04cd49b5189..c5af6cea62a84 100644 --- a/sites/zh-CN/docs/Robotics/Robot_Kits/Lerobot/cn_Lerobot_SO100Arm_New.md +++ b/sites/zh-CN/docs/Robotics/Robot_Kits/Lerobot/cn_Lerobot_SO100Arm_New.md @@ -10,7 +10,7 @@ image: https://files.seeedstudio.com/wiki/robotics/projects/lerobot/Arm_kit.webp slug: /lerobot_so100m_new sku: 114993666,114993667,114993668,101090144 last_update: - date: 3/2/2026 + date: 3/11/2026 author: ZhangJiaQuan createdAt: '2025-01-08' updatedAt: '2026-03-03' @@ -29,8 +29,8 @@ url: https://wiki.seeedstudio.com/cn/lerobot_so100m_new/ - ### 项目介绍 + SO-ARM10x 和 reComputer Jetson AI 智能机器人套件无缝结合了高精度的机器人手臂控制与强大的 AI 计算平台,提供了全面的机器人开发解决方案。该套件基于 Jetson Orin 或 AGX Orin 平台,结合 SO-ARM10x 机器人手臂和 LeRobot AI 框架,为用户提供适用于教育、科研和工业自动化等多种场景的智能机器人系统。 本维基提供了 SO ARM10x 的组装和调试教程,并在 Lerobot 框架内实现数据收集和训练。 @@ -68,8 +68,8 @@ Seeed Studio **仅对硬件质量负责**。教程严格按官方文档更新, - **主臂齿轮比优化**:主臂现在采用了经过优化的齿轮比电机,无需外部减速机构,同时提升了性能。 - **新增功能支持**:主臂现在可以实时跟随从臂动作,这对即将引入的策略尤为关键,可实现人类实时干预并修正机器动作。 - # 规格参数 + 本教程硬件由[矽递科技Seeed Studio](https://www.seeedstudio.com/)提供 @@ -131,7 +131,7 @@ Seeed Studio **仅对硬件质量负责**。教程严格按官方文档更新,
-:::danger +:::danger 若购买 **SO101 Arm Kit 标准版**,所有电源均为5V。若购买 **SO101 Arm Kit Pro 版**,Leader机械臂的校准及每一步骤均使用5V电源,Follower机械臂的校准及每一步骤均使用12V电源。 ::: @@ -146,35 +146,34 @@ Seeed Studio **仅对硬件质量负责**。教程严格按官方文档更新, | 3D打印桌面夹具 | 4 | ✅ | | 手臂的3D打印部件 | 1 | Option | - # 初始系统环境 + For Ubuntu X86: - - Ubuntu 22.04 - - CUDA 12+ - - Python 3.10 - - Troch 2.6 +- Ubuntu 22.04 +- CUDA 12+ +- Python 3.10 +- Troch 2.6 For Jetson Orin: - - Jetson Jetpack 6.0 和 6.1,暂不支持6.2 - - Python 3.10 - - Torch 2.3+ +- Jetson Jetpack 6.0 和 6.1,暂不支持6.2 +- Python 3.10 +- Torch 2.3+ # 步骤目录 - - [A. 3D打印指南](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#3d打印指南) - - [B. 安装Lerobot](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#安装lerobot) - - [C. 校准舵机并组装机械臂](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#校准舵机并组装机械臂) - - [D. 校准机械臂](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#校准机械臂) - - [E. 遥操作](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#遥操作) - - [F. 添加摄像头](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#添加摄像头) - - [G. 数据集制作采集](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#数据集制作采集) - - [H. 可视化数据集](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#可视化数据集) - - [I. 重播一个回合](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#重播一个回合) - - [J. 训练](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#训练) - - [K. 评估](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#评估) - +- [A. 3D打印指南](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#3d打印指南) +- [B. 安装Lerobot](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#安装lerobot) +- [C. 校准舵机并组装机械臂](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#校准舵机并组装机械臂) +- [D. 校准机械臂](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#校准机械臂) +- [E. 遥操作](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#遥操作) +- [F. 添加摄像头](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#添加摄像头) +- [G. 数据集制作采集](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#数据集制作采集) +- [H. 可视化数据集](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#可视化数据集) +- [I. 重播一个回合](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#重播一个回合) +- [J. 训练](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#训练) +- [K. 评估](https://wiki.seeedstudio.com/cn/lerobot_so100m_new/#评估) ## 3D打印参考参数 @@ -182,10 +181,10 @@ For Jetson Orin: 随着2025年4月28日官方发布 SO101,SO100 将不再支持打印指导,但源文件仍可在我们的 [Makerworld](https://makerworld.com/zh/models/908660) 找到。不过,对于之前购买了SO100 的用户,教程和安装方法以及代码依然兼容。SO101 的打印件也完全兼容 SO100 的电机套件安装。 ::: - ### 第一步:选择打印机 提供的 STL 文件可以直接在许多 FDM 打印机上打印。以下是经过测试并推荐的设置,但其他设置也可能适用。 + - 材料:PLA+ - 喷嘴直径与精度:0.4mm 喷嘴直径,层高 0.2mm,或 0.6mm 喷嘴直径,层高 0.4mm。 - 填充密度:15% @@ -212,15 +211,12 @@ For Jetson Orin: - [Follower](https://github.com/TheRobotStudio/SO-ARM100/blob/main/STL/SO101/Follower/Prusa_Follower_SO101.stl) - [Leader](https://github.com/TheRobotStudio/SO-ARM100/blob/main/STL/SO101/Leader/Prusa_Leader_SO101.stl) - - ## 安装 LeRobot
- 需要根据你的 CUDA 版本安装 pytorch 和 torchvision 等环境。 1. 安装 Miniconda: @@ -234,6 +230,7 @@ source ~/.bashrc ``` 或者,对于 X86 Ubuntu 22.04: + ```bash mkdir -p ~/miniconda3 cd miniconda3 @@ -257,17 +254,20 @@ git clone https://github.com/Seeed-Projects/lerobot.git ~/lerobot ``` 4. 使用 miniconda 时,在环境中安装 ffmpeg: - + ```bash conda install ffmpeg -c conda-forge ``` :::tip 这通常会为你的平台安装使用 libsvtav1 编码器编译的 ffmpeg 7.X。如果不支持 libsvtav1(可以通过 ffmpeg -encoders 查看支持的编码器),你可以: + - 【适用于所有平台】显式安装 ffmpeg 7.X: + ```bash conda install ffmpeg=7.1.1 -c conda-forge ``` + - 【仅限 Linux】安装 ffmpeg 的构建依赖并从源码编译支持 libsvtav1 的 ffmpeg,并确保使用的 ffmpeg 可执行文件是正确的,可以通过 `which ffmpeg` 确认。 如果你遇到以下报错,也可以使用上述命令解决。 @@ -308,25 +308,19 @@ print(torch.cuda.is_available()) 如果你使用的是 Jetson 设备,请根据[此教程](https://github.com/Seeed-Projects/reComputer-Jetson-for-Beginners/blob/main/3-Basic-Tools-and-Getting-Started/3.3-Pytorch-and-Tensorflow/README.md#installing-pytorch-on-recomputer-nvidia-jetson)安装 Pytorch 和 Torchvision。 - ## 校准舵机并组装机械臂 - -
- import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; - - SO101 的舵机校准初始化与 SO100 方法和代码一致,只是需要注意:SO101 的 Leader 机械臂前三个关节减速比与 SO100 不同,因此需要仔细区分并校准。 为便于校准与后续排查,建议在舵机校准前对每个电机做好标记: @@ -357,6 +351,7 @@ SO101 的舵机校准初始化与 SO100 方法和代码一致,只是需要注 查找机械臂对应的 USB 端口 为了找到每个机械臂正确的端口,请运行实用脚本两次: + ```bash lerobot-find-port ``` @@ -373,6 +368,7 @@ Remove the usb cable from your MotorsBus and press Enter when done. The port of this MotorsBus is /dev/ttyACM0 Reconnect the USB cable. ``` + :::tip 请记住要拔出 USB 接头,否则将无法检测到接口。 ::: @@ -389,15 +385,14 @@ sudo chmod 666 /dev/ttyACM1 **配置舵机** - :::danger 如果你买的是SO101的标准版,则使用5V电源进行Leader舵机校准(ST-3215-C046, C044, C001). ::: + | **Leader机械臂6号舵机校准** | **Leader机械臂5号舵机校准** | **Leader机械臂4号舵机校准** | **Leader机械臂3号舵机校准** | **Leader机械臂2号舵机校准** | **Leader机械臂1号舵机校准** | |:---------:|:---------:|:---------:|:---------:|:---------:|:---------:| | ![fig1](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/cal_L6.jpg) | ![fig2](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/cal_L5.jpg) | ![fig3](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/cal_L4.jpg) |![fig4](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/cal_L3.jpg) |![fig5](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/cal_L2.jpg) |![fig6](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/cal_L1.jpg) | - :::danger 如果你买的是SO101的Pro版,则使用12V电源进行Follower舵机校准(ST-3215-C047/ST-3215-C018),如果是SO101标准版则使用5V进行舵机校准(ST-3215-C001). ::: @@ -410,7 +405,6 @@ sudo chmod 666 /dev/ttyACM1 再次提醒,请确保舵机关节 ID 和齿轮比与 **SO-ARM101** 的严格对应。 ::: - 将 USB 线从电脑连接到从动臂的舵机驱动板,并接通电源。然后,运行以下命令。 ```bash @@ -455,30 +449,27 @@ Connect the controller board to the 'wrist_roll' motor only and press enter. lerobot-setup-motors \ --teleop.type=so101_leader \ --teleop.port=/dev/ttyACM0 -``` +```
- -
- ## 组装教程 -
- :::tip + - SO-ARM101 双臂的组装过程与 SO-ARM100 相同。唯一的区别在于 SO-ARM101 增加了线缆夹,且主机械臂(Leader Arm)关节舵机的齿轮比不同。因此,SO100 和 SO101 都可以参考以下内容进行安装。 - 组装前,请再次检查您的电机型号和减速比。如果您购买的是 SO100,可以忽略此步骤。如果您购买的是 SO101,请参考下表区分 F1 至 F6 和 L1 至 L6。 + ::: | Servo Model | Gear Ratio | Corresponding Joints | @@ -502,13 +493,15 @@ lerobot-setup-motors \ | ![fig1](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_L7.jpg) | ![fig2](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_L8.jpg) | ![fig3](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_L9.jpg) |![fig4](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_L10.jpg) |![fig5](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_L11.jpg) |![fig6](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_L12.jpg) | | **步骤 13** | **步骤 14** | **步骤 15** | **步骤 16** | **步骤 17** | **步骤 18** | | ![fig1](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_L13.jpg) | ![fig2](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_L14.jpg) | ![fig3](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_L15.jpg) |![fig4](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_L16.jpg) |![fig5](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_L18.jpg) |![fig6](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_L21.jpg) | -| **步骤 19** | **步骤 20** | +| **步骤 19** | **步骤 20** | | ![fig1](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_L22.jpg) | ![fig2](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_L23.jpg) | **组装从动臂** :::tip + - 从动臂的组装步骤与领导臂基本相同。唯一的区别在于第12步之后,末端执行器(夹爪和手柄)的安装方式有所不同。 + ::: | **步骤 1** | **步骤 2** | **步骤 3** | **步骤 4** | **步骤 5** | **步骤 6** | @@ -516,14 +509,11 @@ lerobot-setup-motors \ | ![fig1](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F1.jpg) | ![fig2](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F2.jpg) | ![fig3](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F3.jpg) |![fig4](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F3.5.jpg) |![fig5](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F4.jpg) |![fig6](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F5.jpg) | | **步骤 7** | **步骤 8** | **步骤 9** | **步骤 10** | **步骤 11** | **步骤 12** | | ![fig1](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F6.jpg) | ![fig2](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F7.jpg) | ![fig3](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F8.jpg) |![fig4](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F9.jpg) |![fig5](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F11.jpg) |![fig6](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F12.jpg) | -| **步骤 13** | **步骤 14** | **步骤 15** | **步骤 16** | **步骤 17** | +| **步骤 13** | **步骤 14** | **步骤 15** | **步骤 16** | **步骤 17** | | ![fig1](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F13.jpg) | ![fig2](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F14.jpg) | ![fig3](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F15.jpg) |![fig4](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F16.jpg) |![fig5](https://files.seeedstudio.com/wiki/robotics/projects/lerobot/so101/install_F17.jpg) | - - ## 校准机械臂 -
@@ -532,7 +522,7 @@ lerobot-setup-motors \ SO100 和 SO101 的代码是兼容的。SO100 用户可以直接使用 SO101 的参数和代码进行操作。 ::: -:::danger +:::danger 若购买 **SO101 Arm Kit 标准版**,所有电源均为5V。若购买 **SO101 Arm Kit Pro 版**,Leader机械臂的校准及每一步骤均使用5V电源,Follower机械臂的校准及每一步骤均使用12V电源。 ::: @@ -565,7 +555,6 @@ lerobot-calibrate \ 下面的视频演示了如何执行校准。首先,您需要将机器人移动到所有关节都位于其活动范围中间的位置。然后,按下回车键后,您必须将每个关节在其完整的运动范围内移动。 - ### 校准领导臂 对主机械臂进行校准的步骤与上述相同,请运行以下命令或 API 示例: @@ -635,7 +624,6 @@ python -m src.tools.servo_center_test 完成中位校准后,请回到本节上方的 `lerobot-calibrate` 流程重新进行机械臂整臂校准。 - ## 遥控操作 现在,您就可以遥控操作您的机器人了!运行这个简单的脚本(它不会连接和显示摄像头): @@ -643,11 +631,11 @@ python -m src.tools.servo_center_test 请注意,与机器人关联的 **ID** 用于存储校准文件。在使用相同设置进行遥控操作、录制和评估时,使用相同的 **ID** 至关重要。 先对串口给予权限: + ```bash sudo chmod 666 /dev/ttyACM* ``` - 运行遥操作: ```bash @@ -662,9 +650,8 @@ lerobot-teleoperate \ 遥控操作命令将自动执行以下步骤: -1. 识别任何缺失的校准文件并启动校准程序。 -2. 连接机器人和遥控设备,并开始遥控操作。 - +1. 识别任何缺失的校准文件并启动校准程序。 +2. 连接机器人和遥控设备,并开始遥控操作。 ## 添加摄像头 @@ -680,10 +667,10 @@ lerobot-teleoperate \ 淘宝来一单 🖱️ - - 🚀 步骤 1:安装 Orbbec SDK 依赖环境 1. 拉取 `pyorbbec` 仓库 + ```bash cd ~/ git clone https://github.com/orbbec/pyorbbecsdk.git @@ -692,11 +679,13 @@ lerobot-teleoperate \ 2. 下载并安装 SDK 对应的 **.whl 文件** 前往 [pyorbbecsdk Releases](https://github.com/orbbec/pyorbbecsdk/releases), 根据 Python 版本选择并安装,例如: + ```bash pip install pyorbbecsdk-x.x.x-cp310-cp310-linux_x86_64.whl ``` 3. 在 `pyorbbec` 目录下安装依赖 + ```bash cd ~/pyorbbecsdk pip install -r requirements.txt @@ -716,6 +705,7 @@ lerobot-teleoperate \ ``` 5.修改utils.py和__init__.py + - 在`~/lerobot/src/lerobot/cameras`目录下找到`utils.py`,在大概`45`行处添加如下代码: ```python @@ -739,14 +729,10 @@ from .orbbec.configuration_orbbec import OrbbecCameraConfig - - - -- 🚀 步骤 2:函数调用与示例 +- 🚀 步骤 2:函数调用与示例 以下示例均需将 `so101_follower` 替换为你所使用实际机械臂型号(如 `so100` / `so101`)。 - 我们加入了focus_area超参数,因为过远的深度数据对于机械臂没有意义(抓取不到),因此小于或者大于focus_area的深度数据将会变为黑色,默认的focus_area是(20,600) 目前支持的分辨率只限于 width: 640, height: 880 @@ -764,12 +750,10 @@ lerobot-teleoperate \ ``` -
- 后续采集数据、训练及评估任务与常规RGB命令一样,只需要把: ```bash @@ -778,12 +762,9 @@ lerobot-teleoperate \ 替换到常规rgb命令中即可,你也可以再后面添加额外的单目RGB相机。 - - **💡 作者与贡献** -- 作者: 张家铨,王文钊 - 华南师范大学 - +- 作者: 张家铨,王文钊 - 华南师范大学 @@ -791,7 +772,6 @@ lerobot-teleoperate \ - 为了实例化摄像头,您需要一个摄像头标识符。这个标识符可能会在您重启电脑或重新插拔摄像头时发生变化,这主要取决于您的操作系统。 要查找连接到您系统的摄像头的**摄像头索引**,请运行以下脚本: @@ -845,6 +825,7 @@ lerobot-teleoperate \ 如果您有更多摄像头,可以通过更改 `--robot.cameras` 参数来添加。您应该注意`index_or_path` 的格式,它由 `python -m lerobot.find_cameras opencv` 命令输出的摄像头 ID 的最后一位数字决定。 例如,如果你想添加摄像头: + ```bash lerobot-teleoperate \ --robot.type=so101_follower \ @@ -861,16 +842,12 @@ lerobot-teleoperate \ `fourcc: "MJPG"`格式图像是经过压缩后的图像,你可以尝试更高分辨率,当然你可以尝试`YUYV`格式图像,但是这会导致图像的分辨率和FPS降低导致机械臂运行卡顿。目前`MJPG`格式下可支持`3`个摄像头`1920*1080`分辨率并且保持`30FPS`, 但是依然不推荐2个摄像头通过同一个USB HUB接入电脑。同时,如果摄像头接在 USB2.0 的接口,也可能会出现无法读取的问题,建议优先使用 USB3.0 接口并尽量直连设备。 ::: - - ## 数据集制作采集 -
- - 如果你想数据集保存在本地,可以直接运行: ```bash @@ -927,6 +904,7 @@ lerobot-record \ ``` 你会看到类似如下数据: + ```bash INFO 2024-08-10 15:02:58 ol_robot.py:219 dt:33.34 (30.0hz) dtRlead: 5.06 (197.5hz) dtWfoll: 0.25 (3963.7hz) dtRfoll: 6.22 (160.7hz) dtRlaptop: 32.57 (30.7hz) dtRphone: 33.84 (29.5hz) ``` @@ -947,6 +925,7 @@ INFO 2024-08-10 15:02:58 ol_robot.py:219 dt:33.34 (30.0hz) dtRlead: 5.06 (197.5h - 如果记录过程中断,可以通过重新运行相同的命令并添加 `--resume=true` 来恢复记录。 ⚠️ **重要提示**:在恢复时,需将 `--dataset.num_episodes` 设置为要额外记录的剧集数量(而不是数据集中目标的总剧集数量)。 + - 若要从头开始记录,请**手动删除**数据集目录。 **3. 记录参数** @@ -971,16 +950,18 @@ INFO 2024-08-10 15:02:58 ol_robot.py:219 dt:33.34 (30.0hz) dtRlead: 5.06 (197.5h :::tip 如果你的键盘按下后没有反应,可能你需要降低你pynput的版本,例如安装个1.6.8版本的。 + ```bash pip install pynput==1.6.8 ``` + ::: :::tip 假设你正在执行“将红色方块抓取并放入盒子”的任务: - 如果在操作过程中不慎将方块弄掉,或出现任何可能导致该剧集数据质量较差的情况,可以先将机械臂操控至休息状态(即弯曲并折叠回初始位置),然后按下左箭头键。此时系统将返回到环境准备阶段,刚刚录制的动作数据会被直接舍弃。 -- 如果本次任务完成得较快,机械臂已经成功完成操作并回到休息状态,而你不希望等待剩余时间结束,也可以按下左箭头键,以跳过剩余等待时间,直接进入下一个剧集前的环境准备阶段。 +- 如果本次任务完成得较快,机械臂已经成功完成操作并回到休息状态,而你不希望等待剩余时间结束,也可以按下右箭头键,以跳过剩余等待时间,直接进入下一个剧集前的环境准备阶段。 在录制过程中合理使用方向键,有助于避免失败动作污染数据集,并有效提升整体录制效率。 @@ -1007,6 +988,7 @@ pip install pynput==1.6.8 Linux 问题: 如果在记录过程中右箭头/左箭头/ESC 键无响应: + - 验证 `$DISPLAY` 环境变量是否已设置(参见 [pynput 限制](https://pynput.readthedocs.io/en/latest/limitations.html ))。 ## 可视化数据集 @@ -1039,7 +1021,6 @@ lerobot-dataset-viz \ - ## 回放一个数据集 :::tip @@ -1061,12 +1042,10 @@ lerobot-replay \ ## 训练及评估 -
-
[ACT](https://huggingface.co/docs/lerobot/act) @@ -1103,21 +1082,16 @@ lerobot-train \ 命令解释 -* **数据集指定**:我们通过 `--dataset.repo_id=${HF_USER}/so101_test` 参数提供了数据集。 -* **训练步数**:我们通过 `--steps=300000` 修改训练步数,算法默认为800000,根据自己的任务难易程度,来进行调整,如果不确定,可以调高一些,因为训练过程中会生成检查点,评估可以从检查点开始。 -* **策略类型**:我们使用 `policy.type=act` 提供了策略,同样你可以更换[act,diffusion,pi0,pi0fast,pi0fast,sac,smolvla]等策略,这将从 `configuration_act.py` 加载配置。重要的是,这个策略会自动适应您机器人(例如 `laptop` 和 `phone`)的电机状态、电机动作和摄像头数量,这些信息已保存在您的数据集中。 -* **设备选择**:我们提供了 `policy.device=cuda`,因为我们正在 Nvidia GPU 上进行训练,但您可以使用 `policy.device=mps` 在 Apple Silicon 上进行训练。 -* **可视化工具**:我们提供了 `wandb.enable=true` 来使用 [Weights and Biases](https://docs.wandb.ai/quickstart) 可视化训练图表。这是可选的,但如果您使用它,请确保您已通过运行 `wandb login` 登录。 - - - +- **数据集指定**:我们通过 `--dataset.repo_id=${HF_USER}/so101_test` 参数提供了数据集。 +- **训练步数**:我们通过 `--steps=300000` 修改训练步数,算法默认为800000,根据自己的任务难易程度,来进行调整,如果不确定,可以调高一些,因为训练过程中会生成检查点,评估可以从检查点开始。 +- **策略类型**:我们使用 `policy.type=act` 提供了策略,同样你可以更换[act,diffusion,pi0,pi0fast,pi0fast,sac,smolvla]等策略,这将从 `configuration_act.py` 加载配置。重要的是,这个策略会自动适应您机器人(例如 `laptop` 和 `phone`)的电机状态、电机动作和摄像头数量,这些信息已保存在您的数据集中。 +- **设备选择**:我们提供了 `policy.device=cuda`,因为我们正在 Nvidia GPU 上进行训练,但您可以使用 `policy.device=mps` 在 Apple Silicon 上进行训练。 +- **可视化工具**:我们提供了 `wandb.enable=true` 来使用 [Weights and Biases](https://docs.wandb.ai/quickstart) 可视化训练图表。这是可选的,但如果您使用它,请确保您已通过运行 `wandb login` 登录。 **评估** - 您可以使用 [`lerobot/record.py`](https://github.com/huggingface/lerobot/blob/main/lerobot/record.py) 中的 `record` 功能,但需要将策略训练结果训练结果权重文件作为输入。例如,运行以下命令记录 10 个评估回合: - ```bash lerobot-record \ --robot.type=so101_follower \ @@ -1128,18 +1102,15 @@ lerobot-record \ --dataset.repo_id=seeed/eval_test123 \ --dataset.single_task="Put lego brick into the transparent box" \ --policy.path=outputs/train/act_so101_test/checkpoints/last/pretrained_model -``` - - -1. `--policy.path` 参数,指示您的策略训练结果权重文件的路径(例如 `outputs/train/act_so101_test/checkpoints/last/pretrained_model`)。如果您将模型训练结果权重文件上传到 Hub,也可以使用模型仓库(例如 `${HF_USER}/act_so100_test`)。 +``` + +1. `--policy.path` 参数,指示您的策略训练结果权重文件的路径(例如 `outputs/train/act_so101_test/checkpoints/last/pretrained_model`)。如果您将模型训练结果权重文件上传到 Hub,也可以使用模型仓库(例如 `${HF_USER}/act_so100_test`)。 2. 数据集的名称`dataset.repo_id`以 `eval_` 开头,这个操作会在你评估的时候为你单独录制评估时候的视频和数据,将保存在eval_开头的文件夹下,例如`seeed/eval_test123`。 3. 如果评估阶段遇到`File exists: 'home/xxxx/.cache/huggingface/lerobot/xxxxx/seeed/eval_xxxx'`请先删除`eval_`开头的这个文件夹再次运行程序。 4. 当遇到`mean is infinity. You should either initialize with stats as an argument or use a pretrained model`请注意--robot.cameras这个参数中的front和side等关键词必须和采集数据集的时候保持严格一致。 -
-
[SmolVLA](https://huggingface.co/docs/lerobot/smolvla) @@ -1224,10 +1195,8 @@ lerobot-record \ --teleop.id=my_red_leader_arm \ ``` -
-
[Pi0](https://huggingface.co/docs/lerobot/pi0) @@ -1247,9 +1216,11 @@ pip install -e ".[pi]" ```bash pip install "lerobot[pi]@git+https://github.com/huggingface/lerobot.git" ``` + ::: **训练** + ```bash lerobot-train \ --policy.type=pi0 \ @@ -1292,8 +1263,8 @@ lerobot-record \ --dataset.num_episodes=10 \ --policy.path=outputs/pi0_training/checkpoints/last/pretrained_model ``` -
+
[Pi0.5](https://huggingface.co/docs/lerobot/pi05) @@ -1320,9 +1291,11 @@ pip install -e ".[pi]" ```bash pip install "lerobot[pi]@git+https://github.com/huggingface/lerobot.git" ``` + ::: **训练** + ```bash lerobot-train \ --dataset.repo_id=${HF_USER}/my_dataset \ @@ -1366,11 +1339,8 @@ lerobot-record \ --policy.path=outputs/pi05_training/checkpoints/last/pretrained_model ``` -
- -
[GR00T N1.5](https://huggingface.co/docs/lerobot/groot) @@ -1468,7 +1438,6 @@ lerobot-record \ License:该模型遵循 Apache 2.0 许可证(与原始 GR00T 仓库一致)。 -
@@ -1554,7 +1523,6 @@ LoRA 的学习率通常可以比全量微调更大一个量级(常见经验:
(可选)在训练时使用多GPU训练 - ## 1.训练步骤 ### 方式一:使用命令行参数进行多卡训练 @@ -1601,8 +1569,6 @@ $(which lerobot-train) \ --mixed_precision=fp16:使用 fp16 混合精度(如果硬件支持,也可以使用 bf16) - - 请注意,**bf16 需要硬件支持**,并非所有 GPU 都可以使用。 | 精度类型 | 硬件支持情况 | @@ -1613,50 +1579,32 @@ $(which lerobot-train) \ | bf16 | 仅部分较新的 GPU 支持(如 Ampere 及更新架构) | - - 如果你的 GPU 不支持 bf16,请在 accelerate 配置中选择 fp16, 或在命令行中显式指定 fp16。 - - ### 方式二:使用 accelerate 配置文件(可选) 如果您经常进行多卡训练,也可以将上述的训练配置进行保存,从而避免繁琐的命令行输入。 - - > **提示**:如果你不理解这一节的内容,或者只是想尽快跑起来训练, > **可以直接跳过本节,使用方式一(命令行参数)即可。** - - `accelerate config` 的作用是: **将您的硬件环境(GPU 数量、混合精度等)保存为一个配置文件, 以后运行 `accelerate launch` 时无需重复填写这些信息。** - - 它并不会改变 LeRobot 的训练逻辑,只是为了减少重复输入参数。 - - 如果只是**偶尔使用多 GPU**,或你是第一次尝试,**不使用它完全没有问题**。 - - --- - - 运行: - - ```bash accelerate config @@ -1665,36 +1613,20 @@ accelerate config 在交互式配置过程中,对于单机多 GPU 的常见场景,可以按如下方式选择: - - Compute environment:This machine - - Number of machines:1 - - Number of processes:使用的 GPU 数量(通常等于 GPU 张数) - - GPU ids to use:直接回车(表示使用所有 GPU) - - Mixed precision: - - 优先选择 fp16 - - 若确认 GPU 支持 bf16,也可选择 bf16 - - 完成配置后,可以直接使用一下命令进行训练: ```bash @@ -1715,8 +1647,6 @@ accelerate launch $(which lerobot-train) \ ``` - - ## 多 GPU 训练对于训练参数的影响以及调整策略 LeRobot 不会根据 GPU 数量自动调整学习率或训练步骤。以避免在用户在不知情的情况下改变训练行为。这与其他常用的分布式训练框架不同。 @@ -1737,8 +1667,6 @@ LeRobot 不会根据 GPU 数量自动调整学习率或训练步骤。以避免 - steps = 100000 - - 双卡训练(有效 batch size 变为 16): - batch_size 如果仍然被您设定为 8 @@ -1802,6 +1730,292 @@ accelerate launch --num_processes=2 $(which lerobot-train) \ 如需更高级的配置和故障排除,请参见[Accelerate]https://huggingface.co/docs/accelerate/index 文档。如果你想了解更多如何在大量GPU上训练,可以看看这份超棒的指南:[Ultrascale Playbook]。
+
+ (可选)在部署时使用异步推理 + +在不启用异步推理时,LeRobot 的控制流程可以理解为常规的顺序式 / 同步式推理:策略先预测一段动作,再执行这段动作,之后再等待下一次预测。对于较大的模型,这会导致机器人在等待新动作块时出现明显停顿。异步推理的目标,就是让机器人一边执行当前动作块,一边提前计算下一块动作,从而减少空等并提升响应性。异步推理适用于 LeRobot 支持的策略;包括 ACT、OpenVLA、Pi0、SmolVLA 这类按 chunk 输出动作的策略。由于推理和实际控制解耦,异步推理也有助于利用具有更强算力的机器来为机器人进行推理。 + +你可以在 Hugging Face 提供的[博客文章](https://huggingface.co/blog/async-robot-inference)中阅读更多关于异步推理的信息。 + +先让我们介绍一些基本概念: + +- 客户端:连接机械臂和相机,采集观测数据(如图像、机器人位姿等),把这些观测发送到服务器;同时接收服务器返回的动作块,并按顺序执行。 +- 服务器端:提供算力的设备,接收相机数据和机械臂数据,推理(也就是计算)出动作块发回客户端。它可以是连接机械臂和摄像头的设备本身,也可以是局域网内的另一台电脑,或是网上租赁的云端服务器。 +- 动作块:一系列的机械臂动作指令,由策略经过服务器端推理得到。 +- 同步推理:预测一块动作块、执行一块动作块;机器人在等待下一块动作时会出现等待动作块推理的间隙,这时候机械臂不会移动。在模型参数量更大并且算力不足的时候,推理的时间间隙是显著的,这时候机械臂会运动一段时间,然后停滞一段时间(推理),然后继续运动。 +- 异步推理:不同于同步推理,机器人执行当前动作块的同时,服务器已经在计算下一块动作;重叠部分会做聚合,以得到更及时的控制。 + +### 异步推理的三种部署场景 + +#### 1. 单机部署 + +机器人、相机、客户端、服务器都在同一台设备上。 +这是最简单的情况,服务器监听 127.0.0.1 即可,客户端也连接 127.0.0.1:端口。官方文档中的命令示例就是这个场景。 + +#### 2. 局域网部署 + +机器人和相机接在一台轻量设备上,策略服务器运行在同一局域网中的另一台高算力设备上。 +此时服务器必须监听一个可被其他机器访问的地址,客户端也必须连接服务器的局域网 IP,而不能再写 127.0.0.1。 + +#### 3. 跨网络 / 云端部署 + +策略服务器运行在公网可访问的云主机上,客户端通过公网连接它。 +这种方式可以使用云主机更强的 GPU。在网络状况良好的情况下,网络往返时间(网络延时)有时相对推理耗时较小,但这取决于你的实际网络环境。 + +> 安全提醒:LeRobot async inference 管线存在未认证 gRPC + pickle 反序列化的风险。如果服务器上有重要信息或者重要服务,公网部署时,不建议把服务直接裸露到互联网;更稳妥的做法是 VPN、SSH 隧道,或至少把安全组来源 IP 限制到你自己的客户端公网地址。 + +### 开始异步推理部署 + +#### Step1: 环境配置 + +首先,使用 pip 安装运行异步推理所需的额外依赖。客户端和服务器端均需要安装 lerobot 并安装额外依赖: + +```bash +pip install -e ".[async]" +``` + +#### Step2: 网络配置与检查 + +##### 1. 代理问题 + +如果你当前终端配置了代理,并且连接出现异常,可以临时取消代理环境变量: + +```bash +unset http_proxy https_proxy ftp_proxy all_proxy HTTP_PROXY HTTPS_PROXY FTP_PROXY ALL_PROXY +``` + +注意:以上的命令只对一个终端生效,如果你重新开了另一个终端窗口,需要重新运行该命令。 + +##### 2. 在防火墙 / 安全组放行端口 + +- 单机部署:通常可以跳过。 +- 局域网部署:需要在服务器端放行监听端口。 + 局域网放行监听端口示例(在服务器端运行): + +```bash +sudo ufw allow 8080/tcp +``` + +- 云端部署:需要在云服务器安全组中放行该端口,并尽量限制来源 IP。 + +如果是在云端服务器上运行: +在服务器管理页面的安全组放行 8080 端口,或使用其他已经放行的端口。不同云服务平台的方式并不统一,详见云平台服务商。 + +##### 3. 确认 IP 地址 + +单机部署可以跳过这一步(单机的 IP 地址恒为 127.0.0.1)。 + +如果是局域网部署: +需要确认并记住服务器端的局域网 IP 地址。客户端连接时,填写的应当是运行 policy_server 的那台机器的局域网 IP,而不是客户端自己的 IP。 + +Linux / Jetson / 树莓派: + +```bash +hostname -I +``` + +如果输出多个地址,一般选择当前局域网网卡对应的那个,例如 192.168.x.x。 +也可以使用: + +```bash +ip addr +``` + +查看当前联网网卡下的 inet 字段。 + +Windows: + +```bash +ipconfig +``` + +找到类似 IPv4 地址 . . . . . . . . . . . : 192.168.14.140 的字段,它就是该机器的局域网 IP 地址。 + +macOS: + +```bash +ifconfig +``` + +找到当前联网网卡对应的 inet 字段,它就是局域网 IP 地址。 + +我们需要将服务器端的局域网 IP 地址记住。我们将用`<局域网IP地址>`来指代它。 + +如果是云端服务器部署: +在服务器控制台寻找公网 IP,一般是这些名字之一: + +- Public IPv4 +- External IP +- Public IP address +- EIP +- 公网 IP + +我们需要将公网 IP 地址记住。我们将用`<服务器公网IP>`来指代它。 + +##### 4. 连接测试 + +- 单机部署:可跳过这一步 +- 局域网 / 云端部署:建议在客户端测试是否能访问服务器端口,测试例子如下: + +局域网示例:在客户端运行 + +```bash +nc -vz <局域网IP地址> 8080 +``` + +云端示例:在客户端运行 + +```bash +nc -vz <服务器公网IP> 8080 +``` + +#### Step3: 启动服务 + +##### 场景 A:单机部署 + +在一个终端中启动本地服务: + +```bash +python -m lerobot.async_inference.policy_server \ + --host=127.0.0.1 \ + --port=8080 +``` + +运行成功后,你需要保持这个终端打开,你需要新建新的终端才可以执行其他命令。 + +##### 场景 B:局域网内部署 + +在服务器端运行: + +```bash +python -m lerobot.async_inference.policy_server \ + --host=0.0.0.0 \ + --port=8080 +``` + +此时客户端连接时,--server_address 中填写的应当是服务器端的局域网 IP 地址,即 `<局域网IP地址>:8080`。 + +##### 场景 C:云端服务器部署 + +在服务器端运行: + +```bash +python -m lerobot.async_inference.policy_server \ + --host=0.0.0.0 \ + --port=8080 +``` + +此时客户端连接时,--server_address 中填写的应当是服务器的公网 IP 地址,即`<服务器公网IP>:8080`。 + +#### Step4: 选择推理参数 + +在客户端运行: + +```bash +python -m lerobot.async_inference.robot_client \ + --server_address=:8080 \ + --robot.type=so100_follower \ + --robot.port=/dev/tty.usbmodem585A0076841 \ + --robot.id=follower_so100 \ + --robot.cameras="{ laptop: {type: opencv, index_or_path: 0, width: 1920, height: 1080, fps: 30}, phone: {type: opencv, index_or_path: 0, width: 1920, height: 1080, fps: 30}}" \ + --task="dummy" \ + --policy_type=your_policy_type \ + --pretrained_name_or_path=user/model \ + --policy_device=cuda \ + --actions_per_chunk=50 \ + --chunk_size_threshold=0.5 \ + --aggregate_fn_name=weighted_average \ + --debug_visualize_queue_size=True +``` + +参数解释: + +- --server_address + 指定策略服务器的地址和端口。``应该换为 127.0.0.1(本机)或 `<局域网IP地址>`(局域网)或 `<服务器公网IP>`(云服务器)。 + +- --robot.type、--robot.port、--robot.id、--robot.cameras + 硬件设备参数,与数据集采集时的参数保持一致。 + +- --task + 任务的描述,SmolVLA 等视觉语言策略可以根据任务文本决定动作目标。 + +- --policy_type + 替换成具体策略名,例如: + + - smolvla + - act + +- --pretrained_name_or_path + 这个的值要替换为服务器端的模型路径,或者 Hugging Face 上的模型路径。 + +- --policy_device + 指定服务器端使用的推理设备。 + 可以是 cuda、mps 或 cpu。 + +- --actions_per_chunk=50 + 指定每次推理输出多少个动作。 + 这个值越大: + + - 优点:动作缓存更充足,不容易断流 + - 缺点:预测跨度更长,控制误差可能累计得更明显 + +- --chunk_size_threshold=0.5 + 指定何时向服务器请求下一块动作。 + 这是一个阈值,范围通常在 0 到 1 之间。 + 可以理解为:当当前动作队列剩余比例低于这个阈值时,客户端就会提前发送新的观测,请求下一块动作。 + + 这里设置为 0.5,表示: + + - 当当前动作块大约消耗到一半时 + - 客户端就开始请求下一块动作 + + 这个值越大,请求会越频繁,系统更灵敏,但服务器负载也更高。 + 这个值越小,就越接近同步推理的行为。 + +- --aggregate_fn_name=weighted_average + 指定重叠动作区间的聚合方式。 + + 在异步推理中,旧动作块还没完全执行完时,新动作块可能已经回来了。 + 这时两块动作会有一部分时间区间重叠,需要用一个聚合函数把它们合成最终执行动作。 + + weighted_average 的含义就是: + 对重叠部分使用加权平均的方式进行融合。 + + 这样通常能让动作切换更平滑,减少突变。 + +- --debug_visualize_queue_size=True + 是否在运行时可视化动作队列大小。 + 打开后可以更直观地看到队列是否频繁触底,从而帮助你调整 actions_per_chunk 和 chunk_size_threshold。 + +#### Step5: 根据机器人表现调整参数 + +在异步推理中,有两个同步推理没有的额外参数需要调整: + +| 参数 | 建议初始值 | 说明 | +|---|---:|---| +| actions_per_chunk | 50 | 策略一次输出多少动作。典型值:10-50。 | +| chunk_size_threshold | 0.5 | 当动作队列剩余比例 ≤ chunk_size_threshold 时,客户端会发送一个新的动作块。值的范围为 [0, 1]。 | + +当 --debug_visualize_queue_size=True 时,会在运行时绘制动作队列大小的变化情况。 + +异步推理需要平衡的是:服务器生成动作块的速度必须大于等于客户端消耗动作块的速度,否则动作队列会空,机器人将重新出现卡顿(可以在队列可视化中看到曲线触底)。 + +服务器生成动作块的速度受模型大小、设备类型、显存/内存、GPU 算力等影响。 +客户端消耗动作块的速度受设定的执行 fps 影响。 + +如果队列频繁空,需要加大 actions_per_chunk、chunk_size_threshold,或者减少 fps。 +当队列曲线波动频繁,但是队列剩余动作一直充足时,可以适当降低 chunk_size_threshold。 + +一般来说: + +- actions_per_chunk 经验值在 10-50 +- chunk_size_threshold 经验值在 0.5-0.7,建议调整时从 0.5 开始,慢慢加大。 + +
+ +
+ +
如果你遇到了以下报错: @@ -1815,44 +2029,42 @@ accelerate launch --num_processes=2 $(which lerobot-train) \ pip install datasets==2.19 ``` - 训练可能需要几个小时。您将在 `outputs/train/act_so101_test/checkpoints` 目录中找到训练结果权重文件。 要从某个训练结果权重文件恢复训练,下面是一个从 `act_so101_test` 策略的最后一个训练结果权重文件恢复训练的示例命令: + ```bash lerobot-train \ --config_path=outputs/train/act_so101_test/checkpoints/last/pretrained_model/train_config.json \ --resume=true ``` - - -
- -
- - ## FAQ - 如果使用本文档教程,请git clone本文档推荐的github仓库`https://github.com/Seeed-Projects/lerobot.git`,本文档推荐的仓库是验证过后的稳定版本,Lerobot官方仓库是实时更新的最新版本,会出现一些无法预知的问题,例如数据集版本不同,指令不同等。 - - 如果校准舵机ID时候遇到 + ```bash `Motor ‘gripper’ was not found, Make sure it is connected` ``` + 请仔细检查通讯线是否与舵机连接正常,电源是否正确电压供电。” - 如果遇到 + ```bash Could not connect on port "/dev/ttyACM0" ``` + 并且通过`ls /dev/ttyACM*`看到是有ACM0存在的,则是忘记给串口权限了,终端输入`sudo chmod 666 /dev/ttyACM*` 即可` - 如果遇到 + ```bash No valid stream found in input file. Is -1 of the desired media type? ``` + 请安装ffmpeg7.1.1,`conda install ffmpeg=7.1.1 -c conda-forge`。
@@ -1860,27 +2072,35 @@ lerobot-train \
- 如果遇到 + ```bash ConnectionError: Failed to sync read 'Present_Position' on ids=[1,2,3,4,5,6] after 1 tries. [TxRxResult] There is no status packet! ``` + 需要检查对应端口号的机械臂是否接通电源,总线舵机是否出现数据线松动或者脱落,哪个舵机灯不亮就是前面那个舵机的线松了。 - 如果校准机械臂的时候遇到 + ```bash Magnitude 30841 exceeds 2047 (max for sign_bit_index=11) ``` + 对机械臂进行重新断电和上电,再次尝试校准机械臂。如果在校准过程中遇到 MAX 角度达到上万的值也可以使用这个方法;如果仍然无效,则需要对相应舵机重新进行舵机校准(中位校准和 ID 写入)。 - 如果评估阶段遇到 + ```bash File exists: 'home/xxxx/.cache/huggingface/lerobot/xxxxx/seeed/eval_xxxx' ``` + 请先删除`eval_`开头的这个文件夹再次运行程序。 - 如果评估阶段遇到 + ```bash `mean` is infinity. You should either initialize with `stats` as an argument or use a pretrained model ``` + 请注意--robot.cameras这个参数中的front和side等关键词必须和采集数据集的时候保持严格一致。 - 如果你维修或者更换过机械臂零件,请完全删除`~/.cache/huggingface/lerobot/calibration/robots`或者`~/.cache/huggingface/lerobot/calibration/teleoperators`下的文件并重新校准机械臂,否则会出现报错提示,校准的机械臂信息会存储该目录下的json文件中。 @@ -1893,7 +2113,6 @@ lerobot-train \ - 如果程序提示无法读取USB摄像头图像数据,请确保USB摄像头不是接在Hub上的,USB摄像头必须直接接入设备,确保图像传输速率快。 - :::tip 如果你遇到无法解决的软件问题或环境依赖问题,除了查看本教程末尾的常见问题(FAQ)部分外,请及时在 [LeRobot 平台](https://github.com/huggingface/lerobot) 或 [LeRobot Discord 频道](https://discord.gg/8TnwDdjFGU) 反馈问题。 :::