Changed FB_Axis and refernces to follow code standards

This commit is contained in:
Federico Rojas
2020-03-18 17:05:52 +01:00
parent 47199a6a16
commit c4c2fdc0f3
2 changed files with 30 additions and 29 deletions
+29 -28
View File
@@ -24,6 +24,7 @@ VAR
bRestoreExecute: BOOL := FALSE;
bExecuteReadEncRefSys: BOOL := FALSE;
nRetry: INT;
iAxes : UINT; //index for for loops in Position recovery actions
aFbReadEncRefSys: ARRAY [1..gvl_app.nAxisNum] OF MC_ReadParameter;
aFbRestorePosition: ARRAY [1..GVL_app.nAxisNum] OF MC_SetPosition;
fbGetDeviceIdentification: FB_GetDeviceIdentification;
@@ -83,7 +84,7 @@ END_IF]]></ST>
// This ACT will restore the position of an incremental axis on startup with the act position it read before losing power.
// It checks the type of axis, 0=incremental, and that the axis was stationary at shut down.
// Because 0 equates to incremental we also need to check that the data is valid, otherwise by default it would restore all axes.
// By default an axis will not restore the position unless it is set to opt-in, i.e. gvl.aAxes[GVL.iAxis].stConfig.eRestorePosition is non-zero.
// By default an axis will not restore the position unless it is set to opt-in, i.e. gvl.aAxes[iAxes].stConfig.eRestorePosition is non-zero.
// This needs to be initialised somewhere in TwinCAT code otherwise it will not be available at start up.
// A restore will only be performed on a loss of power, this code shouldn't make any changes on a reset cold, a rest origin or a download.
// There is a enum to allow for different types of restore modes, currently only one is implemented.
@@ -102,9 +103,9 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
// Cycle through function blocks that read the encoder reference system i.e. whether axis is incremental or absolute
// Result stored in Value, 0=Inc 1=Abs, execute set during the case statement
FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
aFbReadEncRefSys[GVL.iAxis](
Axis := gvl.aAxes[GVL.iAxis].Axis,
FOR iAxes:= 1 TO gvl_app.nAxisNum DO
aFbReadEncRefSys[iAxes](
Axis := gvl.aAxes[iAxes].Axis,
Enable := bExecuteReadEncRefSys,
ParameterNumber := MC_AxisParameter.AxisEncoderReferenceSystem,
Value=>,
@@ -112,11 +113,11 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
END_FOR
// Cycle through set position function blocks for each axis
FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
aFbRestorePosition[GVL.iAxis](
Axis := gvl.aAxes[GVL.iAxis].Axis,
FOR iAxes:= 1 TO gvl_app.nAxisNum DO
aFbRestorePosition[iAxes](
Axis := gvl.aAxes[iAxes].Axis,
Execute := ,
Position := aAxesPersistent[GVL.iAxis].fPositionAtShutdown);
Position := aAxesPersistent[iAxes].fPositionAtShutdown);
END_FOR
CASE eStartUp OF
@@ -136,13 +137,13 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
// 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.nAxisNum is not set correctly
FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
IF aFbReadEncRefSys[GVL.iAxis].Valid = FALSE THEN
IF aFbReadEncRefSys[GVL.iAxis].Busy = TRUE THEN
FOR iAxes:= 1 TO gvl_app.nAxisNum DO
IF aFbReadEncRefSys[iAxes].Valid = FALSE THEN
IF aFbReadEncRefSys[iAxes].Busy = TRUE THEN
// Exit MAIN.STARTUP Action and wait till next cycle, needs to cycle through whole program in order for data to update
RETURN;
ELSE
// Sometimes the code gets here and the aFbReadEncRefSys[GVL.iAxis] misses the rising edge. If the code gets here it means
// Sometimes the code gets here and the aFbReadEncRefSys[iAxes] misses the rising edge. If the code gets here it means
// .valid=FALSE and .busy=FALSE which indicateds the FB probably hasn't started and thus needs to see a rising edge.
// Set execute to low, Exit MAIN.STARTUP and go back a step in the CASE statement.
bExecuteReadEncRefSys := FALSE;
@@ -157,10 +158,10 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
eExecuteRestore:
// Execute position restore by setting aFbRestorePosition.execute = TRUE
FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
IF aFbReadEncRefSys[GVL.iAxis].Valid = TRUE AND aFbReadEncRefSys[GVL.iAxis].Value = 0 AND NOT(aAxesPersistent[GVL.iAxis].bMovingAtShutdown) THEN
IF GVL.aAxes[GVL.iAxis].stConfig.eRestorePosition = E_RestorePosition.RestoreWithoutHome THEN
aFbRestorePosition[GVL.iAxis].Execute := TRUE;
FOR iAxes:= 1 TO gvl_app.nAxisNum DO
IF aFbReadEncRefSys[iAxes].Valid = TRUE AND aFbReadEncRefSys[iAxes].Value = 0 AND NOT(aAxesPersistent[iAxes].bMovingAtShutdown) THEN
IF GVL.aAxes[iAxes].stConfig.eRestorePosition = E_RestorePosition.RestoreWithoutHome THEN
aFbRestorePosition[iAxes].Execute := TRUE;
END_IF
END_IF
END_FOR
@@ -170,10 +171,10 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
// 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 GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
IF aFbReadEncRefSys[GVL.iAxis].Valid = TRUE AND aFbReadEncRefSys[GVL.iAxis].Value = 0 AND NOT(aAxesPersistent[GVL.iAxis].bMovingAtShutdown) THEN
IF GVL.aAxes[GVL.iAxis].stConfig.eRestorePosition = E_RestorePosition.RestoreWithoutHome THEN
IF NOT aFbRestorePosition[GVL.iAxis].Done THEN
FOR iAxes:= 1 TO gvl_app.nAxisNum DO
IF aFbReadEncRefSys[iAxes].Valid = TRUE AND aFbReadEncRefSys[iAxes].Value = 0 AND NOT(aAxesPersistent[iAxes].bMovingAtShutdown) THEN
IF GVL.aAxes[iAxes].stConfig.eRestorePosition = E_RestorePosition.RestoreWithoutHome THEN
IF NOT aFbRestorePosition[iAxes].Done THEN
RETURN;
END_IF
END_IF
@@ -183,8 +184,8 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
eFinishRestore:
// Remove execute = TRUE for aFbRestorePosition
FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
aFbRestorePosition[GVL.iAxis].Execute := FALSE;
FOR iAxes:= 1 TO gvl_app.nAxisNum DO
aFbRestorePosition[iAxes].Execute := FALSE;
END_FOR
bPositionRestoreDone := TRUE;
bRestoreExecute := FALSE;
@@ -194,14 +195,14 @@ END_IF]]></ST>
</Action>
<Action Name="STORE_PERSISTENT" Id="{cb5c9254-2e5f-47b1-9baa-10e728a961b0}" FolderPath="POSITION_RECOVERY\">
<Implementation>
<ST><![CDATA[FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
aAxesPersistent[GVL.iAxis].fPositionAtShutdown := gvl.aAxes[GVL.iAxis].Axis.NcToPlc.ActPos;
IF gvl.aAxes[GVL.iAxis].Axis.NcToPlc.ActVelo <> 0 THEN
aAxesPersistent[GVL.iAxis].bMovingAtShutdown := TRUE;
<ST><![CDATA[FOR iAxes:= 1 TO gvl_app.nAxisNum DO
aAxesPersistent[iAxes].fPositionAtShutdown := gvl.aAxes[iAxes].Axis.NcToPlc.ActPos;
IF gvl.aAxes[iAxes].Axis.NcToPlc.ActVelo <> 0 THEN
aAxesPersistent[iAxes].bMovingAtShutdown := TRUE;
ELSE
aAxesPersistent[GVL.iAxis].bMovingAtShutdown := FALSE;
aAxesPersistent[iAxes].bMovingAtShutdown := FALSE;
END_IF
aAxesPersistent[GVL.iAxis].bMovingAtShutdown := aAxesPersistent[GVL.iAxis].bMovingAtShutdown OR gvl.aAxes[GVL.iAxis].Axis.Status.Moving;
aAxesPersistent[iAxes].bMovingAtShutdown := aAxesPersistent[iAxes].bMovingAtShutdown OR gvl.aAxes[iAxes].Axis.Status.Moving;
END_FOR]]></ST>
</Implementation>
</Action>