largemodel 是一个基于 ROS2 Humble 的机器人 AI 服务节点包,集成了语音识别(ASR)、大模型任务规划、双层 AI 决策、动作执行和语音合成(TTS)等功能。该包使机器人能够理解用户的自然语言指令,通过大模型进行任务规划,并自主执行导航、机械臂控制、物体抓取等多种动作。
┌─────────────────────────────────────────────────────────────────┐
│ largemodel_control.launch.py │
├─────────────┬─────────────────┬─────────────────┬───────────────┤
│ camera_arm │ model_service │ action_service │ asr │
│ _kin │ 节点 │ 节点 │ 节点 │
├─────────────┴─────────────────┴─────────────────┴───────────────┤
│ large_model_interface (共用工具) │
└─────────────────────────────────────────────────────────────────┘
功能:语音唤醒 → 录音 → 语音识别
发布话题:
| 话题 | 类型 | 说明 |
|------|------|------|
| /asr | String | ASR 识别结果 |
| /wakeup | Bool | 唤醒信号 |
| /beep | UInt16 | 蜂鸣器控制 |
| /record_status | Bool | 录音状态 |
功能:AI 大脑,调用大模型进行任务规划和执行
双层 AI 架构:
订阅话题:
| 话题 | 说明 |
|------|------|
| /asr | ASR 识别结果 |
| /actionstatus | 动作执行反馈 |
| /seewhat_handle | 视觉触发信号 |
功能:解析并执行机器人动作
支持的动作函数(18种):
| 类别 | 动作 | 函数签名 |
|---|---|---|
| 基础移动 | 左转/右转 | move_left(x, speed), move_right(x, speed) |
| 基础移动 | 漂移/跳舞 | drift(), dance() |
| 基础移动 | 速度控制 | set_cmdvel(x, y, z, duration) |
| 导航 | 导航到点 | navigation(point_name) |
| 导航 | 获取位置 | get_current_pose() |
| 机械臂 | 上下/摇头点头鼓掌 | arm_up(), arm_down(), arm_shake(), arm_nod(), arm_applaud() |
| 机械臂 | 抓取/放置 | grasp_obj(x1,y1,x2,y2), putdown() |
| 机械臂 | Apriltag 分拣 | apriltag_sort(id), apriltag_remove_higher(h) |
| 机械臂 | 颜色追踪移除 | color_remove_higher(color, h) |
| 视觉 | 追踪/巡线 | track(x1,y1,x2,y2), follw_line_clear() |
| 系统 | 等待/结束 | wait(seconds), finish_dialogue(), finishtask() |
largemodel/
├── config/
│ ├── yahboom.yaml # 主配置文件
│ ├── large_model_interface.yaml # 大模型 API 配置
│ └── map_mapping.yaml # 地图导航点配置
├── launch/
│ └── largemodel_control.launch.py # 启动文件
├── largemodel/
│ ├── __init__.py
│ ├── asr.py # 语音识别节点
│ ├── model_service.py # 模型服务节点
│ └── action_service.py # 动作执行节点
├── utils/
│ ├── large_model_interface.py # 大模型接口封装
│ ├── mic_serial.py # 串口通信工具
│ ├── promot.py # Prompt 模板
│ └── dify_client2.py # Dify API 客户端
├── resources_file/
│ └── system_vioce/ # 系统提示音
│ ├── zh/ # 中文提示音
│ └── en/ # 英文提示音
├── test/ # 测试文件
├── package.xml
└── setup.py
支持国内版和国际版两种模式:
# 国内版本参数
asr:
ros__parameters:
VAD_MODE: 2
sample_rate: 16000
use_oline_asr: True
language: 'zh'
regional_setting: "China"
action_service:
ros__parameters:
text_chat_mode: True # True: 文字模式, False: 语音模式
useolinetts: True # True: 在线 TTS, False: 本地 TTS
model_service:
ros__parameters:
language: 'zh'
regional_setting: "China"
# 阿里百炼配置
tongyi_api_key: "your-api-key"
tongyi_base_url: "https://dashscope.aliyuncs.com"
tongyi_app_id: "your-app-id"
multimodel: "qwen-vl-max"
# TTS 配置
tts_supplier: "aliyun" # 或 "baidu"
oline_tts_model: "cosyvoice-v1"
voice_tone: "zh_CN-female-shaohan"
# ASR 配置
oline_asr_model: "paraformer-realtime-v2"
oline_asr_sample_rate: 16000
local_asr_model: "iic/SenseVoiceSmall"
A:
name: '水果店'
position:
x: 1.633
y: 3.490
z: 0.0
orientation:
x: 0.0
y: 0.0
z: 0.618
w: 0.786
cd ~/M3Pro_ws
colcon build --packages-select largemodel
或编译整个工作空间:
colcon build
source install/setup.bash
ros2 launch largemodel largemodel_control.launch.py text_chat_mode:=True
ros2 launch largemodel largemodel_control.launch.py text_chat_mode:=False
# 启动 ASR 节点
ros2 run largemodel asr
# 启动模型服务节点
ros2 run largemodel model_service
# 启动动作服务节点
ros2 run largemodel action_service
ros2 launch largemodel largemodel_control.launch.py \
text_chat_mode:=True \
language:=zh \
regional_setting:=China
pip install rclpy std_msgs geometry_msgs sensor_msgs nav2_msgs
pip install pyaudio webrtcvad playsound pygame
pip install dashscope openai piper funasr
pip install pyserial cv-bridge pyyaml
interfaces (自定义 action 包)arm_msgs (机械臂消息)arm_interface (机械臂接口)M3Pro_demo (相机和运动学节点)用户语音 ──▶ ASR 节点 ──▶ Model Service ──▶ Action Service ──▶ 机器人执行
│ │ │
│ │ ▼
│ │ 动作反馈
│ │ │
▼ ▼ ▼
唤醒成功 双层AI规划 执行完成
提示音 任务分解 语音播报
/dev/mic 串口设备有正确的读写权限large_model_interface.yaml 中配置正确的大模型 API 密钥map_mapping.yaml 中的导航点坐标resources_file 目录下的音频文件存在# 检查串口设备
ls -l /dev/mic
# 添加串口权限
sudo usermod -a -G dialout $USER
# 检查 API 密钥配置
cat config/large_model_interface.yaml
# 检查网络连接
ping dashscope.aliyuncs.com
# 检查导航点配置
cat config/map_mapping.yaml
# 检查 action 服务是否正常
ros2 node list | grep action_service