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 }) body: JSON.stringify({ angles: targetAngles, speed: 500 })
}) })
}, },
async invertAngles() { async mirrorAngles() {
// 每个角度取反:10 → -10, -10 → 10 // 镜像角度:只取反 J1,其它不变
const inverted = this.angleInputs.map(a => -a) const mirrored = [...this.angleInputs]
mirrored[0] = -mirrored[0] // 只取反 J1
// 🔍 角度范围检查(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 { try {
await this.applyAngles(inverted) await this.applyAngles(mirrored)
this.angleInputs = inverted // 只有在成功后才更新显示 this.angleInputs = mirrored // 只有在成功后才更新显示
alert('✅ 角度已反转并应用') alert('✅ 角度已镜像并应用(仅 J1 取反)')
} catch (e) { } catch (e) {
alert('❌ 应用失败: ' + e.message) alert('❌ 应用失败: ' + e.message)
} }
+2 -2
View File
@@ -510,7 +510,7 @@
<div class="btn-row"> <div class="btn-row">
<button class="btn btn-primary" @click="refreshAngles">🔄 刷新角度</button> <button class="btn btn-primary" @click="refreshAngles">🔄 刷新角度</button>
<button class="btn btn-secondary" @click="applyAngles">✅ 应用角度</button> <button class="btn btn-secondary" @click="applyAngles">✅ 应用角度</button>
<button class="btn btn-warning" @click="invertAngles">🔄 反转角度</button> <button class="btn btn-warning" @click="mirrorAngles">🔄 镜像角度</button>
</div> </div>
</div> </div>
</div> </div>
@@ -585,6 +585,6 @@
</div> </div>
<script src="/static/js/vue3.global.prod.js?v=20260526a"></script> <script src="/static/js/vue3.global.prod.js?v=20260526a"></script>
<script src="/static/js/setting.js?v=20260529a"></script> <script src="/static/js/setting.js?v=20260529b"></script>
</body> </body>
</html> </html>