This commit is contained in:
ywb
2026-05-29 20:21:46 +08:00
parent 9084c383cc
commit 8035cf29e2
3 changed files with 50 additions and 12 deletions
+40 -2
View File
@@ -857,13 +857,51 @@ createApp({
body: JSON.stringify({ joint: 'J' + (idx + 1), angle: val })
})
},
async applyAngles() {
async applyAngles(angles = null) {
const targetAngles = angles || this.angleInputs
await fetch(API + '/api/arm/set_angles', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ angles: this.angleInputs, speed: 500 })
body: JSON.stringify({ angles: targetAngles, speed: 500 })
})
},
},
async invertAngles() {
// 每个角度取反:10 → -10, -10 → 10
const inverted = this.angleInputs.map(a => -a)
// 🔍 角度范围检查(myCobot 630 限位)
const limits = [
[-180, 180], // J1
[-90, 90], // J2
[-90, 90], // J3
[-180, 180], // J4
[-90, 90], // J5
[-180, 180] // J6
]
const outOfRange = []
for (let i = 0; i < 6; i++) {
if (inverted[i] < limits[i][0] || inverted[i] > limits[i][1]) {
outOfRange.push('J' + (i+1) + '=' + inverted[i].toFixed(1) + '° (范围: ' + limits[i][0] + '~' + limits[i][1] + '°)')
}
}
if (outOfRange.length > 0) {
alert('⚠️ 角度超出范围:\n' + outOfRange.join('\n'))
return // 不执行反转
}
// 应用到机械臂
try {
await this.applyAngles(inverted)
this.angleInputs = inverted // 只有在成功后才更新显示
alert('✅ 角度已反转并应用')
} catch (e) {
alert('❌ 应用失败: ' + e.message)
}
// 等待2秒让机械臂到位,然后刷新显示
setTimeout(() => this.refreshAngles(), 2000)
},
jogStart(idx, dir) {
const joint = 'J' + (idx + 1)
fetch(API + '/api/arm/jog', {