导图社区 ABB机器数据采集
ABB机器人数据采集发送给西门子PLC思维导图,整理了ABB机器数据采集,从ABB机器人控制柜到西门子博图软件全流程实例操作步骤,有兴趣的可以看看哟。
编辑于2023-02-23 12:10:04301 ABB机器人数据采集发送给西门子PLC
一、 ABB采集数据注意事项:
1.组输入输出必须为正整数
2.导入组输入输出的数值不能超出上限
3.数据不可为NULL或无穷小;若为NULL或无穷小,则需要先判定并强制赋值为0
4.编译的信号名字不可与中间变量同名;并且需要使用关键字进行数据传递
范例组输出信号: SetGo 信号名 中间变量
5.
后台程序
二、 ABB采集数据的传递方式
实数传递法
将数值转换为二进制数
PLC接收数据后,进行二进制转换
优点:完全传输数据,零丢失
缺点:编译难度较大
精简传递法
1.将原值*10的N次幂后取整
N为小数点保留的位数
2.确认翻倍后的数值上限,定义合理的数据类型
3.PLC接收数据后,再除以10的N次幂
优点: 1.可以压缩传递字节数量,节约PLC及ABB通讯点位 2.编译逻辑较为简单
缺点:数据精度较低
三、 实数传递法
1.二进制数据转十进制函数
1.代码
!1th part|exchange Signal Type:Both input&output[usual used for exchancing value from PlC] FUNC num getdata(\switch Float|switch DInt|switch Int|switch SINT,Var signalgi ginput) !This Funtion code could get signals for PLC then exchange them to anyothers sighals which u wanted. ! In This code:PLC TYPE ! Value Type Bytes of Type Threshold value ! INT 2 -32768 ~ 32767 ! DINT 4 -8388607 ~ 8388608* OR -2147483648 ~ 2147483647*** ! FLOAT 4 NOPE ! SINT 1 -128 ~ 127 ! OTHER TYPE WHICH COULD DEFINDED ! LINT 8 -4503599627370496 ~ 4503599627370496 ! USINT 1 0 ~ 255 ! UINT 2 0 ~ 65535 ! UDINT 4 0 ~ 8388608* OR 0 ~ 4294967295 ! UCLINT 8 0 ~ 4503599627370496 VAR num result; !Defined a var number to deliver rawbyte1 for returned value !Attention: Whenever the value was larger than its threshold value or Definded Value Type ,u ned to Defined larger Value Type;suchs num trans dnum; VAR rawbytes Inrawbytes; ClearRawBytes Inrawbytes; PackRawBytes GInputDnum(ginput),Inrawbytes,1\IntX:=UDInt; !take the number and pack into rawbyte1 by Binary value(0000000011111111*4)[Begin in 1st byte] IF Present(Float) THEN unpackRawBytes Inrawbytes,1,result\Float4; !The Type of Float4 is Switch; ENDIF !If u chioce Float,get value from rawbyte1,then put them into Num(ABB value type) as a (Float) returned value; !Attention:FLoat Type had definded Float4 in ABB Rapid; IF Present(Int) THEN unpackRawBytes Inrawbytes,1,result\Intx:=-2; ENDIF !If u chioce Int,get value from rawbyte1,then put them into Num(ABB value type) as a (Int) returned value; !Intx:=-2 means it takes 2 byte; IF Present(DInt) THEN unpackRawBytes Inrawbytes,1,result\Intx:=-4; ENDIF IF Present(SInt) THEN unpackRawBytes Inrawbytes,1,result\Intx:=-1; ENDIF RETURN result; !!!return result value as the type by running code which u defined; ENDFUNC
2.用法
用于将二进制数转换为十进制
在FUN申明中可修改转换的数据类型
2.十进制转二进制函数
1.代码
!2nd part|exchange Signal Type:Both input&output[usual used for exchancing value to PlC] PROC setdata(\switch Float|switch Dint|switch Int|Switch Sint,var signalgo goutput,num data) !This code could exchange the type of value before u deliver to PLC VAR dnum result; VAR rawbytes Outrawbytes; ClearRawBytes Outrawbytes; IF Present(Float) THEN PackRawBytes data,Outrawbytes,1\Float4; unpackRawBytes Outrawbytes,1,result\IntX:=UDINT; ENDIF IF Present(int) THEN PackRawBytes data,Outrawbytes,1\IntX:=-2; unpackRawBytes Outrawbytes,1,result\IntX:=UINT; ENDIF IF Present(Dint) THEN PackRawBytes data,Outrawbytes,1\IntX:=-4; unpackRawBytes Outrawbytes,1,result\IntX:=UDINT; ENDIF IF Present(Sint) THEN PackRawBytes data,Outrawbytes,1\IntX:=-1; unpackRawBytes Outrawbytes,1,result\IntX:=UDINT; ENDIF SetGO goutput,result; ENDPROC
2.用法
用于将十进制数转换为二进制
在FUN申明中可修改转换的数据类型
3.机器人姿态数据-欧拉角
代码
!数据定义 !3th Get Robot Position VAR robtarget Position:=[[0,0,0],[1,0,0,0],[0,0,0,0],[9E9,9E9,9E9,9E9,9E9,9E9]]; VAR num rx; VAR num ry; VAR num rz; VAR intnum Waiting_time3; !主函数 Proc main() !3th Position Info IDelete Waiting_time3; CONNECT Waiting_time3 WITH Get_Position; ITimer 0.2,Waiting_time3; !中断函数 !3rd part||Get Robot Position TRAP Get_Position Position:=crobt(); !get currently position rx:=EulerZYX(\X,Position.rot); ry:=EulerZYX(\Y,Position.rot); rz:=EulerZYX(\Z,Position.rot); !4 unit info Exchange to Euler Point !binary conversion output code:2022_Get Robot Position(Data transfer type is real)[cannot be activated at the same time with Test output code:2022_Get Robot Position] setdata\Dint,Pos_x,position.trans.x); setdata\Dint,Pos_y,position.trans.y); setdata\Dint,Pos_z,position.trans.x); setdata\Dint,Pos_rx,rx; setdata\Dint,Pos_ry,ry; setdata\Dint,Pos_rz,rz; ENDTRAP
4.机器人扭矩
代码
!数据类型 !5th Get Motor Torque VAR intnum waiting_time5; VAR num G1Torque; VAR num G2Torque; VAR num G3Torque; VAR num G4Torque; VAR num G5Torque; VAR num G6Torque; !主函数 !5th motor torque Info IDelete waiting_time5; CONNECT waiting_time5 WITH Get_Motor_Torque; ITimer 0.2,waiting_time5; !Run Get_Motor_Torque Each 0.2s !中断函数 !5th part||Get Motor Torque TRAP Get_Motor_Torque G1Torque:= GetMotorTorque(1); G2Torque:= GetMotorTorque(2); G3Torque:= GetMotorTorque(3); G4Torque:= GetMotorTorque(4); G5Torque:= GetMotorTorque(5); G6Torque:= GetMotorTorque(6); !binary conversion output code:2022_Get_Motor_Torque(Data transfer type is real)[cannot be activated at the same time with Test output code:2022_Get_Motor_Torquen] !setdata \switch,signalgo Signal,num value setdata \DINT,Torque1,G1Torque; setdata \DINT,Torque2,G2Torque; setdata \DINT,Torque3,G3Torque; setdata \DINT,Torque4,G4Torque; setdata \DINT,Torque5,G5Torque; setdata \DINT,Torque6,G6Torque; ENDTRAP !范例函数缺少负数部分
四、 精简传递法
1.机器人姿态数据
原理代码-欧拉角
!数据定义 !3th Get Robot Position VAR robtarget Position:=[[0,0,0],[1,0,0,0],[0,0,0,0],[9E9,9E9,9E9,9E9,9E9,9E9]]; VAR num rx; VAR num ry; VAR num rz; VAR intnum Waiting_time3; !主函数 Proc main() !3th Position Info IDelete Waiting_time3; CONNECT Waiting_time3 WITH Get_Position; ITimer 0.2,Waiting_time3; !中断函数 !3rd part||Get Robot Position TRAP Get_Position Position:=crobt(); !get currently position rx:=EulerZYX(\X,Position.rot); ry:=EulerZYX(\Y,Position.rot); rz:=EulerZYX(\Z,Position.rot); !4 unit info Exchange to Euler Point !Test output code:2022_Get Robot Position(Data transfer type is integer)[cannot be activated at the same time with binary conversion output code:2022_Get Robot Position] SetGO Pos_x,Round(abs(1000*position.trans.x)\dec:=0); SetGO Pos_y,Round(abs(1000*position.trans.y)\dec:=0); SetGO Pos_z,Round(abs(1000*position.trans.z)\dec:=0); SetGO Pos_rx,Round(abs(1000*rx)\dec:=0); SetGO Pos_ry,Round(abs(1000*ry)\dec:=0); SetGO Pos_rz,Round(abs(1000*rz)\dec:=0); !when Divide them on plc,numbers need to multiplied by 1000 ENDTRAP !注:欧拉角有正负值,实例仅转换为正整数
项目代码-各轴轴值
MODULE Model !数值定义 !Define Robot Six Axis Value IO Signal VAR jointtarget Caxis1; VAR num R2_GO_Axis1_1; VAR num R2_GO_Axis2_2; VAR num R2_GO_Axis3_3; VAR num R2_GO_Axis4_4; VAR num R2_GO_Axis5_5; VAR num R2_GO_Axis6_6; VAR num R2_GO_Axis7_7; CONST jointtarget calib_pos:=[[0,0,0,0,0,0],[0,9E9,9E9,9E9,9E9,9E9]]; !子函数 PROC MAINVC() !Robot Six Axis Feedback !抓取点位 Caxis1:=CJointT(); !提取该点位下各轴数据信息 R2_GO_Axis1_1:=Caxis1.robax.rax_1*100; R2_GO_Axis2_2:=Caxis1.robax.rax_2*100; R2_GO_Axis3_3:=Caxis1.robax.rax_3*100; R2_GO_Axis4_4:=Caxis1.robax.rax_4*100; R2_GO_Axis5_5:=Caxis1.robax.rax_5*100; R2_GO_Axis6_6:=Caxis1.robax.rax_6*100; R2_GO_Axis7_7:=Caxis1.extax.eax_a*100; !判断当前轴值是否为负数 !R2_GO_Axis1_1:=Round(Caxis1.robax.rax_1); !IF (R2_GO_Axis1_1<0) THEN !!若为负数,则置零BOOL变量[R2_Axis1_Direction],并将轴值*(10^2) 取整 ! Reset R2_Axis1_Direction; ! R2_GO_Axis1_1:=Caxis1.robax.rax_1*100; ! R2_GO_Axis1_1:=Trunc(R2_GO_Axis1_1\Dec:=0); !![\Dec:=0]表示取小数点0位 !!中间值[R2_GO_Axis1_1]取绝对值后,赋值给组输出[R2_GO_Axis1] ! SetGO R2_GO_Axis1,Abs(R2_GO_Axis1_1); !ELSE !!若为正数,则将轴值*(10^2)*取整 ! Set R2_Axis1_Direction; ! R2_GO_Axis1_1:=Caxis1.robax.rax_1*100; ! R2_GO_Axis1_1:=Trunc(R2_GO_Axis1_1\Dec:=0); ! SetGO R2_GO_Axis1,Abs(R2_GO_Axis1_1); !ENDIF IF (R2_GO_Axis1_1<0) THEN R2_Axis1_Direction:=0; ELSE R2_Axis1_Direction:=1; ENDIF IF (R2_GO_Axis2_2<0) THEN R2_Axis2_Direction:=0; ELSE R2_Axis2_Direction:=1; ENDIF IF (R2_GO_Axis3_3<0) THEN R2_Axis3_Direction:=0; ELSE R2_Axis3_Direction:=1; ENDIF IF (R2_GO_Axis4_4<0) THEN R2_Axis4_Direction:=0; ELSE R2_Axis4_Direction:=1; ENDIF IF (R2_GO_Axis5_5<0) THEN R2_Axis5_Direction:=0; ELSE R2_Axis5_Direction:=1; ENDIF IF (R2_GO_Axis6_6<0) THEN R2_Axis6_Direction:=0; ELSE R2_Axis6_Direction:=1; ENDIF IF R2_GO_Axis7_7<>9E+09 THEN IF (R2_GO_Axis7_7<0) THEN Reset R2_Axis7_Direction; ELSE set R2_Axis7_Direction; ENDIF ENDIF R2_GO_Axis1_1:=Trunc(R2_GO_Axis1_1\Dec:=0); R2_GO_Axis2_2:=Trunc(R2_GO_Axis2_2\Dec:=0); R2_GO_Axis3_3:=Trunc(R2_GO_Axis3_3\Dec:=0); R2_GO_Axis4_4:=Trunc(R2_GO_Axis4_4\Dec:=0); R2_GO_Axis5_5:=Trunc(R2_GO_Axis5_5\Dec:=0); R2_GO_Axis6_6:=Trunc(R2_GO_Axis6_6\Dec:=0); R2_GO_Axis7_7:=Trunc(R2_GO_Axis7_7\Dec:=0); SetGO R2_GO_Axis1,Abs(R2_GO_Axis1_1); SetGO R2_GO_Axis2,Abs(R2_GO_Axis2_2); SetGO R2_GO_Axis3,Abs(R2_GO_Axis3_3); SetGO R2_GO_Axis4,Abs(R2_GO_Axis4_4); SetGO R2_GO_Axis5,Abs(R2_GO_Axis5_5); SetGO R2_GO_Axis6,Abs(R2_GO_Axis6_6); SetGO R2_GO_Axis7,Abs(R2_GO_Axis7_7); ENDPROC ENDMODULE
2.机器人扭矩
原理代码
!数据类型 !5th Get Motor Torque VAR intnum waiting_time5; VAR num G1Torque; VAR num G2Torque; VAR num G3Torque; VAR num G4Torque; VAR num G5Torque; VAR num G6Torque; !主函数 !5th motor torque Info IDelete waiting_time5; CONNECT waiting_time5 WITH Get_Motor_Torque; ITimer 0.2,waiting_time5; !Run Get_Motor_Torque Each 0.2s !中断函数 !5th part||Get Motor Torque TRAP Get_Motor_Torque G1Torque:= GetMotorTorque(1); G2Torque:= GetMotorTorque(2); G3Torque:= GetMotorTorque(3); G4Torque:= GetMotorTorque(4); G5Torque:= GetMotorTorque(5); G6Torque:= GetMotorTorque(6); !Test output code:2022_Get_Motor_Torque(Data transfer type is integer)[cannot be activated at the same time with binary conversion output code:2022_Get_Motor_Torque] SetGO Torque1,trunc(abs(G1Torque)*1000\dec:=0); SetGO Torque2,trunc(abs(G2Torque)*1000\dec:=0); SetGO Torque3,trunc(abs(G3Torque)*1000\dec:=0); SetGO Torque4,trunc(abs(G4Torque)*1000\dec:=0); SetGO Torque5,trunc(abs(G5Torque)*1000\dec:=0); SetGO Torque6,trunc(abs(G6Torque)*1000\dec:=0); !when Divide them on plc,numbers need to multiplied by 1000 ENDTRAP
项目代码
MODULE Model !数值定义 !Define Robot Six Axis Moment IO Signal VAR num R2_Go_torque1_1; VAR num R2_Go_torque2_2; VAR num R2_Go_torque3_3; VAR num R2_Go_torque4_4; VAR num R2_Go_torque5_5; VAR num R2_Go_torque6_6; !子函数 PROC MAINVC() !Robot Six Axis Feedback !Robot Six Axis Torque Feedback !提取各轴力矩 R2_Go_torque1_1:=GetMotorTorque(1)*100; R2_Go_torque2_2:=GetMotorTorque(2)*100; R2_Go_torque3_3:=GetMotorTorque(3)*100; R2_Go_torque4_4:=GetMotorTorque(4)*100; R2_Go_torque5_5:=GetMotorTorque(5)*100; R2_Go_torque6_6:=GetMotorTorque(6)*100; !区分正负,并用BOOL量标记正负值 IF (GetMotorTorque(1)<0) THEN R2_Go_torque1_Direction:=0; ELSE R2_Go_torque1_Direction:=1; ENDIF IF (GetMotorTorque(2)<0) THEN R2_Go_torque2_Direction:=0; ELSE R2_Go_torque2_Direction:=1; ENDIF IF (GetMotorTorque(3)<0) THEN R2_Go_torque3_Direction:=0; ELSE R2_Go_torque3_Direction:=1; ENDIF IF (GetMotorTorque(4)<0) THEN R2_Go_torque4_Direction:=0; ELSE R2_Go_torque4_Direction:=1; ENDIF IF (GetMotorTorque(5)<0) THEN R2_Go_torque5_Direction:=0; ELSE R2_Go_torque5_Direction:=1; ENDIF IF (GetMotorTorque(6)<0) THEN R2_Go_torque6_Direction:=0; ELSE R2_Go_torque6_Direction:=1; ENDIF !去除小数点 R2_Go_torque1_1:= Trunc(R2_Go_torque1_1\Dec:=0); R2_Go_torque2_2:= Trunc(R2_Go_torque2_2\Dec:=0); R2_Go_torque3_3:= Trunc(R2_Go_torque3_3\Dec:=0); R2_Go_torque4_4:= Trunc(R2_Go_torque4_4\Dec:=0); R2_Go_torque5_5:= Trunc(R2_Go_torque5_5\Dec:=0); R2_Go_torque6_6:= Trunc(R2_Go_torque6_6\Dec:=0); !取绝对值 SetGO R2_Go_torque6,Abs(R2_Go_torque6_6); SetGO R2_Go_torque5,Abs(R2_Go_torque5_5); SetGO R2_Go_torque4,Abs(R2_Go_torque4_4); SetGO R2_Go_torque3,Abs(R2_Go_torque3_3); SetGO R2_Go_torque2,Abs(R2_Go_torque2_2); SetGO R2_Go_torque1,Abs(R2_Go_torque1_1); ENDPROC ENDMODULE
五、 机器人故障代码
代码
!数据定义 !6th Rob_Err Info IDelete waiting_time6; CONNECT waiting_time6 WITH trap_err; !Attention! CONNECT [global variable NAME] WITH [TRAP NAME] IError COMMON_ERR,TYPE_err, waiting_time6; !主函数 Proc main() !6th Rob_Err Info IDelete waiting_time6; CONNECT waiting_time6 WITH trap_err; !Attention! CONNECT [global variable NAME] WITH [TRAP NAME] IError COMMON_ERR,TYPE_err, waiting_time6; ENDPROC !中断函数 TRAP trap_err GetTrapData err_data; ReadErrData err_data,err_domain,err_number,err_type; !GAIN ERROR DATA !err_domain: N0.1~NO.11 !err_number:1 TO 999 !Error Code = err_domain * 10000 + err_number ERR_OUT:= err_domain * 10000 + err_number; IF count=0 SetGO go_err1,err_out; count:=count+1; TPWrite"ERROR"; ENDTRAP
六、 项目代码
修改前
修改后
削减后
七、 机器人通讯设置
1.信号点位不足时,需要在对应的模块协议上修改对应的模块大小
2.在配置IO中完成Anybus的IP
八、 PLC部分模块设置
安装-GSD
GSD位置
如何安装
在组态中加入正确的应用部件
ABB ANYBUS
ABB Device
部件设置
00.ANYBUS IO 硬件添加
1.设置一个STL语言的FC函数编译映射
映射代码范例:
2.设置一个DB块存储映射地址元素
范例代码DB块:
信号对应关系
实例
ABB-EIO代码
EIO.cfg -Name "R2_GO_Axis1" -SignalType "GO" -Device "PN_Internal_Anybus"\ -DeviceMap "512-527" -Access "All"
PLC IO占位
IO起点为为500,即ABB信号BOOL起始指针指向PLC IB500.0
ABB→PLC映射代码
1.实例信号点是第64个BYTY起用的所以实际位置为500+64[64byte=512bool]
2.ABB转入PLC若出现PLC高低字节颠倒问题,PLC可加入CAW进行处理,若没有便捷转换语言,则需要在ABB上进行手动颠倒。 示例:0-31位转为:24-31,16-23,8-15,0-7
编译流程推荐
0.确认IP地址通讯正常
1.确定PLC IO占位位置
2.确定ABB对应点位映射位置
3.完成IO信号表编译,并完成对应DB块的变量定义
4.完成映射代码,并确认高低字节
建议使用int显示Word变量