From e14ee07a84ac26106c728b3697a2049c9fbdf722 Mon Sep 17 00:00:00 2001 From: ywb <347742090@qq.com> Date: Thu, 14 May 2026 22:53:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=BA=E5=9E=8B=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agv_app/data/machines_config.json | 252 +++++++++++++++++++++++++----- agv_app/data/mission_config.json | 4 +- agv_app/static/js/setting.js | 97 ++++++++++++ agv_app/templates/setting.html | 35 +++-- 4 files changed, 334 insertions(+), 54 deletions(-) diff --git a/agv_app/data/machines_config.json b/agv_app/data/machines_config.json index bb03c17..39e6ce9 100644 --- a/agv_app/data/machines_config.json +++ b/agv_app/data/machines_config.json @@ -209,48 +209,6 @@ "poses": [] } }, - { - "id": "m_3_4", - "row": 3, - "col": 4, - "front": { - "coords": [ - 0, - 0, - 0 - ], - "poses": [] - }, - "back": { - "coords": [ - 0, - 0, - 0 - ], - "poses": [] - } - }, - { - "id": "m_3_3", - "row": 3, - "col": 3, - "front": { - "coords": [ - 0, - 0, - 0 - ], - "poses": [] - }, - "back": { - "coords": [ - 0, - 0, - 0 - ], - "poses": [] - } - }, { "id": "m_0_1", "row": 0, @@ -334,5 +292,215 @@ ], "poses": [] } + }, + { + "id": "m_0_3", + "row": 0, + "col": 3, + "front": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + }, + "back": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + } + }, + { + "id": "m_0_4", + "row": 0, + "col": 4, + "front": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + }, + "back": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + } + }, + { + "id": "m_0_5", + "row": 0, + "col": 5, + "front": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + }, + "back": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + } + }, + { + "id": "m_1_3", + "row": 1, + "col": 3, + "front": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + }, + "back": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + } + }, + { + "id": "m_1_5", + "row": 1, + "col": 5, + "front": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + }, + "back": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + } + }, + { + "id": "m_1_4", + "row": 1, + "col": 4, + "front": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + }, + "back": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + } + }, + { + "id": "m_2_3", + "row": 2, + "col": 3, + "front": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + }, + "back": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + } + }, + { + "id": "m_2_1", + "row": 2, + "col": 1, + "front": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + }, + "back": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + } + }, + { + "id": "m_2_4", + "row": 2, + "col": 4, + "front": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + }, + "back": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + } + }, + { + "id": "m_2_5", + "row": 2, + "col": 5, + "front": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + }, + "back": { + "coords": [ + 0, + 0, + 0 + ], + "poses": [] + } } ] \ No newline at end of file diff --git a/agv_app/data/mission_config.json b/agv_app/data/mission_config.json index 1e1f374..fe42feb 100644 --- a/agv_app/data/mission_config.json +++ b/agv_app/data/mission_config.json @@ -1,6 +1,6 @@ { - "rows": 2, - "cols": 2, + "rows": 4, + "cols": 6, "grid": [], "positions": [ { diff --git a/agv_app/static/js/setting.js b/agv_app/static/js/setting.js index d401e53..8ff514b 100644 --- a/agv_app/static/js/setting.js +++ b/agv_app/static/js/setting.js @@ -29,6 +29,7 @@ const app = createApp({ models: [], selectedModelId: null, newModelName: '', + newModelId: null, newModelDesc: '', newModelNotes: '', newPoseForm: {}, // 机型配置:新建姿态的表单 @@ -211,6 +212,7 @@ const app = createApp({ headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: this.newModelName || '型号_' + (this.models.length + 1), + id: this.newModelId, description: this.newModelDesc || '', notes: this.newModelNotes || '', serial_prefix: this.newModelSerial || '' @@ -831,6 +833,101 @@ const app = createApp({ onPreviewError(e) { e.target.style.display = 'none' }, + // === 姿态角度控制(机型配置 Tab) === + async refreshPoseAngles(modelId, poseId) { + // 获取当前机械臂角度,填入姿态,保存到后端 + if (!this.armConnected) { + alert('机械臂未连接') + return + } + try { + var res = await fetch(API + '/api/arm/get_angles') + var data = await res.json() + if (data.ok && data.angles) { + // Find the pose and update + var model = this.models.find(m => m.id === modelId) + if (model) { + var pose = model.poses.find(p => p.id === poseId) + if (pose) { + pose.arm_angles = [...data.angles] + // Save to backend + await fetch(API + '/api/models/' + modelId + '/poses/' + poseId, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ arm_angles: pose.arm_angles }) + }) + } + } + } + } catch (e) { + console.error('refreshPoseAngles error:', e) + } + }, + async applyPoseAngles(modelId, poseId) { + // 调整机械臂到姿态的角度 + var model = this.models.find(m => m.id === modelId) + if (model) { + var pose = model.poses.find(p => p.id === poseId) + if (pose && pose.arm_angles) { + try { + await fetch(API + '/api/arm/set_angles', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ angles: pose.arm_angles, speed: 500 }) + }) + } catch (e) { + console.error('applyPoseAngles error:', e) + } + } + } + }, + async adjustPoseAngle(modelId, poseId, jointIndex, delta) { + // 微调姿态角度,并实时调整机械臂 + var model = this.models.find(m => m.id === modelId) + if (model) { + var pose = model.poses.find(p => p.id === poseId) + if (pose) { + if (!pose.arm_angles) pose.arm_angles = [0, 0, 0, 0, 0, 0] + pose.arm_angles[jointIndex] = (pose.arm_angles[jointIndex] || 0) + delta + // Save to backend + await fetch(API + '/api/models/' + modelId + '/poses/' + poseId, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ arm_angles: pose.arm_angles }) + }) + // Move arm + await fetch(API + '/api/arm/set_angle', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ joint: 'J' + (jointIndex + 1), angle: pose.arm_angles[jointIndex] }) + }) + } + } + }, + async updatePoseAngleAndMove(modelId, poseId, jointIndex, value) { + // 更新姿态角度(输入框),并实时调整机械臂 + var model = this.models.find(m => m.id === modelId) + if (model) { + var pose = model.poses.find(p => p.id === poseId) + if (pose) { + if (!pose.arm_angles) pose.arm_angles = [0, 0, 0, 0, 0, 0] + pose.arm_angles[jointIndex] = parseFloat(value) || 0 + // Save to backend + await fetch(API + '/api/models/' + modelId + '/poses/' + poseId, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ arm_angles: pose.arm_angles }) + }) + // Move arm + await fetch(API + '/api/arm/set_angle', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ joint: 'J' + (jointIndex + 1), angle: pose.arm_angles[jointIndex] }) + }) + } + } + }, + // === AGV 控制 === async refreshAgvPosition() { if (!this.agvConnected) return diff --git a/agv_app/templates/setting.html b/agv_app/templates/setting.html index d6dfded..0dc61d5 100644 --- a/agv_app/templates/setting.html +++ b/agv_app/templates/setting.html @@ -4,7 +4,7 @@