机型配置
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user