ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

XLeRobot LLM Agent 实战:用视觉-语言模型与 VLA 策略打造自主决策的家务机器人

XLeRobot LLM Agent 实战:用视觉-语言模型与 VLA 策略打造自主决策的家务机器人 XLeRobot LLM Agent 实战用视觉-语言模型与 VLA 策略打造自主决策的家务机器人【免费下载链接】XLeRobotXLeRobot: Practical Dual-Arm Mobile Home Robot for $660项目地址: https://gitcode.com/GitHub_Trending/xl/XLeRobot想象一下告诉机器人去清理我的厨房然后看着它自己规划路径、移动并执行任务。本文基于 XLeRobot 官方中文文档中的 LLM Agent 教程完整讲解如何借助 RoboCrew 具身 Agent 库为这台约 $660 的双臂移动家用机器人装上大脑以摄像头视觉与语音命令感知环境与接收指令通过调用移动工具自主导航并通过 VLA视觉-语言-动作策略执行抓取、放置等精细操作。读完本文你将掌握从安装依赖、配置 API Key、设置 USB 设备规则到编写硬编码任务 Agent、语音控制 Agent、最终组合 VLA 操作工具的完整实战流程。LLM Agent 控制机器人如何听懂并执行任务LLM Agent 方案的核心思路是将机器人的底层能力移动、转向、手臂操作封装为一个个工具tool交给大语言模型LLM作为可调用的函数LLM 通过摄像头图像理解当前环境结合用户下达的任务文本自主决定按什么顺序调用哪些工具从而完成观察 → 决策 → 执行 → 再观察的闭环。具体到 XLeRobot 上agent 的三条感知/执行链路为摄像头视觉主摄像头采集环境图像经特殊增强后送入 LLM使机器人能够理解自身位置与周围物体语音命令通过麦克风接收自然语言指令支持自定义唤醒词通过 TTS 让机器人开口回应VLA 策略操作当任务涉及抓取、放置等精细动作时调用训练好的 VLA 策略如 ACT驱动机械臂完成操作。文档中的演示案例是agent 控制 XLeRobot 完成抓取笔记本并交给人类的完整任务。下文的三个实战阶段将逐步搭建这个 agent。一、环境准备安装 RoboCrew 与配置 API Key创建 agent 使用的是 RoboCrew 库——一个专门为具身 agent 设计的 Python 库。在控制设备树莓派或笔记本电脑上创建新的虚拟环境并安装pip install robocrew在脚本同级目录创建.env文件写入 LLM 的 API Key 以便连接大模型GOOGLE_API_KEYyour gemini api key here二、第一个 Agent执行硬编码任务首先实现一个最简单的 agent它只执行一个硬编码的任务如靠近人类跑完即结束。这一阶段可以验证摄像头、舵机控制器与 LLM 调用链路是否全部打通。2.1 初始化摄像头与舵机控制器from robocrew.core.camera import RobotCamera from robocrew.core.LLMAgent import LLMAgent from robocrew.robots.XLeRobot.tools import create_move_forward, create_turn_right, create_turn_left from robocrew.robots.XLeRobot.servo_controls import ServoControler # 设置主摄像头 main_camera RobotCamera(/dev/camera_center) # 摄像头usb端口 例如: /dev/video0 #设置舵机控制器 right_arm_wheel_usb /dev/arm_right # 提供您的右臂usb端口。例如: /dev/ttyACM1 servo_controler ServoControler(right_arm_wheel_usbright_arm_wheel_usb) #设置工具 move_forward create_move_forward(servo_controler) turn_left create_turn_left(servo_controler) turn_right create_turn_right(servo_controler)需要特别说明的是XLeRobot 的右臂同时承担轮子驱动的角色通过右臂的舵机总线控制移动底座因此right_arm_wheel_usb传入的是连接到轮子的那个 USB 端口例如/dev/ttyACM1。这一点与仓库中的机器人配置相互印证——在 config_xlerobot.py 中XLerobotConfig定义了port1: str /dev/ttyACM0连接 so101 手臂与头部摄像头的总线和port2: str /dev/ttyACM1两个端口分别对应左臂/头部与右臂/轮子两条舵机总线。2.2 初始化并运行 Agent# 初始化agent agent LLMAgent( modelgoogle_genai:gemini-3-flash-preview, tools[ move_forward, turn_left, turn_right, ], main_cameramain_camera, servo_controlerservo_controler, ) agent.task Approach a human. agent.go()关键参数说明参数说明model使用的 LLM 模型支持 LangChain 表示法中的任意模型tools提供给 LLM 的工具列表即上面创建的移动工具main_camera主摄像头对象LLM 通过它获取环境图像servo_controler舵机控制器对象task赋予 agent 的任务描述此处为硬编码任务当任务执行完毕agent 会通过调用finish_task工具自行结束工作。在发送到 LLM 之前摄像头图像会经过特殊增强处理使机器人更容易理解其环境——这正是 agent 看懂世界的视觉基础。2.3 完整代码from robocrew.core.camera import RobotCamera from robocrew.core.LLMAgent import LLMAgent from robocrew.robots.XLeRobot.tools import create_move_forward, create_turn_right, create_turn_left from robocrew.robots.XLeRobot.servo_controls import ServoControler # 设置主摄像头 main_camera RobotCamera(/dev/camera_center) # 摄像头usb端口 例如: /dev/video0 #设置舵机控制器 right_arm_wheel_usb /dev/arm_right # 提供您的右臂usb端口。例如: /dev/ttyACM1 left_arm_head_usb /dev/arm_left # 提供您的左臂usb端口。例如: /dev/ttyACM0 servo_controler ServoControler(right_arm_wheel_usb, left_arm_head_usb) #设置工具 move_forward create_move_forward(servo_controler) turn_left create_turn_left(servo_controler) turn_right create_turn_right(servo_controler) # 初始化agent agent LLMAgent( modelgoogle_genai:gemini-3-flash-preview, tools[move_forward, turn_left, turn_right], main_cameramain_camera, servo_controlerservo_controler, ) agent.task Approach a human. agent.go()三、设置 Udev 规则让 USB 端口名称恒定在进入更高级的示例之前有一个可选但强烈推荐的步骤——让手臂和摄像头的 USB 端口名称保持恒定避免每次树莓派重启后这些名称被交换例如/dev/arm_right与/dev/arm_left互换导致 agent 接错设备。RoboCrew 已内置一个实用程序把配置 udev 规则的复杂过程简化为几次点击robocrew-setup-usb-modules运行后实用程序会要求你断开所有 USB 连接然后逐个重新连接——这样每个 USB 设备都会获得固定的名称agent 脚本中的端口路径也就稳定可靠了。四、语音控制的 Agent唤醒词、语音输入与 TTS简单的 agent 已经跑通现在为它增加听与说的能力让机器人可以通过麦克风接收语音命令。4.1 安装 Portaudio首先安装 Portaudio使控制设备能够采集声音sudo apt install portaudio19-dev将带有麦克风的声卡连接到 agent控制设备如果需要机器人开口回应还可以选配扬声器。4.2 修改 Agent 初始化agent LLMAgent( modelgoogle_genai:gemini-3-flash-preview, tools[move_forward, turn_left, turn_right], main_cameramain_camera, servo_controlerservo_controler, sounddevice_index2, # 提供您的麦克风设备索引。 wakewordhey robot, # 可选 - 设置自定义唤醒词默认为robot ttsTrue, # 启用文本转语音机器人可以说话。 ) agent.go()语音相关的四个核心参数sounddevice_index带有麦克风的声卡设备索引可用sounddevice相关工具查询本机设备列表后填入wakeword唤醒词默认为robot。当机器人听到的句子中包含该词时会把整句话视为一条新任务开始执行否则忽略该句——这保证了 agent 不会对无关对话作出反应tts设为True时启用文本转语音机器人可以用语音回应history_len机器人应在内存中保留最近多少个动作避免内存溢出详见下一阶段的完整示例。4.3 完整代码from robocrew.core.camera import RobotCamera from robocrew.core.LLMAgent import LLMAgent from robocrew.robots.XLeRobot.tools import create_move_forward, create_turn_right, create_turn_left from robocrew.robots.XLeRobot.servo_controls import ServoControler # 设置主摄像头 main_camera RobotCamera(/dev/camera_center) # 摄像头usb端口 例如: /dev/video0 #设置舵机控制器 right_arm_wheel_usb /dev/arm_right # 提供您的右臂usb端口。例如: /dev/ttyACM1 servo_controler ServoControler(right_arm_wheel_usbright_arm_wheel_usb) #设置工具 move_forward create_move_forward(servo_controler) turn_left create_turn_left(servo_controler) turn_right create_turn_right(servo_controler) # 初始化agent agent LLMAgent( modelgoogle_genai:gemini-3-flash-preview, tools[move_forward, turn_left, turn_right], main_cameramain_camera, servo_controlerservo_controler, sounddevice_index2, # 提供您的麦克风设备索引。 wakewordhey robot, # 可选 - 设置自定义唤醒词默认为robot ttsTrue, # 启用文本转语音机器人可以说话。 ) agent.task Wait for the voice commands and execute. agent.go()运行代码让机器人听令去往某个地方吧五、激活手臂操作将 VLA 策略封装为 Agent 工具这是 agent 最先进也最实用的部分——通过 VLA 策略进行手臂操作。有了它机器人可以执行扔垃圾、从厨房端茶等全方位的家务任务。5.1 前置条件训练 VLA 策略首先需要训练一个 agent 稍后调用的 VLA 策略。完整的训练流程数据采集、训练、部署见仓库中的 VLA (1) ACT 教程。该教程覆盖了用 Leader Arm 或 VR 遥操作记录单臂/双臂数据集并强调头部舵机角度保持一致、摄像头完整覆盖操作区域等关键细节使用 LeRobot 框架训练 ACT 等策略将策略部署到机器人本地或外部 GPU 服务器的异步推理流程。这里假设你已经训练好了一个 VLA 策略它可以从桌子上抓取笔记本并放入机器人篮子用于后续运输。5.2 创建 VLA 操作工具from robocrew.robots.XLeRobot.tools import create_vla_single_arm_manipulation pick_up_notebook create_vla_single_arm_manipulation( tool_nameGrab_a_notebook, tool_descriptionManipulation tool to grab a notebook from the table and put it to your basket., task_promptGrab a notebook., server_address0.0.0.0:8080, policy_nameGrigorij/act_right-arm-grab-notebook-2, policy_typeact, arm_portright_arm_wheel_usb, servo_controlerservo_controler, camera_config{main: {index_or_path: /dev/camera_center}, right_arm: {index_or_path: /dev/camera_right}}, main_camera_objectmain_camera, policy_devicecpu, )参数语义说明参数说明tool_name/tool_description工具的名称与描述这就是 LLM 看到的内容——LLM 据此判断何时调用该工具因此描述应写清楚工具能做什么task_prompt触发该策略执行时的任务提示词server_addressVLA 策略服务器地址host:port工具本身是策略客户端所有 VLA 计算都在服务器端运行policy_name训练好的策略在模型库HF hub上的名称policy_type策略类型如actarm_port执行操作的机械臂 USB 端口camera_config摄像头配置必须与数据集收集期间使用的摄像头配置一致主摄像头 右臂摄像头policy_device策略推理设备如cpuexecution_time可选参数限制单次策略执行的最长时间见完整代码中的give_notebook示例创建完成后把pick_up_notebook加入 agent 的tools列表即可。你可以创建任意数量的操作工具覆盖不同的任务。5.3 运行 VLA 策略服务器工具是策略客户端因此必须在服务器端启动策略服务。轻量级 ACT 策略可以直接在树莓派上运行对于其他更消耗资源的策略如 SmolVLA、PI0.5则需要运行在不同计算机上。启动命令python -m lerobot.async_inference.policy_server \ --host0.0.0.0 \ --port8080如果使用本地网络中的外部计算机作为服务器请将其 IP 提供给server_address参数而不是用0.0.0.0例如server_address123.234.12.34:80805.4 完整示例抓取笔记本并交给人类在完整代码中除了 VLA 操作工具还加入了更多移动工具以实现更精确的导航前进/后退、左右横移、转向、环视look_around、以及精确定位模式go_to_precision_mode/go_to_normal_mode切换。完整的 agent 初始化还展示了history_len保留最近 8 个动作、camera_fov摄像头视场角90 度与debug_modeTrue调试模式的用法from robocrew.core.camera import RobotCamera from robocrew.core.LLMAgent import LLMAgent from robocrew.robots.XLeRobot.tools import \ create_vla_single_arm_manipulation, \ create_go_to_precision_mode, \ create_go_to_normal_mode, \ create_move_backward, \ create_move_forward, \ create_strafe_right, \ create_strafe_left, \ create_look_around, \ create_turn_right, \ create_turn_left from robocrew.robots.XLeRobot.servo_controls import ServoControler # 设置主摄像头 main_camera RobotCamera(/dev/camera_center) # 摄像头usb端口 例如: /dev/video0 #设置舵机控制器 right_arm_wheel_usb /dev/arm_right # 提供您的右臂usb端口。例如: /dev/ttyACM1 left_arm_head_usb /dev/arm_left # 提供您的左臂usb端口。例如: /dev/ttyACM0 servo_controler ServoControler(right_arm_wheel_usb, left_arm_head_usb) #设置工具 move_forward create_move_forward(servo_controler) move_backward create_move_backward(servo_controler) turn_left create_turn_left(servo_controler) turn_right create_turn_right(servo_controler) strafe_left create_strafe_left(servo_controler) strafe_right create_strafe_right(servo_controler) look_around create_look_around(servo_controler, main_camera) go_to_precision_mode create_go_to_precision_mode(servo_controler) go_to_normal_mode create_go_to_normal_mode(servo_controler) pick_up_notebook create_vla_single_arm_manipulation( tool_nameGrab_a_notebook, tool_descriptionManipulation tool to grab a notebook from the table and put it to your basket., task_promptGrab a notebook., server_address0.0.0.0:8080, policy_nameGrigorij/act_right-arm-grab-notebook-2, policy_typeact, arm_portright_arm_wheel_usb, servo_controlerservo_controler, camera_config{main: {index_or_path: /dev/camera_center}, right_arm: {index_or_path: /dev/camera_right}}, main_camera_objectmain_camera, policy_devicecpu, ) give_notebook create_vla_single_arm_manipulation( tool_nameGive_a_notebook_to_a_human, tool_descriptionManipulation tool to take a notebook from your basket and give it to human., task_promptGrab a notebook and give it to a human., server_address0.0.0.0:8080, policy_nameGrigorij/act_right_arm_give_notebook, policy_typeact, arm_portright_arm_wheel_usb, servo_controlerservo_controler, camera_config{main: {index_or_path: /dev/camera_center}, right_arm: {index_or_path: /dev/camera_right}}, main_camera_objectmain_camera, policy_devicecpu, execution_time45, ) # 初始化agent agent LLMAgent( modelgoogle_genai:gemini-3-flash-preview, system_promptsystem_prompt, tools[ move_forward, move_backward, strafe_left, strafe_right, turn_left, turn_right, look_around, go_to_precision_mode, go_to_normal_mode, pick_up_notebook, give_notebook, ], history_len8, main_cameramain_camera, camera_fov90, servo_controlerservo_controler, debug_modeTrue, ) agent.task Approach blue notebook, grab it from the table and give it to human. Do not approach human until you grabbed a notebook. agent.go()注意这个任务描述设计得很讲究Approach blue notebook, grab it from the table and give it to human. Do not approach human until you grabbed a notebook.—— 通过补充在抓到笔记本之前不要靠近人类的约束引导 LLM 按正确的顺序编排工具调用。至此一个具备**自主导航移动工具语音交互唤醒词/TTS精细操作VLA 策略**完整能力的 XLeRobot LLM Agent 就搭建完成了。提示你的机器人从桌子上抓取笔记本并交给你它就会开始工作。六、进阶参考从仓库源码理解底层能力理解 agent 背后的底层能力有助于你更合理地设计工具集与任务描述舵机总线与端口分配仓库 config_xlerobot.py 中的XLerobotConfig定义了port1/port2双总线结构并给出了teleop_keys键盘映射前进i、后退k、左移j、右移l、左转u、右转o、加速n、减速m、退出b与文档中右臂总线同时驱动轮子的用法对应双臂底座头部的完整控制参考 4_xlerobot_teleop_keyboard.py其中定义了左右臂各自的关节/笛卡尔空间按键映射、头部双电机控制head_motor_1/head_motor_2、以及基于SO101Kinematics逆运动学的轨迹执行逻辑——agent 的移动/环视工具正是这类舵机控制能力的封装VLA 策略的数据与部署链路参考 VLA (1) ACT 教程其中说明了如何用 VR/Leader Arm 采集与 agent 工具camera_config一致的多摄像头数据集、训练 ACT 策略并通过python -m lerobot.async_inference.policy_server异步推理服务把策略暴露给 agent 工具调用该教程还提示需要保证训练时与 agent 运行时头部舵机角度一致RoboCrew 的ServoControler.turn_head_to_vla_position()可复现标准摄像头角度多策略选择除了 ACT仓库文档还提供了 SmolVLAVLA_pi05.md、VLA_smol.md等其他 VLA 方案可作为 agent 工具集进一步扩展的方向。从整体架构看XLeRobot 的 LLM Agent 方案将规划LLM 高层决策与控制舵机/VLA 低层执行解耦LLM 负责理解任务与环境、编排工具调用顺序VLA 策略负责单步操作的精细执行。这种分层设计让机器人既能理解去清理我的厨房这样的高层指令又能完成从桌上抓取笔记本这样的低层精细动作是低成本家用机器人走向自主决策的一条务实路径。【免费下载链接】XLeRobotXLeRobot: Practical Dual-Arm Mobile Home Robot for $660项目地址: https://gitcode.com/GitHub_Trending/xl/XLeRobot创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表