Defining Main Program of the C2C Master Project

Description

The following steps are performed in the main program of the C2C Master project:

Step

Action

1

To use the Sercos encoder, the C2C Encoder Output object is connected to the Log. Encoder object using the function FC_SetMasterEncoder.

2

The axis state is verified.

If AxisState < 3, position control of the axis of the C2C Master (TTS1) and monitoring of the power supply of the C2C Master (TTS1) are enabled.

3

The synchronization state between C2C Master and the participating C2C Slave in the C2C network is verified.

If SyncGroupState = 5, the motion can be started.

4

The axis is moved using the YOffsetGenerator.

5

The user data received from the C2C Slave is copied to the data structure ST_MyData.

Defining SR_Main

Enter the following code in the SR_Main program of the C2C Master project:

PROGRAM SR_Main
VAR
   xSercosEncoderSetMasterEncoder: BOOL := TRUE;
   diSercEncSetMasterEncoderResult: DINT := 0;
   xSercosEncoderMotion : BOOL := TRUE;
   stMyData : ST_MyData;
   diDataCopyResult : DINT := 0;
   xEnableYOffsetGenerator : BOOL := TRUE;
END_VAR

IF xSercosEncoderSetMasterEncoder THEN
   //Connecting C2C Encoder Output (C2C_EncOut) with Logical encoder (LE_Enc)
   diSercEncSetMasterEncoderResult := SystemInterface.FC_SetMaster­Encoder(i_stLEncId:= C2C_EncOut.stLogicalAddress, i_stMasterId:= DRV_Lexium62.stLogicalAddress);
   xSercosEncoderSetMasterEncoder := FALSE;
END_IF

IF xSercosEncoderMotion THEN
// If the axis is not ready (AxisState < 3), enable position control for axis and monitoring for power supply.
   IF DRV_Lexium62.AxisState <3 THEN
      DRV_Lexium62.ControllerEnableSet := TRUE;
      PSM_Lexium62.PowerSupplyCheckSet := TRUE;
   ELSE
      // If SyncGroupState =5, then C2C network is synchronized.
      IF C2C_Master.SyncGroupState = 5 THEN
         // All C2C Slaves are synchronized, axis can be moved
         IF xEnableYOffsetGenerator = TRUE AND DRV_Lexium62.YOffsetState = 0 THEN
            DRV_Lexium62.YOffsetEnable := TRUE;
            xEnableYOffsetGenerator := FALSE;
         ELSE
            IF DRV_Lexium62.YOffsetState = 1 THEN
               DRV_Lexium62.YOffsetRefPosition := DRV_Lexium62.YOffsetRefPosition + 360;
               xSercosEncoderMotion := FALSE;
            END_IF
         END_IF
      END_IF
   END_IF
END_IF

// Copying input data (C2C Data input)
diDataCopyResult := FC_C2CDataCopy(i_stLogAddr:= C2C_DataIn.stLogica­lAddress, i_dwPointerToData:=ADR(stMyData) , i_uiDataLen:= SIZEOF(stMyData));