This commit is contained in:
ywb
2026-05-29 20:57:50 +08:00
parent 498613ba75
commit 6f3a36bc60
2 changed files with 9 additions and 28 deletions
+7 -26
View File
@@ -865,35 +865,16 @@ createApp({
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 // 不执行反转
}
async mirrorAngles() {
// 镜像角度:只取反 J1,其它不变
const mirrored = [...this.angleInputs]
mirrored[0] = -mirrored[0] // 只取反 J1
// 应用到机械臂
try {
await this.applyAngles(inverted)
this.angleInputs = inverted // 只有在成功后才更新显示
alert('✅ 角度已反转并应用')
await this.applyAngles(mirrored)
this.angleInputs = mirrored // 只有在成功后才更新显示
alert('✅ 角度已镜像并应用(仅 J1 取反)')
} catch (e) {
alert('❌ 应用失败: ' + e.message)
}