今天给大家分享一下 LeRobot 具身智能机械臂 SO-ARM100 的完整使用流程,包括设备组装、环境配置、远程控制、数据录制到模型训练的全过程。适合刚入门具身智能的小伙伴参考学习。
一、前期准备与资源获取
在开始之前,我们需要准备好相关的资源和工具:
-
官方资源:
- LeRobot 开源项目学习社区:http://wiki.wowrobo.com/zh/koch-001
- GitHub 仓库:https://github.com/huggingface/lerobot
- 入门视频教程:LeRobot具身智能机械臂实操入门课程-02:相机选型、接线与代码调试_哔哩哔哩_bilibili
-
必要设备:
- 主机械臂(扶手)12V/5A
- 从机械臂(抓手)12V/10A
- 双端 Type-C 线
- 电脑拓展坞或两个 Type-C 转 USB 转接头
- 摄像头(2K USB Camera 和 1080P USB Camera)
二、设备组装与接线
1. 硬件连接要点
- 主机械臂和从机械臂通过双端 Type-C 连接电脑拓展坞,或使用两个 Type-C 转 USB 转接头连接电脑
- 特别注意:相机需要直接连接电脑,不能接拓展坞!
- 确保电源适配正确:主机械臂 12V/5A,从机械臂 12V/10A
2. 组装检查
组装完成后,建议参考官方视频教程中的标准示意图进行检查,确保每个部件安装到位,接线正确。
三、环境配置
1. 项目下载
首先克隆 LeRobot 项目到本地:
git clone https://github.com/huggingface/lerobot.git
或者直接下载 ZIP 压缩包:https://github.com/huggingface/lerobot
2. 创建并激活虚拟环境
使用 conda 创建专门的虚拟环境:
conda create -n lerobot python=3.10
conda activate lerobot
3. 安装依赖
进入项目目录并安装所需依赖:
cd lerobot
pip install -e ".[feetech]" -i https://pypi.tuna.tsinghua.edu.cn/simple
对于 Linux 系统,还需要安装 ffmpeg:
conda install -y -c conda-forge ffmpeg
pip uninstall -y opencv-python
conda install -y -c conda-forge "opencv>=4.10.0"
四、机械臂端口检测与配置
1. 查找端口号
运行以下脚本检测机械臂对应的端口号:
python lerobot/scripts/find_motors_bus_port.py
操作步骤:
- 运行脚本,记录当前可用端口
- 拔下机械臂 USB 线,按回车
- 对比前后端口变化,确定机械臂对应的端口号
2. 修改配置文件
找到配置文件:lerobot/common/robot_devices/robots/configs.py
修改So100RobotConfig
类中的端口设置,将检测到的端口号填入:
@RobotConfig.register_subclass("so100")
@dataclass
class So100RobotConfig(ManipulatorRobotConfig):calibration_dir: str = ".cache/calibration/so100"max_relative_target: int | None = Noneleader_arms: dict[str, MotorsBusConfig] = field(default_factory=lambda: {"main": FeetechMotorsBusConfig(port="COM5", # 主机械臂端口motors={"shoulder_pan": [1, "sts3215"],"shoulder_lift": [2, "sts3215"],"elbow_flex": [3, "sts3215"],"wrist_flex": [4, "sts3215"],"wrist_roll": [5, "sts3215"],"gripper": [6, "sts3215"],},),})follower_arms: dict[str, MotorsBusConfig] = field(default_factory=lambda: {"main": FeetechMotorsBusConfig(port="COM4", # 从机械臂端口motors={# 电机配置与主机械臂相同"shoulder_pan": [1, "sts3215"],"shoulder_lift": [2, "sts3215"],"elbow_flex": [3, "sts3215"],"wrist_flex": [4, "sts3215"],"wrist_roll": [5, "sts3215"],"gripper": [6, "sts3215"],},),})
五、相机配置
1. 相机连接测试
确保相机直接连接电脑,然后通过系统的相机应用检查相机是否工作正常。
2. 确定相机索引
运行以下脚本测试相机并生成图像:
python lerobot/common/robot_devices/cameras/opencv.py --images-dir outputs/images_from_opencv_cameras
查看生成的图像,确定每个相机对应的索引。
3. 配置相机参数
修改configs.py
文件中的相机配置,设置正确的相机索引:
cameras: dict[str, CameraConfig] = field(default_factory=lambda: {"laptop": OpenCVCameraConfig(camera_index=0, # 侧面桌面相机fps=30,width=640,height=480,),"phone": OpenCVCameraConfig(camera_index=2, # 顶部相机fps=30,width=640,height=480,),}
)
六、远程操作测试
完成上述配置后,可以进行第一次远程操作测试:
python lerobot/scripts/control_robot.py --robot.type=so100 --control.type=teleoperate
如果一切正常,此时应该可以通过主机械臂控制从机械臂,实现主从一致操作,同时会显示相机画面。
七、数据集录制
1. 准备工作
- 确保相机角度和画面符合要求
- 准备好要抓取的目标物体(如红色方块)和放置容器
- 建议至少录制 50 组数据,涵盖 5 个不同位置,每个位置重复 10 次
2. 录制命令
使用以下命令开始录制数据集:
python lerobot/scripts/control_robot.py --robot.type=so100 --control.type=record --control.fps=30 --control.single_task="Grasp a lego block and put it in the bin." --control.repo_id=D:/so100_test --control.warmup_time_s=5 --control.episode_time_s=30 --control.reset_time_s=30 --control.num_episodes=2 --control.push_to_hub=false
参数说明:
warmup_time_s
:初始化时间episode_time_s
:每次收集数据的时间reset_time_s
:每次数据收集之间的准备时间num_episodes
:预期收集的数据集数量push_to_hub
:是否将数据上传到 HuggingFace Hubrepo_id
:数据集存储路径
3. 解决录制问题
问题 1:control.tags 参数问题
修改lerobot/scripts/control_robot.py
文件,在control_robot
函数中添加以下代码:
@parser.wrap()
def control_robot(cfg: ControlPipelineConfig):init_logging()logging.info(pformat(asdict(cfg)))# 新增两行if isinstance(cfg.control, RecordControlConfig):cfg.control.tags = ["so100", "tutorial"]robot = make_robot_from_config(cfg.robot)# ...
问题 2:Unknown encoder 'libsvtav1'
修改lerobot/common/datasets/video_utils.py
文件,将编码器改为 libx264:
vcodec: str = "libx264"
或者按照官方建议,在 Linux 上重新安装 ffmpeg:
conda install -c conda-forge ffmpeg
八、Hugging Face 配置
1. 登录 Hugging Face
首先需要在 Hugging Face 上注册账号,然后在终端中登录:
huggingface-cli login --token 你的令牌 --add-to-git-credential
将你的令牌替换上述命令中的 "你的令牌",令牌可以在 Hugging Face 个人设置中获取。
2. 设置用户名
$env:HF_USER = "你的用户名"
九、数据集可视化
可以通过 Hugging Face 的在线工具可视化数据集:
- 访问:Visualize Dataset
- 输入你的数据集路径(如:
acssdsd/so100_test
) - 即可查看数据集中的样本、 episodes 和语言指令
十、机器人重播
可以让机器人自动复现录制的动作:
python lerobot/scripts/control_robot.py --robot.type=so100 --control.type=replay --control.fps=30 --control.repo_id=你的用户名/so100_test --control.episode=0
十一、模型训练
1. 安装 CUDA 和 PyTorch
确保安装了支持 CUDA 的 PyTorch 版本,LeRobot 需要 torch>=2.2.1。
根据你的 CUDA 版本从PyTorch 官网或下载页面选择合适的版本安装。
例如,对于 CUDA 12.1 和 Python 3.10:
pip install torch-2.2.1+cu121-cp310-cp310-win_amd64.whl
2. 开始训练
python lerobot/scripts/train.py --dataset.repo_id=你的用户名/so100_test --policy.type=act --output_dir=outputs/train/act_so100_test --job_name=act_so100_test --device=cuda --wandb.enable=true
如果不需要使用 Weights and Biases 进行可视化,可以先禁用:
wandb disabled
训练过程可能需要几个小时,具体取决于数据集大小和硬件性能。训练完成后,检查点将保存在outputs/train/act_so100_test/checkpoints
目录下。
总结
本文详细介绍了 LeRobot 具身智能机械臂 SO-ARM100 从硬件组装、环境配置到模型训练的完整流程。通过这些步骤,你可以搭建起一个完整的具身智能系统,实现自定义抓取任务。
实际操作中,可能会遇到各种问题,建议参考官方文档和社区资源进行排查。希望这篇指南能帮助你顺利入门具身智能机器人开发!
如果有任何问题或建议,欢迎在评论区留言讨论。
参考资料:
- LeRobot 官方文档
- WowRobo Wiki
- Seeed Studio 文档