am-freescan/scripts/prepare_coordinate_management_ui.py
lixiaolong ba0f749d40 feat: 完善检测任务、夹具轨迹与设备工作流
完善扫描成果与比对资料管理,精简业务菜单和任务工作台,更新批量导入模板。

适配机械臂新协议、坐标系管理及目标位姿组件,增加扫描参数字典和角色自动分配。

修复试运行终止状态与过期扫描任务资源释放,补充回归测试、迁移脚本及接口文档。
2026-11-06 10:50:49 +08:00

43 lines
5.0 KiB
Python

"""Actual coordinate management page with memory-only arm records. Never connects to hardware."""
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
PAGE=r'''<!doctype html><html lang="zh"><meta charset="utf-8"><title>坐标系建立离线验证</title><body><div id="app"></div><script type="module">
import {createApp,h,ref} from '/node_modules/.vite/deps/vue.js';
import {createRouter,createMemoryHistory,RouterView} from '/coordinate-management-router-verification.mjs';
import ElementPlus from '/node_modules/.vite/deps/element-plus.js';
import '/node_modules/element-plus/dist/index.css';
import '/node_modules/element-plus/theme-chalk/dark/css-vars.css';
import zhCn from '/node_modules/element-plus/es/locale/lang/zh-cn.mjs';
import Page from '/src/views/lab/md/coordinate-system/index.vue';
import {emptyCoordinate,validateCoordinate} from '/src/cmvr/common/utils/armUserCoordinates.mjs';
const calls=ref([]),records=new Map(),points=[[0,0,0],[.1,0,0],[0,.1,0]];let sample=0,revision=9007199254740993n;
const clone=v=>JSON.parse(JSON.stringify(v));
const seed=(name)=>({...emptyCoordinate(),name,revision:'4',tcpOffset:[0,0,0,0,0,0],userPose:[0,0,0,0,0,0],calibrationPoints:points.map(([x,y,z])=>({baseTcpPose:{x,y,z,rx:0,ry:0,rz:0}}))});
records.set('offline-a',[seed('夹具A坐标系')]);records.set('offline-b',[seed('夹具B坐标系')]);
const api=async(op,p)=>{calls.value.push(JSON.stringify({op,robotId:p.robotId,deviceId:p.deviceId,name:p.name||p.coordinate?.name}));
const rows=records.get(p.robotId);if(!rows)throw Error('未选择内存机械臂');
if(op==='getRobotState')return {data:{state:{connected:true,robotMode:'ARM_ROBOT_MODE_IDLE',poweredOn:true,brakeReleased:true,moving:false,programRunning:false}}};
if(op==='getActiveTcpOffset')return {data:{success:true,units:'m_rad',offset:[0,0,0,0,0,0]}};
if(op==='listUserCoordinateSystems')return {data:{coordinates:clone(rows),applicationKnown:false}};
if(op==='calibrateUserCoordinateSystem'){validateCoordinate('CALIBRATE_USER_COORDINATE_SYSTEM',p);return {data:{coordinate:{...clone(p.coordinate),userPose:[0,0,0,0,0,0]}}}};
if(op==='createUserCoordinateSystem'){validateCoordinate('CREATE_USER_COORDINATE_SYSTEM',p);if(rows.some(x=>x.name===p.coordinate.name))throw Error('坐标系名称已存在');const c={...clone(p.coordinate),revision:String(revision++),userPose:[0,0,0,0,0,0]};rows.push(c);return {data:{coordinate:clone(c)}}};
if(!['getUserCoordinateSystem','updateUserCoordinateSystem','deleteUserCoordinateSystem'].includes(op))throw Error('离线验证禁止控制操作:'+op);
const current=rows.find(x=>x.name===(p.name||p.coordinate?.name));if(!current)throw Error('坐标系不存在');if(current.revision!==p.expectedRevision)throw Error('坐标系版本冲突');
if(op==='getUserCoordinateSystem')return {data:{coordinate:clone(current)}};
if(op==='updateUserCoordinateSystem'){validateCoordinate('UPDATE_USER_COORDINATE_SYSTEM',p);Object.assign(current,clone(p.coordinate),{revision:String(revision++)});return {data:{coordinate:clone(current)}}};
rows.splice(rows.indexOf(current),1);return {data:{}};
};
const router=createRouter({history:createMemoryHistory(),routes:[{path:'/lab/master/coordinate-system',component:Page}]});
const app=createApp({setup(){return()=>h('main',{style:'max-width:1120px;margin:20px auto;padding:20px;background:var(--el-bg-color);color:var(--el-text-color-primary)'},[h('h2','配置中心 · 离线界面验证(不连接现场)'),h('button',{onClick:()=>document.documentElement.classList.toggle('dark')},'切换明暗主题'),h(RouterView),h('details',[h('summary','内存调用记录'),h('pre',{'data-testid':'calls'},calls.value.join('\n'))])])}});
app.component('ContentWrap',{setup(_,ctx){return()=>h('section',{style:'padding:20px;border:1px solid var(--el-border-color);border-radius:8px;margin-top:14px'},ctx.slots.default?.())}});app.directive('hasPermi',{});
app.provide('armCoordinateRobotReader',async()=>({rows:[{robotId:'offline-a',robotName:'离线机器人A'},{robotId:'offline-b',robotName:'离线机器人B'},{robotId:'offline-empty',robotName:'无机械臂机器人'}]}));
app.provide('armCoordinateDeviceReader',async id=>({data:id==='offline-empty'?[]:[{deviceId:'offline-arm',deviceName:'离线机械臂',deviceKind:2}]}));
app.provide('armCoordinateApi',api);app.provide('armCoordinatePoseReader',async p=>{calls.value.push(JSON.stringify({op:'getPose',...p}));const [x,y,z]=points[sample++%3];return {data:{x,y,z,rx:0,ry:0,rz:0,referenceFrame:'base',endFrame:'tcp'}}});
app.use(ElementPlus,{locale:zhCn});app.use(router);await router.push({path:'/lab/master/coordinate-system',query:{robotId:'offline-a',deviceId:'offline-arm'}});await router.isReady();app.mount('#app');
</script></body></html>'''
if __name__=='__main__':
(ROOT/'am-web/coordinate-management-router-verification.mjs').write_text("export {createRouter,createMemoryHistory,RouterView} from 'vue-router'",encoding='utf-8')
path=ROOT/'am-web/coordinate-management-verification.html'
path.write_text(PAGE,encoding='utf-8')
print(path)