Nav2导航 + 初始化位置功能

- nav2_navigator.py: 通过 ros2 action 与 Nav2 通信,修复 YAML 格式(pose 嵌套)
- mission_executor.py: 改用 Nav2 navigate_to_pose action 导航
- app.py: navigate/to 等 API 改用 Nav2Navigator;新增 /api/mission/init_pose
  API,通过子进程调用 rclpy 发布 /initialpose 到 (0,0,0)
- setting.html/js: 任务配置Tab加「初始化位置」按钮

注意:ROS2 daemon (domain=1) 与 Flask 在不同 domain,
Flask 进程内调用 rclpy 会破坏 daemon 状态,需通过子进程调用
This commit is contained in:
ywb
2026-05-16 14:22:10 +08:00
parent f2130acfaa
commit a9840c38ef
5 changed files with 91 additions and 41 deletions
+17
View File
@@ -50,6 +50,7 @@ const app = createApp({
agvMoveInterval: null,
agvCameraUrl: API + '/api/camera/refresh',
agvCameraTimer: null,
initPoseLoading: false,
}
},
mounted() {
@@ -336,6 +337,22 @@ const app = createApp({
}
} catch (e) { alert('保存失败: ' + e.message) }
},
async initPose() {
try {
this.initPoseLoading = true
const res = await fetch(API + '/api/mission/init_pose', { method: 'POST' })
const data = await res.json()
if (data.ok) {
alert('✅ 初始位置已设为 (0, 0, 0)')
} else {
alert('❌ 初始化失败: ' + (data.error || '未知错误'))
}
} catch (e) {
alert('❌ 初始化位置请求失败: ' + e.message)
} finally {
this.initPoseLoading = false
}
},
async loadAllMachines() {
try {
const res = await fetch(API + '/api/mission/machines')