diff --git a/agv_app/static/js/setting.js b/agv_app/static/js/setting.js index d8d8bf2..451610e 100644 --- a/agv_app/static/js/setting.js +++ b/agv_app/static/js/setting.js @@ -45,6 +45,11 @@ createApp({ agvMoveInterval: null, agvCameraUrl: API + '/api/camera/refresh', agvCameraTimer: null, + // 初始化定位 + initPoseLoading: false, + initPoseMsg: '', + initAmclPoseLoading: false, + initAmclPoseMsg: '', } }, mounted() { @@ -146,6 +151,8 @@ createApp({ const { resolution, origin } = this.mapMeta const wx = origin[0] + px * resolution * this.mapMeta.width const wy = origin[1] + (1 - py) * resolution * this.mapMeta.height + // 确认框 + if (!confirm(`确定导航到坐标 (${wx.toFixed(2)}, ${wy.toFixed(2)}) 吗?`)) return try { const res = await fetch(API + '/api/navigate/to', { method: 'POST', @@ -639,6 +646,44 @@ createApp({ alert('❌ 复位请求失败: ' + e.message) } }, + async initPose() { + if (!this.agvConnected) { alert('AGV 未连接'); return } + if (!confirm('确定要将 AMCL 初始位置设为 (0,0,0) 吗?这会重置定位。')) return + this.initPoseLoading = true + this.initPoseMsg = '' + try { + const res = await fetch(API + '/api/mission/init_pose', { method: 'POST' }) + const data = await res.json() + if (data.ok) { + this.initPoseMsg = '✅ ' + (data.message || '初始化成功') + } else { + this.initPoseMsg = '❌ ' + (data.error || '初始化失败') + } + } catch (e) { + this.initPoseMsg = '❌ 请求失败: ' + e.message + } + this.initPoseLoading = false + setTimeout(() => { this.initPoseMsg = '' }, 5000) + }, + async initAmclPose() { + if (!this.agvConnected) { alert('AGV 未连接'); return } + if (!confirm('确定要将 AMCL 初始位置设为 (0,0,0) 吗?这会重置定位。')) return + this.initAmclPoseLoading = true + this.initAmclPoseMsg = '' + try { + const res = await fetch(API + '/api/mission/init_pose', { method: 'POST' }) + const data = await res.json() + if (data.ok) { + this.initAmclPoseMsg = '✅ ' + (data.message || '初始化成功') + } else { + this.initAmclPoseMsg = '❌ ' + (data.error || '初始化失败') + } + } catch (e) { + this.initAmclPoseMsg = '❌ 请求失败: ' + e.message + } + this.initAmclPoseLoading = false + setTimeout(() => { this.initAmclPoseMsg = '' }, 5000) + }, getPointAt(pointRow, col) { var positions = this.missionConfig.positions || [] diff --git a/agv_app/templates/setting.html b/agv_app/templates/setting.html index e3d6f52..076386b 100644 --- a/agv_app/templates/setting.html +++ b/agv_app/templates/setting.html @@ -48,22 +48,33 @@
{% raw %}{{ mapMsg }}{% endraw %}