使用

您可以使用 Beckhoff TwinCAT 3 软件测试与 RoboDK OPC UA 服务器的连接性。

添加 TwinCAT3 服务器

首先,您可以通过选择 I/O>Devices>Add New Item(I/O>设备>添加新项目)来创建 OPC UA 客户端。

OPC UA - 图片 48

从 OPC >OK 中选择虚拟 OPC UA 设备。

OPC UA - 图片 49

插入 OPC UA 虚拟。

OPC UA - 图片 50

我们需要添加一个 OPC UA 客户端来访问 RoboDK OPC UA 服务器。

选择设备 1 >右键单击 >添加新插件。

OPC UA - 图片 51

选择 "OPC UA 客户端(模块)",然后确定。

OPC UA - 图片 52

插入 OPC UA 客户端。

OPC UA - 图片 53

配置服务器

打开 OPC UA 客户端 > 进入设置选项卡 > 点击 "选择端点 "配置要访问的 OPC UA 服务器端点。

OPC UA - 图片 54

输入 RoboDK OPC UA 服务器 URL 并更新。

OPC UA - 图片 55

插件 RoboDK 服务器方法

按 "Add Nodes(添加节点)"浏览 OPC UA Server 内部的节点。

OPC UA - 图片 56

如果 TwinCAT 与 OPC UA 服务器之间的连接已建立,则可以浏览 OPC UA 服务器的详细信息。

OPC UA - 图片 57

选择所有方法,然后确定。

OPC UA - 图片 58

方法会插入到您的 "配置 "中。

OPC UA - 图片 59

自动生成 RoboDK 方法

在此字段中配置您的名称前缀。

OPC UA - 图片 60

按 "创建 PLC 代码",从 TwinCAT 创建 PLC 代码。

OPC UA - 图片 61

在项目中创建 OpcUaClient 文件夹,并以 IEC61131-3 功能块格式创建所有 RoboDK 方法。

OPC UA - 图片 62

PLC 程序示例

本节展示了 Beckhoff TwinCAT PLC 与 RoboDK OPC UA 服务器通信的示例程序。

主程序

VAR

   bConnected      BOOL;

   站点指针    :DINT;

   iStep           :INT;

   bStart          :BOOL;;

   i               :INT;

   吨               :TON;

   bReset          :BOOL;

   bWrite          :BOOL;

   TON2            :TON;

   bShow           BOOL:=TRUE;

   bVis            BOOL:=True;

END_VAR

 

VAR

   机器人名称        :string(80):='abb_rb1';

   项目 ID          :ULINT;

   arrJoints       :array[0..11]of lreal;

   strJoints       :string(80):='';

   arrJointsFromStr:ARRAY[1...11]OF LREAL;

   sSeparator      :string(1) := ',';

   arrJointsCommand:ARRAY[1...11]OF LREAL;

   strJointsCommand:STRING(80);

END_VAR

 

VAR CONSTANT

   cStepWaitCmd          :INT:=0;

   cStepInit             :INT:=5;

   cStepGetItem          :INT:=10;

   cStepGetItemReset     :INT:=20;

   cStepGetItemError     :INT:=990;

  

   cStepGetJoints        :INT:=30;

   cStepGetJointsReset   :INT:=40;

   cStepGetJointsError   :INT:=991;

  

   cStepGetJointsStr     :INT:=50;

   cStepGetJointsStrReset:INT:=60;

   cStepGetJointsStrError:INT:=992;

  

   cStepSetJointStrDelay :INT:=69;

   cStepSetJointsStr     :INT:=70;

   cStepSetJointsStrReset:INT:=80;

   cStepSetJointsStrError:INT:=993;

  

   cStepEnd              :INT:=300;

   cStepWaitReset        :INT:=999;

END_VAR

 

 

VAR

      aSplit :ARRAY[1..11] OF STRING(80);

      bResultSplit :BOOL;

调试         :BOOL;

   URL        :STRING:='http://192.168.3.42:8091';

END_VAR

bConnected:=OPCUA_VirtualClient_RoboDK_Station.bConnected;

 

