Implementierung mit Beckhoff TwinCAT 3

Sie können die Beckhoff TwinCAT 3 Software verwenden, um die Konnektivität mit dem RoboDK OPC UA Server zu testen.

TwinCAT3 Server hinzufügen

Sie können damit beginnen, den OPC UA Client zu erstellen, indem Sie E/A>Geräte>Neues Element hinzufügen wählen.

OPC UA - Bild 48

Wählen Sie Virtuelles OPC UA-Gerät aus OPC >OK.

OPC UA - Bild 49

OPC UA Virtual wird eingefügt.

OPC UA - Bild 50

Wir müssen einen OPC UA Client hinzufügen, um auf den RoboDK OPC UA Server zuzugreifen.

Wählen Sie Gerät 1 >Rechtsklick >Neues Element hinzufügen.

OPC UA - Bild 51

Wählen Sie "OPC UA Client(Modul)" und Ok.

OPC UA - Bild 52

OPC UA Client wird eingefügt.

OPC UA - Bild 53

Konfigurieren Sie den Server

Öffnen Sie den OPC UA Client > gehen Sie auf die Registerkarte "Einstellungen" > klicken Sie auf "Endpunkt auswählen", um den OPC UA Server Endpunkt zu konfigurieren, auf den Sie zugreifen möchten.

OPC UA - Bild 54

Geben Sie die RoboDK OPC UA Server URL ein und aktualisieren Sie sie.

OPC UA - Bild 55

RoboDK Server Methode

Klicken Sie auf "Knoten hinzufügen", um den Knoten zu suchen, der sich im OPC UA Server befindet.

OPC UA - Bild 56

Wenn die Verbindung zwischen TwinCAT und dem OPC UA Server hergestellt ist, können Sie die Details des OPC UA Servers durchsuchen.

OPC UA - Bild 57

Wählen Sie alle Methoden und Ok.

OPC UA - Bild 58

Methoden werden in Ihre Konfiguration eingefügt.

OPC UA - Bild 59

RoboDK-Methode automatisch generieren

Konfigurieren Sie Ihr Namenspräfix in diesem Feld.

OPC UA - Bild 60

Klicken Sie auf "Create Plc Code", um den SPS-Code aus TwinCAT zu erstellen.

OPC UA - Bild 61

In Ihrem Projekt wird ein OpcUaClient-Ordner erstellt, und alle RoboDK-Methoden werden im IEC61131-3 Funktionsblockformat erstellt.

OPC UA - Bild 62

PLC Programm Beispiel

Dieser Abschnitt zeigt ein Beispielprogramm für eine Beckhoff TwinCAT SPS, die mit dem RoboDK OPC UA Server kommuniziert.

PROGRAMM HAUPT

VAR

   bConnected      :BOOL;

   StationPointer  :DINT;

   iStep           :INT;

   bStart          :BOOL;;

   i               :INT;

   TON             :TON;

   bReset          :BOOL;

   bWrite          :BOOL;

   TON2            :TON;

   bShow           :BOOL:=TRUE;

   bVis            :BOOL:=True;

END_VAR

 

VAR

   Roboter_name          :STRING(80):='ABB_RB1';

   Artikel_ID      :ULINT;

   arrJoints       :ARRAY[0..11]OF LREAL;

   strJoints       :STRING(80):='';

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

   sTrennzeichen   :STRING(1) := ',';

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

   strJointsCommand:STRING(80);

END_VAR

 

VAR KONSTANTE

   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;

        debuggen        :BOOL;

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

END_VAR

bConnected:=OPCUA_VirtualClient_RoboDK_Station.bConnected;

 

CASE 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]:='';

        END_FOR

        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

              DANN

              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

              DANN

              iStep:=cStepGetJoints;

        END_IF

   cStepGetJoints:

 

        IF OPCUA_VirtualClient_RoboDK_Station.getJoints.bDone

              AND NOT OPCUA_VirtualClient_RoboDK_Station.getJoints.bBusy

              DANN

              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

       

              DANN

              iStep:=cStepGetJointsStr;

        END_IF;

       

   cStepGetJointsStr:

 

        IF OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bDone

              AND NOT OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bBusy

              DANN

              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

              DANN

                   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:

 

       

        WENN (

        OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bDone

              UND NICHT   

        OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bBusy

         )

              OR NOT bWrite

              DANN

              iStep:=cStepSetJointsStrReset;

        ELSIF OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bError           

          DANN

              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

              DANN

              iStep:=cStepEnd;

        END_IF;

       

   cStepEnd:

        TON(IN:=TRUE,PT:=T#0.1S);

        IF TON.Q THEN

              TON(IN:=FALSE);

              IF NOT debug THEN

                   iSchritt:=10;

              ELSE

                   iStep:=cStepSetJointStrDelay;

              END_IF;

        END_IF

       

   cStepGetItemError:

        Artikel_ID:=0;

        iStep:=cStepWaitReset;

  

   cStepGetJointsError:

        FOR i :=0 TO 11 DO

              arrJoints[i]:=-99999.99;

        END_FOR

        iStep:=cStepWaitReset;

       

   cStepGetJointsStrError:

        strJoints:='';

        iStep:=cStepWaitReset;

       

   cStepWaitReset:

        IF bReset THEN

              iStep:=cStepInit;

              bReset:=FALSE;

        END_IF;   

END_CASE

 

aSplit[1] := strJoints;

 

FOR i:=1 TO 7 DO

    bResultSplit := FindAndSplit(

   pTrennzeichen := ADR(sTrennzeichen)

   ,pSrcString := ADR(aSplit[i])

   ,pLeftString:= ADR(aSplit[i])

   ,nLinksGröße := SIZEOF(aSplit[i])

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

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

   ,bSearchFromRight := FALSE );

    IF NOT bResultSplit THEN

        EXIT;

    END_IF

END_FOR

 

FOR i :=1 BIS 6 DO

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

END_FOR;

 

//

OPCUA_VirtualClient_RoboDK_Station.getItem(

bAusführen:=iStep=cStepGetItem

Artikel_Name:=Roboter_name

);

 

 

OPCUA_VirtualClient_RoboDK_Station.getJoints(

bAusführen:=iStep=cStepGetJoints

,Item_ID:=Item_ID,Joints=>arrJoints

);

 

 

OPCUA_VirtualClient_RoboDK_Station.getJointsStr(

bAusführen:=iStep=cStepGetJointsStr

,Roboter_name:=Roboter_name,Verbindungen=>strJoints

);

 

IF bSchreiben THEN

OPCUA_VirtualClient_RoboDK_Station.setJointsStr(

   bAusführen:=TRUE

,Roboter_name:=Roboter_name,Joints:=strJointsCommand);

END_IF;