初始化位置

This commit is contained in:
ywb
2026-05-18 09:07:56 +08:00
parent 0dfd20b17b
commit a4c8171c42
2 changed files with 71 additions and 15 deletions
+45
View File
@@ -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 || []
+11
View File
@@ -48,8 +48,18 @@
<p v-if="mapMsg" class="hint">{% raw %}{{ mapMsg }}{% endraw %}</p>
</section>
<section class="card" v-if="mapLoaded" style="margin-top:16px">
<div style="display:flex;align-items:center;justify-content:space-between">
<h2>地图可视化</h2>
<div style="display:flex;gap:8px;align-items:center">
<span style="font-size:12px;color:#888">旋转:</span>
<button class="btn btn-secondary" style="padding:4px 10px;font-size:12px" @click="rotateMap(-90)">↶ 90°</button>
<button class="btn btn-secondary" style="padding:4px 10px;font-size:12px" @click="rotateMap(90)">↷ 90°</button>
<button class="btn btn-secondary" style="padding:4px 10px;font-size:12px" @click="resetMapView">重置</button>
</div>
</div>
<div class="map-container" style="position:relative;background:#111;border-radius:8px;overflow:hidden">
<!-- 地图旋转 wrapper -->
<div :style="{ transform: 'rotate(' + mapRotation + 'deg)', transition: 'transform 0.3s ease' }">
<img :src="mapImageUrl" @error="onMapError" @click="onMapClick" style="width:100%;display:block;cursor:crosshair" title="点击地图导航到该位置">
<!-- 地图覆盖层:显示点位坐标 -->
<div class="map-overlay">
@@ -67,6 +77,7 @@
</div>
</div>
</div>
</div>
</section>
</div>