67 lines
6.0 KiB
HTML
67 lines
6.0 KiB
HTML
|
|
<!doctype html>
|
|||
|
|
<html lang="zh-CN"><meta charset="UTF-8"><title>机械臂示教与轨迹隔离检查</title>
|
|||
|
|
<style>body{font:14px Arial;margin:24px;background:#f5f7fa}main{max-width:1100px;margin:auto;background:white;padding:24px}#result{white-space:pre-wrap;max-height:200px;overflow:auto}nav{margin-bottom:16px}nav a,nav button{margin-right:12px}</style>
|
|||
|
|
<main><h2>机械臂示教与轨迹检查</h2><p>所有设备请求在内存模拟,不访问设备,不创建业务数据。</p><nav><a href="?mode=panel">示教面板</a><a href="?mode=params&action=ARM_START_TRAJECTORY_RECORDING">录制组件配置</a><a href="?mode=params&action=ARM_REPLAY_RECORDED_TRAJECTORY">回放组件配置</a><button id="finish">完成模拟回放</button><button id="fail">模拟下一次操作失败</button></nav><div id="app"></div><pre id="result" role="status"></pre></main>
|
|||
|
|
<script type="module">
|
|||
|
|
import {createApp,h} from 'vue'
|
|||
|
|
import ElementPlus from 'element-plus'
|
|||
|
|
import 'element-plus/dist/index.css'
|
|||
|
|
import Panel from '/src/cmvr/common/views/device/register/components/MechanicalArm/ArmTeachingPanel.vue'
|
|||
|
|
import Params from '/src/cmvr/common/views/flow/components/params/ArmTeachingParams.vue'
|
|||
|
|
import {createArmTeachingGroup} from '/src/cmvr/common/utils/armTeaching.mjs'
|
|||
|
|
import request from '/src/cmvr/request.ts'
|
|||
|
|
import {service} from '/src/config/axios/service.ts'
|
|||
|
|
const log=[]
|
|||
|
|
const write=()=>document.querySelector('#result').textContent=JSON.stringify(log,null,2)
|
|||
|
|
let recording=false,recordingFile='',mode='ARM_CONTROL_MODE_POSITION',moving=false,fail=false,pending
|
|||
|
|
let files=[]
|
|||
|
|
const response=(config,data,code=200)=>({data:{code,data,msg:code===200?'success':'模拟SDK:当前仍在录制,拒绝回放'},status:200,statusText:'OK',headers:{},config})
|
|||
|
|
request.defaults.adapter=async config=>{
|
|||
|
|
const path=config.url||'',method=(config.method||'get').toLowerCase(),body=typeof config.data==='string'?JSON.parse(config.data):config.data
|
|||
|
|
if(path==='/api/arm/teaching/validate')return response(config,true)
|
|||
|
|
if(path==='/api/arm/torqueOn'&&config.params?.robotId==='E2E-ARM-QA'){log.push({operation:'torqueOn'});write();return response(config,{success:true})}
|
|||
|
|
const op=path.split('/').at(-1),p=method==='get'?config.params:body
|
|||
|
|
if(!path.startsWith('/api/arm/teaching/')||p?.robotId!=='E2E-ARM-QA')throw Error('此隔离页不允许真实设备请求')
|
|||
|
|
if(op==='getArmInfo')return response(config,{deviceId:'fixture-arm',model:'模拟六轴机械臂',dof:6})
|
|||
|
|
if(op==='getRobotState')return response(config,{state:{connected:true,poweredOn:true,brakeReleased:true,moving,programRunning:false,robotMode:'ARM_ROBOT_MODE_IDLE',timestamp:Date.now()/1000,controlMode:mode,safetyMode:'ARM_SAFETY_MODE_NORMAL',actualJointState:{position:[0,0,0,0,0,0]}}})
|
|||
|
|
if(op==='listRecordedTrajectories')return response(config,{recording,recordingFile,recordedSamples:'9007199254740993',recordingError:'',trajectories:files})
|
|||
|
|
const allowed=['enterTeachingMode','startTrajectoryRecording','stopTrajectoryRecording','exitTeachingMode','completeTeaching','moveToTrajectoryStart','replayRecordedTrajectory','stopMotion']
|
|||
|
|
if(!allowed.includes(op)||method!=='post')throw Error('禁止未声明的模拟操作')
|
|||
|
|
log.push({operation:op,fileName:p.fileName,timeoutMs:p.timeoutMs});write()
|
|||
|
|
if(fail){fail=false;return response(config,null,500)}
|
|||
|
|
if(op==='enterTeachingMode')mode='ARM_CONTROL_MODE_FREEDRIVE'
|
|||
|
|
if(op==='startTrajectoryRecording'){recording=true;recordingFile=p.fileName.endsWith('.csv')?p.fileName:p.fileName+'.csv'}
|
|||
|
|
if(op==='stopTrajectoryRecording'||op==='completeTeaching'){
|
|||
|
|
if(recording)files=[...files,{fileName:recordingFile,samples:'9007199254740993',durationS:3,samplingFrequencyHz:100}]
|
|||
|
|
recording=false
|
|||
|
|
}
|
|||
|
|
if(op==='exitTeachingMode'||op==='completeTeaching')mode='ARM_CONTROL_MODE_POSITION'
|
|||
|
|
if(op==='replayRecordedTrajectory'){
|
|||
|
|
moving=true
|
|||
|
|
return await new Promise(resolve=>pending=cancelled=>{moving=false;resolve(response(config,cancelled?null:{success:true},cancelled?500:200));pending=null})
|
|||
|
|
}
|
|||
|
|
if(op==='stopMotion'){moving=false;if(pending)pending(true)}
|
|||
|
|
return response(config,{success:true})
|
|||
|
|
}
|
|||
|
|
service.defaults.adapter=async config=>{
|
|||
|
|
if(config.url?.endsWith('/resource-occupations'))return {data:{code:0,data:[{resource_type:'ROBOT',resource_id:'E2E-ARM-QA',owner_key:'MANUAL:E2E-ARM-QA'}]},status:200,statusText:'OK',headers:{},config}
|
|||
|
|
if(config.url?.endsWith('/clear-occupation'))return {data:{code:0,data:true},status:200,statusText:'OK',headers:{},config}
|
|||
|
|
throw Error('禁止真实业务请求')
|
|||
|
|
}
|
|||
|
|
document.querySelector('#finish').onclick=()=>pending?.(false)
|
|||
|
|
document.querySelector('#fail').onclick=()=>{fail=true}
|
|||
|
|
const query=new URLSearchParams(location.search)
|
|||
|
|
let root
|
|||
|
|
if(query.get('mode')==='params'){
|
|||
|
|
const action=query.get('action')||'ARM_START_TRAJECTORY_RECORDING'
|
|||
|
|
const node={id:'E2E-arm-node',type:'serviceNode',properties:{...structuredClone(createArmTeachingGroup().nodeList.find(n=>n.action===action)),executionTarget:{roleKey:'arm',deviceSlotKey:'arm'}}}
|
|||
|
|
const parameter=node.properties.nodeParams.find(p=>p.name==='fileName');if(parameter)parameter.input='fixture.csv'
|
|||
|
|
const start={id:'E2E-start',type:'start',properties:{name:'开始',resourceRoles:[{roleKey:'arm',displayName:'机械臂工位',deviceSlots:[{slotKey:'arm',deviceKind:2,displayName:'机械臂'}]}]}}
|
|||
|
|
const record={id:'E2E-record',type:'serviceNode',properties:structuredClone(createArmTeachingGroup().nodeList.find(n=>n.action==='ARM_START_TRAJECTORY_RECORDING'))}
|
|||
|
|
const graph=action==='ARM_REPLAY_RECORDED_TRAJECTORY'?{nodes:[start,record,node],edges:[{sourceNodeId:start.id,targetNodeId:record.id},{sourceNodeId:record.id,targetNodeId:node.id}]}:{nodes:[start,node],edges:[{sourceNodeId:start.id,targetNodeId:node.id}]}
|
|||
|
|
window.lf={getGraphData:()=>graph,setProperties:(id,value)=>{log.push({savedNode:id,name:value.name,nodeParams:value.nodeParams});write()}}
|
|||
|
|
root={render:()=>h(Params,{data:node})}
|
|||
|
|
}else root={render:()=>h(Panel,{robotId:'E2E-ARM-QA',deviceId:'fixture-arm'})}
|
|||
|
|
createApp(root).use(ElementPlus).directive('hasPermi',{mounted(){}}).mount('#app')
|
|||
|
|
</script></html>
|