案例 iStep OF

  

 

   cStepWaitCmd:

        IF bStart THEN

              iStep:=cStepInit;

              bStart:=FALSE;

        END_IF

  

   cStepInit:

 

        StationPointer:=0;

        FOR i :=1 TO 11 DO

              arrJoints[i]:=0.0;

              arrJointsFromStr[i]:=0.0;

              aSplit[i]:='';

        结束

        IF NOT OPCUA_VirtualClient_RoboDK_Station.getItem.bBusy

              AND NOT OPCUA_VirtualClient_RoboDK_Station.getItem.bError

              AND NOT OPCUA_VirtualClient_RoboDK_Station.getJoints.bBusy

              AND NOT OPCUA_VirtualClient_RoboDK_Station.getJoints.bError

              AND NOT OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bBusy

              AND NOT OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bError

              AND NOT OPCUA_VirtualClient_RoboDK_Station.setJoints.bBusy

              AND NOT OPCUA_VirtualClient_RoboDK_Station.setJoints.bError

              AND NOT OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bBusy

              AND NOT OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bError

              然后

              iStep:=cStepGetItem;

        END_IF

        iStep:=cStepGetItem;

  

   cStepGetItem:

 

        IF OPCUA_VirtualClient_RoboDK_Station.getItem.bDone THEN

              iStep:=cStepGetItemReset;

        Item_ID:=OPCUA_VirtualClient_RoboDK_Station.getItem.Item_ID;

        ELSIF OPCUA_VirtualClient_RoboDK_Station.getItem.bError THEN

              iStep:=cStepGetItemError;

        END_IF

       

   cStepGetItemReset:

 

        IF NOT OPCUA_VirtualClient_RoboDK_Station.getItem.bError

              AND NOT OPCUA_VirtualClient_RoboDK_Station.getItem.bBusy

              然后

              iStep:=cStepGetJoints;

        END_IF

   cStepGetJoints:

 

        IF OPCUA_VirtualClient_RoboDK_Station.getJoints.bDone

              AND NOT OPCUA_VirtualClient_RoboDK_Station.getJoints.bBusy

              然后

              iStep:=cStepGetJointsReset;

        ELSIF OPCUA_VirtualClient_RoboDK_Station.getJoints.bError THEN

              iStep:=991;

        END_IF

       

   cStepGetJointsReset:

 

        IF NOT OPCUA_VirtualClient_RoboDK_Station.getItem.bError

              AND NOT OPCUA_VirtualClient_RoboDK_Station.getItem.bBusy

       

              然后

              iStep:=cStepGetJointsStr;

        END_IF;

       

   cStepGetJointsStr:

 

        IF OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bDone

              AND NOT OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bBusy

             然后

              iStep:=cStepGetJointsStrReset;

        ELSIF OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bError THEN

              iStep:=cStepGetJointsStrError;

        END_IF         

 

   cStepGetJointsStrReset:

 

        IF NOT OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bError

              AND NOT OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bBusy

              然后

                   iStep:=cStepSetJointStrDelay;

        END_IF;

       

   cStepSetJointStrDelay:

        strJointsCommand:=''; strJointsCommand:=CONCAT(LREAL_TO_STRING(arrJointsCommand[1]),strJointsCommand);

        strJointsCommand:=CONCAT(strJointsCommand,',');

   strJointsCommand:=CONCAT(strJointsCommand,LREAL_TO_STRING(arrJointsCommand[2]));

        strJointsCommand:=CONCAT(strJointsCommand,',');

   strJointsCommand:=CONCAT(strJointsCommand,LREAL_TO_STRING(arrJointsCommand[3]));

        strJointsCommand:=CONCAT(strJointsCommand,',');

   strJointsCommand:=CONCAT(strJointsCommand,LREAL_TO_STRING(arrJointsCommand[4]));

        strJointsCommand:=CONCAT(strJointsCommand,',');

   strJointsCommand:=CONCAT(strJointsCommand,LREAL_TO_STRING(arrJointsCommand[5]));

        strJointsCommand:=CONCAT(strJointsCommand,',');

   strJointsCommand:=CONCAT(strJointsCommand,LREAL_TO_STRING(arrJointsCommand[6]));

        ton2(in:=true,pt:=t#0.2s);

        IF TON2.Q THEN

              ton2(in:=false);

              iStep:=cStepSetJointsStr;

        END_IF

  

   cStepSetJointsStr:

 

       

        如果 (

        OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bDone

              而不是   

        OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bBusy

         )

              OR NOT bWrite

              然后

              iStep:=cStepSetJointsStrReset;

        ELSIF OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bError           

          然后

              iStep:=cStepSetJointsStrError;

        END_IF    

             

   cStepSetJointsStrReset:

        bWrite:=FALSE;

   OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bExecute:=FALSE;

        IF NOT OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bError

              AND NOT OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bBusy

              然后

              iStep:=cStepEnd;

        END_IF;

       

   cStepEnd:

        ton(in:=true,pt:=t#0.1s);

        IF TON.Q THEN

              ton(in:=false);

              IF NOT debug THEN

                   iStep:=10;

              否则

                   iStep:=cStepSetJointStrDelay;

              END_IF;

        END_IF

       

   cStepGetItemError:

        Item_ID:=0;

        iStep:=cStepWaitReset;

  

   cStepGetJointsError:

        FOR i :=0 TO 11 DO

              arrJoints[i]:=-99999.99;

        结束

        iStep:=cStepWaitReset;

       

   cStepGetJointsStrError:

        strJoints:='';

        iStep:=cStepWaitReset;

       

   cStepWaitReset:

        IF bReset THEN

              iStep:=cStepInit;

              bReset:=FALSE;

        END_IF;  

结束

 

aSplit[1] := strJoints;

 

FOR i:=1 TO 7 DO

bResultSplit := FindAndSplit(

   pSeparator := ADR(sSeparator)

   pSrcString := ADR(aSplit[i])

   ,pLeftString:= ADR(aSplit[i])

   ,nLeftSize := SIZEOF(aSplit[i])

   ,pRightString:= ADR(aSplit[i+1])

   ,nRightSize := SIZEOF(aSplit[i+1])

   ,bSearchFromRight := FALSE );

IF NOT bResultSplit THEN

退出;

END_IF

结束

 

FOR i :=1 TO 6 DO

   arrJointsFromStr[i]:=STRING_TO_LREAL(aSplit[i]);

END_FOR;

 

//

OPCUA_VirtualClient_RoboDK_Station.getItem(

bExecute:=iStep=cStepGetItem

项目名称:=机器人名称

);

 

 

OPCUA_VirtualClient_RoboDK_Station.getJoints(

bExecute:=iStep=cStepGetJoints

,Item_ID:=Item_ID,Joints=>arrJoints

);

 

 

OPCUA_VirtualClient_RoboDK_Station.getJointsStr(

bExecute:=iStep=cStepGetJointsStr

,机器人名称:=Robot_name,关节=>strJoints

);

 

IF bWrite THEN

OPCUA_VirtualClient_RoboDK_Station.setJointsStr(

   bExecute:=TRUE

   ,Robot_name:=Robot_name,关节:=strJointsCommand);

END_IF;