Defining Main Program of the C2C Master Project

Description

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

Step

Action

1

To use the Sercos encoder, the C2C Encoder Input 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 Slave (TTS2) and monitoring of the power supply of the C2C Slave (TTS2) are enabled.

  • If AxisState >= 3, the function block FB_MultiCam is started.

3

Then the axis of the C2C Slave (TTS2) is moved with a simple linear profile and the function block FB_MultiCam.

Defining SR_Main

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

PROGRAM SR_Main
VAR
   xSercosEncoderSetMasterEncoder: BOOL := TRUE;
   diSercEncSetMasterEncoderResult: DINT := 0;
   stSercosEncoderMultiCamData: PDL .ST_MultiCam;
   stSercosEncoderMultiCamDataExt: PDL.ST_MultiCamExt;
   fbMultiCam: PDL.FB_MultiCam;
   xSercosEncoderMotion : BOOL := TRUE;
   xSercEncEnable: BOOL := TRUE;
   xSercEncStart: BOOL := FALSE;
   xSercEncNewCam: BOOL := FALSE;
   xSercEncInstantNewCam: BOOL := FALSE;
   stMyData : ST_MyData;
   diDataCopyResult : DINT := 0;
END_VAR
IF xSercosEncoderSetMasterEncoder THEN
//Connecting C2C Encoder Input (C2C_EncIn) with Logical encoder (LE_Enc)
   diSercEncSetMasterEncoderResult := SystemInterface.FC_SetMasterEncoder(i_stLEncId:= LE_Enc.stLogicalAddress, i_stMasterId:= C2C_EncIn.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;
   // Disable FB_MultiCam.
      xSercEncEnable := FALSE;
      xSercEncStart := FALSE;
   ELSE
   // If the axis is ready and follows the reference values (AxisState >= 3), enable and start FB_Multicam
      xSercEncEnable := TRUE;
      xSercEncStart := TRUE;
   END_IF
   //Setting inputs, inputs/outputs and outputs of FB_MultiCam   fbMultiCam(
   i_xEnable:= xSercEncEnable,
   i_ifDrive:= DRV_Lexium62,
   i_xStart:= xSercEncStart,
   i_xWsSelect:= FALSE,
   i_etCsModeSlave:= PDL.ET_MultiCamCsModeSlave.SetSlavePositionToFirstCamPosition,
   i_etCsModeMaster:= PDL.ET_MultiCamCsModeMaster.SetMasterPositionToFirstCamPosition,
   i_etWsMode:= PDL.ET_MultiCamWsMode.NewCamMoveAlwaysNoPositionCheck,
   i_lrWsWindow:= 360.0,
   i_lrWsVel:= 100.0,
   i_lrWsAcc:= 1000.0,
   i_lrWsJerk:= 1000.0,
   i_xWsStart:= FALSE,
   i_diTXEnd:= 0,
   i_lrInstantXLimMax:= 400.0,
   iq_lencMaster:= LE_Enc,
   iq_stExt:= stSercosEncoderMultiCamDataExt,
   iq_xNewCam:= xSercEncNewCam,
   iq_xInstantNewCam:= xSercEncInstantNewCam,
   iq_stMultiCamData:= stSercosEncoderMultiCamDataOut,
   q_xActive=> ,
   q_xReady=> ,
   q_etDiag=> ,
   q_etDiagExt=> ,
   q_sMsg=> ,
   q_xInWsWindow=> ,
   q_xSynActive=> ,
   q_lrPositionX=> ,
   q_lrPositionY=> ,
   q_xXLowEnd=> ,
   q_xXHighEnd=> ,
   q_stActualCamData=> );
END_IF