航路点MCP服务器
MCP(模型上下文协议)服务器,为SO100机器人提供航路点管理和回放功能。该服务器将现有的航路点记录和回放脚本封装到标准化的MCP接口中。
特性
服务器提供三个主要工具:
🔍 read_waypoint
从SO100机器人读取当前关节位置作为航路点。
- 参数:
- name (可选):航路点的自定义名称 - port (可选):用于机器人连接的串行端口(默认: /dev/ttyACM1)
- 退货: 包含航路点数据的JSON字符串,包括时间戳、关节和元数据
▶️ play_waypoint
使用平滑插值在SO100机器人上执行航路点序列。
- 参数:
- waypoint_data:可以是: - 字符串:包含航点的JSON文件的路径 - 骰子:带“关节”键的单个航路点 - 列表:多个航路点或联合位置阵列 - port (可选):用于机器人连接的串行端口(默认: /dev/ttyACM1)
- 退货: 指示成功或失败的状态消息
📏 get_joint_limits
获取SO100机器人的关节角度限制。
- 参数:
- port (可选):用于机器人连接的串行端口(默认: /dev/ttyACM1)
- 退货: JSON字符串,包含每个关节的最小值/最大值
安装
- 安装依赖项:
uv sync --dev- 确保SO100机器人已连接 通过USB串行端口(通常
/dev/ttyACM1)
- 复制
so100_client.py从父目录中确保机器人通信正常工作
用法
启动服务器
HTTP传输(建议用于开发)
python main.py --transport streamable-http --port 8080STDIO传输(适用于MCP客户端)
python main.py --transport stdio自定义配置
python main.py --transport streamable-http --host 0.0.0.0 --port 9000 --robot-port /dev/ttyACM0工具使用示例
读取当前位置
# Via MCP client
result = call_tool("read_waypoint", {"name": "home_position"})从文件中播放路线点
# Play waypoints from JSON file
result = call_tool("play_waypoint", {"waypoint_data": "my_waypoints.json"})玩单路点游戏
# Move to specific joint angles
waypoint = {"joints": [0, 90, -45, 0, 0, 0]}
result = call_tool("play_waypoint", {"waypoint_data": waypoint})玩多个路线点
# Execute sequence of positions
waypoints = [
[0, 0, 0, 0, 0, 0], # Start position
[90, 0, 0, 0, 0, 0], # Move joint 1
[90, 45, 0, 0, 0, 0] # Move joint 2
]
result = call_tool("play_waypoint", {"waypoint_data": waypoints})获得关节限制
# Get robot joint limits
limits = call_tool("get_joint_limits")发展
项目结构
waypoint-mcp/
├── src/waypoint_mcp/
│ ├── __init__.py
│ ├── waypoint_controller.py # Domain logic
│ └── server.py # MCP server implementation
├── tests/
│ ├── __init__.py
│ └── test_waypoint_mcp.py # Basic tests
├── main.py # Entry point
├── pyproject.toml # Dependencies
└── README.md运行测试
uv run pytest代码格式化
uv run black src/ tests/
uv run isort src/ tests/依赖项
- 核心:
- mcp[cli]>=1.1.2 -MCP协议实现 - pyserial>=3.5 -机器人串行通信 - typing-extensions>=4.5.0 -键入提示
- 发展:
- pytest>=7.0.0 -测试框架 - pytest-asyncio>=0.21.0 -异步测试支持 - black>=23.0.0 -代码格式 - isort>=5.12.0 -导入排序
与现有脚本集成
此MCP服务器封装了以下功能:
distiller-record-wps.py-航点记录功能distiller-play-wps.py-航点回放功能
服务器提供更干净的API,同时保持与现有航路点文件格式的兼容性。
安全注意事项
⚠️ 重要安全警告:
- 机器人运动: 这
play_waypoint工具将使机器人移动。确保工作区干净。 - 紧急停止: 保持机器人的紧急停止按钮可用。
- 接头限制: 服务器提供联合限制,但始终验证安全位置。
- 串行连接: 确保正确的串行连接,以避免通信错误。
故障排除
常见问题
- “SO100客户端不可用”
- 确保 so100_client.py 可以在父目录中访问 - 检查Python路径配置
- “无法连接到SO100”
- 验证机器人是否已通电并通过USB连接 - 检查串行端口权限: sudo chmod 666 /dev/ttyACM1 - 尝试不同的串行端口: /dev/ttyACM0, /dev/ttyUSB0
- “8000-9000范围内没有可用端口”
- 使用 --port 用于指定自定义端口的参数 - 检查是否存在冲突的服务
- 航点文件错误
- 确保JSON文件遵循预期的格式,并带有“航点”数组 - 每个航路点应有一个“关节”字段,其中有6个关节角度
许可证
该项目是LeRobotDistiller示例的一部分,并遵循相同的许可条款。
