pages-index-roboticArm.CZXZ3FEr.js 16 KB

1
  1. import{v as e,_ as t,s,h as i,a as l,w as n,i as o,o as a,d as r,j as u,t as m,b as c,u as h,I as d,p as f,m as p,S as g}from"./index-BBz1t8A8.js";const b="10001",S="10002",_="10020",A="10021",T="10022",C="10023",k="1002F",x="10031",N="10032",M="10033",w="1003F";class y{constructor(e="ws://192.168.0.3:3001/jointadjustment"){this.url=e,this.socketTask=null,this.isConnected=!1,this.isRunning=!0,this.maxRetry=10,this.retryDelayList=[1e3,3e3,5e3,1e4],this.currentRetry=0,this.heartbeatInterval=3e4,this.heartbeatTimeout=3,this.heartbeatMissCount=0,this.heartbeatTimer=null,this.onMessageCallback=null}buildRequest(e,t={}){return JSON.stringify({cmd:e,data:t,timestamp:Date.now()})}sendCmd(e,t={}){if(this.isConnected&&this.socketTask)try{const s=this.buildRequest(e,t);console.log(s),this.socketTask.send({data:s})}catch(s){console.log("[发送异常]",s)}else console.log("[发送失败] 未连接")}startHeartbeat(){this.stopHeartbeat(),this.heartbeatMissCount=0,this.heartbeatTimer=setInterval((()=>{this.heartbeatMissCount++,console.log("[心跳] 发送,丢失计数:",this.heartbeatMissCount),this.sendCmd(b),this.heartbeatMissCount>=this.heartbeatTimeout&&(console.log("[心跳] 超时,重连"),this.closeSocket(),this.reconnect())}),this.heartbeatInterval)}stopHeartbeat(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}connect(){this.isRunning&&(this.socketTask&&this.closeSocket(),console.log("[连接] 连接中...",this.url),this.socketTask=e({url:this.url,success:()=>{},fail:e=>{console.log("[连接失败]",e),this.reconnect()}}),this.socketTask.onOpen((()=>{console.log("[连接成功]"),this.isConnected=!0,this.currentRetry=0,this.startHeartbeat()})),this.socketTask.onMessage((e=>{try{const t=JSON.parse(e.data);this.handleMessage(t)}catch(t){console.log("消息解析失败")}})),this.socketTask.onClose((()=>{console.log("[连接关闭]"),this.isConnected=!1,this.stopHeartbeat(),this.reconnect()})),this.socketTask.onError((e=>{console.log("[错误]",e),this.isConnected=!1,this.reconnect()})))}handleMessage(e){if(e.cmd===S)return this.heartbeatMissCount=0,void console.log("[心跳回执] 正常");console.log(e),this.onMessageCallback&&this.onMessageCallback(e)}reconnect(){if(!this.isRunning||this.isConnected)return;if(this.currentRetry>=this.maxRetry)return void console.log("已达最大重连次数");this.currentRetry++;const e=Math.min(this.currentRetry-1,this.retryDelayList.length-1),t=this.retryDelayList[e];console.log(`[${this.currentRetry}/${this.maxRetry}] ${t}ms 后重连`),setTimeout((()=>{this.connect()}),t)}closeSocket(){if(this.isRunning=!1,this.isConnected=!1,this.stopHeartbeat(),this.socketTask){try{this.socketTask.close()}catch{}this.socketTask=null}}}const V=t({data:()=>({IP:"127.0.0.1",shaftNumberSet:0,showParamPopup:!1,actionShaftNumber:[],isSetMultiAngle:!1,shaftNumber:0,axis1Angle:0,axis2Angle:0,axis3Angle:0,faultCode:"0x00000000",faultAxis:0,motor1:{angle:"0",speed:"0",current:"0.0",temp:"0.0",status:"0x0000",lower:0,upper:0,runningSpeed:"0",accelerationTime:"0",stopTime:"0"},motor2:{angle:"0",speed:"0",current:"0.0",temp:"0.0",status:"0x0000",lower:0,upper:0,runningSpeed:"0",accelerationTime:"0",stopTime:"0"},motor3:{angle:"0",speed:"0",current:"0.0",temp:"0.0",status:"0x0000",lower:0,upper:0,runningSpeed:"0",accelerationTime:"0",stopTime:"0"},runningSpeed:"",accelerationTime:"",stopTime:"",client:null}),onLoad(){this.IP=localStorage.getItem("ip"),this.connectWebSocket()},onUnload(){var e;null==(e=this.client)||e.closeSocket()},methods:{setSetting(e){this.shaftNumberSet=e,1==e?(this.runningSpeed=this.motor1.runningSpeed,this.accelerationTime=this.motor1.accelerationTime,this.stopTime=this.motor1.stopTime):2==e?(this.runningSpeed=this.motor2.runningSpeed,this.accelerationTime=this.motor2.accelerationTime,this.stopTime=this.motor2.stopTime):3==e&&(this.runningSpeed=this.motor3.runningSpeed,this.accelerationTime=this.motor3.accelerationTime,this.stopTime=this.motor3.stopTime),this.showParamPopup=!0},connectWebSocket(){this.client=new y("ws://"+this.IP+"3001/jointadjustment"),this.client.onMessageCallback=e=>{this.handleServerMessage(e)},this.client.connect(),setTimeout((()=>{this.getMotorAllInfo()}),500),setTimeout((()=>{this.getMotorSingleInfo(1),this.getMotorSingleInfo(2),this.getMotorSingleInfo(3)}),600)},handleServerMessage(e){const t=e.cmd,l=e.data||{};if(s({title:e.msg,icon:"none"}),t===w)return this.faultCode=l.FaultCode||"0x00000000",this.faultAxis=l.FaultShaftNumber||0,void i({title:"设备故障",content:`轴${this.faultAxis} ${this.faultCode}`,showCancel:!1});if(t===_)1==l.data&&this.isSetMultiAngle&&this.sendMultiAngle();else{if(t===x){const e={angle:l.CPositionAngleV||"0",speed:l.CurrentSpeed||"0",current:l.CurrentAPresent||"0.0",temp:l.TempAPresent||"0.0",status:l.MotorStatusW||"0x0000"};return 1==l.ShaftNumber&&(this.motor1=e),2==l.ShaftNumber&&(this.motor2=e),void(3==l.ShaftNumber&&(this.motor3=e))}if(t===M)return void(1==l.ShaftNumber?(this.motor1.runningSpeed=l.RunningSpeed||"0",this.motor1.accelerationTime=l.AccelerationTime||"0",this.motor1.stopTime=l.StopTime||"0",this.motor1.lower=l.LowerLimitAngle||"0",this.motor1.upper=l.UpperLimitAngle||"0"):2==l.ShaftNumber?(this.motor2.runningSpeed=l.RunningSpeed||"0",this.motor2.accelerationTime=l.AccelerationTime||"0",this.motor2.stopTime=l.StopTime||"0",this.motor2.lower=l.LowerLimitAngle||"0",this.motor2.upper=l.UpperLimitAngle||"0"):3==l.ShaftNumber&&(this.motor3.runningSpeed=l.RunningSpeed||"0",this.motor3.accelerationTime=l.AccelerationTime||"0",this.motor3.stopTime=l.StopTime||"0",this.motor3.lower=l.LowerLimitAngle||"0",this.motor3.upper=l.UpperLimitAngle||"0"));if(t===N)return this.motor1={angle:l.PositionAngleVOAA||"0",speed:l.CurrentApeedOAA||"0",current:l.CurrentOAxisA||"0.0",temp:l.TempAPresentV||"0.0",status:l.AxisStatusWordA||"0x0000"},this.motor2={angle:l.PositionAngleVOAB||"0",speed:l.CurrentApeedOAB||"0",current:l.CurrentOAxisB||"0.0",temp:l.TempBPresentV||"0.0",status:l.AxisStatusWordB||"0x0000"},void(this.motor3={angle:l.PositionAngleVOAC||"0",speed:l.CurrentApeedOAC||"0",current:l.CurrentOAxisC||"0.0",temp:l.TempCPresentV||"0.0",status:l.AxisStatusWordC||"0x0000"})}["10020","10021","10022","10023","1002F"].includes(t)&&console.log("指令执行结果:",l.JointCbkStatus)},sendMultiAngle(){if(0==this.shaftNumber)this.client.sendCmd(T,{TargetAAngleV:String(this.axis1Angle),TargetBAngleV:String(this.axis2Angle),TargetCAngleV:String(this.axis3Angle)});else{let e=0;1===this.shaftNumber&&(e=this.axis1Angle),2===this.shaftNumber&&(e=this.axis2Angle),3===this.shaftNumber&&(e=this.axis3Angle),this.client.sendCmd(A,{STargetAngleV:String(e),ShaftNumber:String(this.shaftNumber)})}this.actionShaftNumber.plus(this.shaftNumber),this.isSetMultiAngle=!1,s({title:"已发送",icon:"none"})},sendSetSingleAxisParm(){this.runningSpeed?this.accelerationTime?this.stopTime?(this.client.sendCmd(C,{RunningSpeed:String(this.runningSpeed),AccelerationTime:String(this.accelerationTime),StopTime:String(this.stopTime),ShaftNumber:String(this.shaftNumberSet)}),this.showParamPopup=!1,s({title:"已发送",icon:"none"})):s({title:"请输入减速时间",icon:"none"}):s({title:"请输入加速时间",icon:"none"}):s({title:"请输入运行速度",icon:"none"})},sendJointEnable(e,t){this.client.sendCmd(_,{JointEnable:String(e),ShaftNumber:String(t)}),0==e&&(this.actionShaftNumber=this.actionShaftNumber.filter((e=>e!==t)))},setMultiAngle(e){if(0===e){const e=this.axis1Angle,t=this.axis2Angle,i=this.axis3Angle,l=Number(this.motor1.lower),n=Number(this.motor1.upper),o=Number(this.motor2.lower),a=Number(this.motor2.upper),r=Number(this.motor3.lower),u=Number(this.motor3.upper);if(e<l||e>n)return void s({title:`轴1角度超出范围:${l}~${n}`,icon:"none",duration:2e3});if(t<o||t>a)return void s({title:`轴2角度超出范围:${o}~${a}`,icon:"none",duration:2e3});if(i<r||i>u)return void s({title:`轴3角度超出范围:${r}~${u}`,icon:"none",duration:2e3})}else{let t=0,i=0,l=0;if(1===e&&(t=this.axis1Angle,i=Number(this.motor1.lower),l=Number(this.motor1.upper)),2===e&&(t=this.axis2Angle,i=Number(this.motor2.lower),l=Number(this.motor2.upper)),3===e&&(t=this.axis3Angle,i=Number(this.motor3.lower),l=Number(this.motor3.upper)),t<i||t>l)return void s({title:`轴${e}角度超出范围:${i}~${l}`,icon:"none",duration:2e3})}this.isSetMultiAngle=!0,this.shaftNumber=e,this.sendJointEnable(1,0)},getMotorAllInfo(){this.client.sendCmd(N,{})},sendZeroCalibration(){this.shaftNumberSet?this.client.sendCmd(k,{ShaftNumber:String(this.shaftNumberSet)}):s({title:"请选择要标定的轴",icon:"none"})},getMotorSingleInfo(e){this.client.sendCmd(M,{ShaftNumber:e})}}},[["render",function(e,t,s,i,b,S){const _=o,A=d,T=f,C=p,k=g;return a(),l(_,{class:"container"},{default:n((()=>[r(_,{class:"form-group"},{default:n((()=>[r(_,{class:"form-item"},{default:n((()=>[r(_,{class:"form-left"},{default:n((()=>[r(_,{class:"label"},{default:n((()=>[u("底轴(轴1)")])),_:1}),r(_,{class:"label-sub"},{default:n((()=>[u("角度("+m(b.motor1.lower)+"°—"+m(b.motor1.upper)+"°)",1)])),_:1}),r(_,{class:"cs-fetch",onClick:t[0]||(t[0]=e=>S.setSetting(1))},{default:n((()=>[u("参数设置")])),_:1})])),_:1}),r(_,{class:"input-with-btn"},{default:n((()=>[r(A,{class:"input",type:"number",modelValue:b.axis1Angle,"onUpdate:modelValue":t[1]||(t[1]=e=>b.axis1Angle=e),modelModifiers:{number:!0},placeholder:"请输入角度"},null,8,["modelValue"]),b.actionShaftNumber.includes(1)?(a(),l(T,{key:0,class:"tzjust-btn",onClick:t[2]||(t[2]=e=>S.sendJointEnable(0,1))},{default:n((()=>[u("停止")])),_:1})):(a(),l(T,{key:1,class:"adjust-btn",onClick:t[3]||(t[3]=e=>S.setMultiAngle(1))},{default:n((()=>[u("调整")])),_:1}))])),_:1})])),_:1}),r(_,{class:"form-item"},{default:n((()=>[r(_,{class:"form-left"},{default:n((()=>[r(_,{class:"label"},{default:n((()=>[u("中轴(轴2)")])),_:1}),r(_,{class:"label-sub"},{default:n((()=>[u("角度("+m(b.motor2.lower)+"°—"+m(b.motor2.upper)+"°)",1)])),_:1}),r(_,{class:"cs-fetch",onClick:t[4]||(t[4]=e=>S.setSetting(2))},{default:n((()=>[u("参数设置")])),_:1})])),_:1}),r(_,{class:"input-with-btn"},{default:n((()=>[r(A,{class:"input",type:"number",modelValue:b.axis2Angle,"onUpdate:modelValue":t[5]||(t[5]=e=>b.axis2Angle=e),modelModifiers:{number:!0},placeholder:"请输入角度"},null,8,["modelValue"]),b.actionShaftNumber.includes(2)?(a(),l(T,{key:0,class:"tzjust-btn",onClick:t[6]||(t[6]=e=>S.sendJointEnable(0,2))},{default:n((()=>[u("停止")])),_:1})):(a(),l(T,{key:1,class:"adjust-btn",onClick:t[7]||(t[7]=e=>S.setMultiAngle(2))},{default:n((()=>[u("调整")])),_:1}))])),_:1})])),_:1}),r(_,{class:"form-item"},{default:n((()=>[r(_,{class:"form-left"},{default:n((()=>[r(_,{class:"label"},{default:n((()=>[u("顶轴(轴3)")])),_:1}),r(_,{class:"label-sub"},{default:n((()=>[u("角度("+m(b.motor3.lower)+"°—"+m(b.motor3.upper)+"°)",1)])),_:1}),r(_,{class:"cs-fetch",onClick:t[8]||(t[8]=e=>S.setSetting(3))},{default:n((()=>[u("参数设置")])),_:1})])),_:1}),r(_,{class:"input-with-btn"},{default:n((()=>[r(A,{class:"input",type:"number",modelValue:b.axis3Angle,"onUpdate:modelValue":t[9]||(t[9]=e=>b.axis3Angle=e),modelModifiers:{number:!0},placeholder:"请输入角度"},null,8,["modelValue"]),b.actionShaftNumber.includes(3)?(a(),l(T,{key:0,class:"tzjust-btn",onClick:t[10]||(t[10]=e=>S.sendJointEnable(0,3))},{default:n((()=>[u("停止")])),_:1})):(a(),l(T,{key:1,class:"adjust-btn",onClick:t[11]||(t[11]=e=>S.setMultiAngle(3))},{default:n((()=>[u("调整")])),_:1}))])),_:1})])),_:1})])),_:1}),b.actionShaftNumber.includes(0)?(a(),l(T,{key:0,class:"tzjust-btn",onClick:t[12]||(t[12]=e=>S.sendJointEnable(0,0))},{default:n((()=>[u("停止")])),_:1})):(a(),l(T,{key:1,class:"btn-confirm",onClick:t[13]||(t[13]=e=>S.setMultiAngle(0))},{default:n((()=>[u("确认调整")])),_:1})),r(_,{class:"info-header"},{default:n((()=>[r(_,{class:"title"},{default:n((()=>[u("上位机信息")])),_:1}),r(_,{class:"btn-fetch",onClick:S.getMotorAllInfo},{default:n((()=>[u("点击获取")])),_:1},8,["onClick"])])),_:1}),0!=b.faultAxis?(a(),l(_,{key:2,class:"fault-box"},{default:n((()=>[u(" 故障:轴"+m(b.faultAxis)+" | 错误码:"+m(b.faultCode),1)])),_:1})):c("",!0),r(k,{class:"info-list","scroll-y":""},{default:n((()=>[r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴1当前角度")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor1.angle)+"°",1)])),_:1})])),_:1}),r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴1当前速度")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor1.speed)+" rpm",1)])),_:1})])),_:1}),r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴1电流")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor1.current)+" A",1)])),_:1})])),_:1}),r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴1温度")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor1.temp)+" ℃",1)])),_:1})])),_:1}),r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴1状态")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor1.status),1)])),_:1})])),_:1}),r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴2当前角度")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor2.angle)+"°",1)])),_:1})])),_:1}),r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴2当前速度")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor2.speed)+" rpm",1)])),_:1})])),_:1}),r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴2电流")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor2.current)+" A",1)])),_:1})])),_:1}),r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴2温度")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor2.temp)+" ℃",1)])),_:1})])),_:1}),r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴2状态")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor2.status),1)])),_:1})])),_:1}),r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴3当前角度")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor3.angle)+"°",1)])),_:1})])),_:1}),r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴3当前速度")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor3.speed)+" rpm",1)])),_:1})])),_:1}),r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴3电流")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor3.current)+" A",1)])),_:1})])),_:1}),r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴3温度")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor3.temp)+" ℃",1)])),_:1})])),_:1}),r(_,{class:"info-item"},{default:n((()=>[r(C,null,{default:n((()=>[u("轴3状态")])),_:1}),r(C,null,{default:n((()=>[u(m(b.motor3.status),1)])),_:1})])),_:1})])),_:1}),b.showParamPopup?(a(),l(_,{key:3,class:"popup-mask",onClick:t[14]||(t[14]=e=>b.showParamPopup=!1)})):c("",!0),r(_,{class:h(["popup-bottom",b.showParamPopup?"popup-show":""])},{default:n((()=>[r(_,{class:"popup-header"},{default:n((()=>[u("轴"+m(b.shaftNumberSet)+"参数设置",1)])),_:1}),r(_,{class:"form-item-row"},{default:n((()=>[r(C,null,{default:n((()=>[u("运行速度")])),_:1}),r(A,{modelValue:b.runningSpeed,"onUpdate:modelValue":t[15]||(t[15]=e=>b.runningSpeed=e),modelModifiers:{number:!0},type:"number",placeholder:"请输入速度"},null,8,["modelValue"])])),_:1}),r(_,{class:"form-item-row"},{default:n((()=>[r(C,null,{default:n((()=>[u("加速时间")])),_:1}),r(A,{modelValue:b.accelerationTime,"onUpdate:modelValue":t[16]||(t[16]=e=>b.accelerationTime=e),modelModifiers:{number:!0},type:"number",placeholder:"请输入加速时间"},null,8,["modelValue"])])),_:1}),r(_,{class:"form-item-row"},{default:n((()=>[r(C,null,{default:n((()=>[u("减速时间")])),_:1}),r(A,{modelValue:b.stopTime,"onUpdate:modelValue":t[17]||(t[17]=e=>b.stopTime=e),modelModifiers:{number:!0},type:"number",placeholder:"请输入减速时间"},null,8,["modelValue"])])),_:1}),r(_,{class:"popup-btns"},{default:n((()=>[r(T,{class:"set-btn zero-btn",onClick:S.sendZeroCalibration},{default:n((()=>[u("零点标定")])),_:1},8,["onClick"]),r(T,{class:"set-btn confirm-btn",onClick:S.sendSetSingleAxisParm},{default:n((()=>[u("确认设置")])),_:1},8,["onClick"])])),_:1})])),_:1},8,["class"])])),_:1})}],["__scopeId","data-v-92e0a0ba"]]);export{V as default};