Format notes and correct indentation to MAIN.RESTORE_POSITION()

Format the comments about the reference system types
Correct wierd identation
Fix Format of if evaluation of boolean variables withouth the "= True or = False"
This commit is contained in:
Federico Rojas
2022-10-14 15:11:03 +02:00
parent 2d5075390a
commit 3c0a37a0e7
+34 -32
View File
@@ -55,7 +55,7 @@ END_FOR]]></ST>
FOR iAxes := 1 TO GVL_APP.nAXIS_NUM DO
//Read encoder position BIAS
IF astAxes[iAxes].stStatus.bAxisInitialized THEN
afbReadPositionBias[iAxes](Axis := GVL.astAxes[iAxes].Axis,
afbReadPositionBias[iAxes](Axis := GVL.astAxes[iAxes].Axis,
Enable := TRUE,
ReadMode:= READMODE_CYCLIC,
ParameterNumber := E_AxisParameters.AxisEncoderOffset);
@@ -101,9 +101,14 @@ END_IF]]></ST>
//0 'DontRestore'
//1 'RestoreWithoutHome' -restores the position using a set position fb and does not set the home bit in the axis struct.
//Note from Beckhoff: "A maximum of 1 MB persistent data can be reliably saved over the entire service life."
//Encoder Reference system types: INCREMENTAL=0; INCREMENTAL (singleturn absolute)=4;
// ABSOLUTE=1; ABSOLUTE MULTITURN RANGE (with single overflow)=3; ABSOLUTE SINGLETURN RANGE (with single overflow)=5;
// ABSOLUTE (modulo)=2;
//Encoder Reference system types: https://infosys.beckhoff.com/english.php?content=../content/1033/tf50x0_tc3_nc_ptp/3439907723.html&id=
//INCREMENTAL=0;
//ABSOLUTE=1;
//ABSOLUTE (modulo)=2;
//ABSOLUTE MULTITURN RANGE (with single overflow)=3;
//INCREMENTAL (singleturn absolute)=4;
//ABSOLUTE SINGLETURN RANGE (with single overflow)=5;
IF bRestoreOnStartup AND eGlobalSUpsState = eSUPS_PowerOK THEN
bRestoreOnStartup := FALSE;
@@ -117,44 +122,44 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
//Result stored in Value, 0=Inc 1=Abs, execute set during the case statement
FOR iAxes := 1 TO GVL_APP.nAXIS_NUM DO
afbReadEncRefSys[iAxes](
Axis := GVL.astAxes[iAxes].Axis,
Enable := bExecuteReadEncRefSys,
ParameterNumber := MC_AxisParameter.AxisEncoderReferenceSystem,
ReadMode := E_READMODE.READMODE_ONCE);
Axis := GVL.astAxes[iAxes].Axis,
Enable := bExecuteReadEncRefSys,
ParameterNumber := MC_AxisParameter.AxisEncoderReferenceSystem,
ReadMode := E_READMODE.READMODE_ONCE);
END_FOR
//Cycle through set position function blocks for each axis
FOR iAxes := 1 TO GVL_APP.nAXIS_NUM DO
afbRestorePosition[iAxes](
Axis := GVL.astAxes[iAxes].Axis,
Position := astAxesPersistent[iAxes].fPositionAtShutdown);
Axis := GVL.astAxes[iAxes].Axis,
Position := astAxesPersistent[iAxes].fPositionAtShutdown);
afbWritePositionBias[iAxes](
Axis:= GVL.astAxes[iAxes].Axis,
ParameterNumber:= E_AxisParameters.AxisEncoderOffset,
Value:= astAxesPersistent[iAxes].fBiasAtShutdown);
Axis:= GVL.astAxes[iAxes].Axis,
ParameterNumber:= E_AxisParameters.AxisEncoderOffset,
Value:= astAxesPersistent[iAxes].fBiasAtShutdown);
END_FOR
CASE eStartUp OF
eColdStart:
//First cycle of the PLC, do nothing just give one cycle for variables to initialise
//First cycle of the PLC, do nothing just give one cycle for variables to initialise
IF NOT bPositionRestoreDone THEN
eStartUp := eReadAxisFeedbackType;
nRetry := 0;
END_IF
eReadAxisFeedbackType:
//Exectute the function blocks to read the encoder reference system (0=inc OR 1=ABS)
//Exectute the function blocks to read the encoder reference system (0=inc OR 1=ABS)
bExecuteReadEncRefSys := TRUE;
eStartUp := eCheckReadDone;
eCheckReadDone:
//Check the encoder reference system has been read for all axis -> if busy then continue with PLC cycle and check again next time.
//If afbReadEncRefSys not started then go back a step.
//If any axes result in an error the code will get stuck here, this happens if GVL_APP.nAXIS_NUM is not set correctly
//Check the encoder reference system has been read for all axis -> if busy then continue with PLC cycle and check again next time.
//If afbReadEncRefSys not started then go back a step.
//If any axes result in an error the code will get stuck here, this happens if GVL_APP.nAXIS_NUM is not set correctly
FOR iAxes := 1 TO GVL_APP.nAXIS_NUM DO
IF afbReadEncRefSys[iAxes].Valid = FALSE THEN
IF afbReadEncRefSys[iAxes].Busy = TRUE THEN
IF NOT afbReadEncRefSys[iAxes].Valid THEN
IF afbReadEncRefSys[iAxes].Busy THEN
//Exit MAIN.STARTUP Action and wait till next cycle, needs to cycle through whole program in order for data to update
RETURN;
ELSE
@@ -168,35 +173,32 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
END_IF
END_IF
END_FOR
//If the code gets here all axes either have .valid=TRUE for all axes
//If the code gets here all axes have .valid=TRUE for all axes
eStartUp := eExecuteRestore;
eExecuteRestore:
//Execute position restore by setting afbRestorePosition.execute = TRUE
//Execute position restore by setting afbRestorePosition.execute = TRUE
FOR iAxes := 1 TO GVL_APP.nAXIS_NUM DO
//Restore position value for incremental encoders
IF afbReadEncRefSys[iAxes].Valid = TRUE AND NOT astAxesPersistent[iAxes].bMovingAtShutdown AND
(afbReadEncRefSys[iAxes].Value = 0 OR afbReadEncRefSys[iAxes].Value = 4 OR afbReadEncRefSys[iAxes].Value = 2) THEN
IF afbReadEncRefSys[iAxes].Valid AND NOT astAxesPersistent[iAxes].bMovingAtShutdown AND (afbReadEncRefSys[iAxes].Value = 0 OR afbReadEncRefSys[iAxes].Value = 4 OR afbReadEncRefSys[iAxes].Value = 2) THEN
IF GVL.astAxes[iAxes].stConfig.eRestorePosition = E_RestorePosition.eRestoreWithoutHome THEN
afbRestorePosition[iAxes].Execute := TRUE;
END_IF
//Restore encoder position BIAS for absolute encoders
ELSIF afbReadEncRefSys[iAxes].Valid = TRUE THEN
ELSIF afbReadEncRefSys[iAxes].Valid THEN
IF GVL.astAxes[iAxes].stConfig.eRestorePosition = E_RestorePosition.eRestoreWithoutHome THEN
afbWritePositionBias[iAxes].Execute := TRUE;
END_IF
END_IF
END_FOR
eStartUp := eCheckRestore;
eCheckRestore:
//Check the set position fbs are finished
//Nothing actually happens if the restore is not done, the code just returns from here each cycle and the
//bPositionRestoreDone will never get set to TRUE and will take up cycle time
//Check the set position fbs are finished
//Nothing actually happens if the restore is not done, the code just returns from here each cycle and the
//bPositionRestoreDone will never get set to TRUE and will take up cycle time
FOR iAxes := 1 TO GVL_APP.nAXIS_NUM DO
IF afbReadEncRefSys[iAxes].Valid = TRUE AND NOT astAxesPersistent[iAxes].bMovingAtShutdown AND
(afbReadEncRefSys[iAxes].Value = 0 OR afbReadEncRefSys[iAxes].Value = 4 OR afbReadEncRefSys[iAxes].Value = 2) THEN
IF afbReadEncRefSys[iAxes].Valid AND NOT astAxesPersistent[iAxes].bMovingAtShutdown AND (afbReadEncRefSys[iAxes].Value = 0 OR afbReadEncRefSys[iAxes].Value = 4 OR afbReadEncRefSys[iAxes].Value = 2) THEN
IF GVL.astAxes[iAxes].stConfig.eRestorePosition = E_RestorePosition.eRestoreWithoutHome THEN
IF NOT afbRestorePosition[iAxes].Done OR NOT afbWritePositionBias[iAxes].Done THEN
RETURN;
@@ -207,7 +209,7 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
eStartUp := eFinishRestore;
eFinishRestore:
//Remove execute = TRUE for afbRestorePosition
//Remove execute = TRUE for afbRestorePosition
FOR iAxes := 1 TO GVL_APP.nAXIS_NUM DO
afbRestorePosition[iAxes].Execute := FALSE;
afbWritePositionBias[iAxes].Execute := FALSE;