Delete local variable i in MAIN and substitute it with GVL.iAxis
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
<Declaration><![CDATA[PROGRAM MAIN
|
||||
VAR
|
||||
sVersion: STRING := '1.0.0';
|
||||
i: UINT; //index variable for the FOR cycle in action AXES()
|
||||
aFbAxes: ARRAY [1..gvl_app.nAxisNum] OF FB_Axis;
|
||||
hmiAxisSelection: INT := 1; //Not possible to use local hmi variables for array indexes
|
||||
|
||||
@@ -20,7 +19,7 @@ VAR
|
||||
//Startup, Shutdown and UPS
|
||||
fbUPS: FB_S_UPS_CX51x0;
|
||||
eUpsMode: E_S_UPS_Mode := eSUPS_WrPersistData_Shutdown;
|
||||
eStartUp: (eColdStart, eReadAxisFeedbackType, eCheckReadDone, eExecuteRestore, eCheckRestore, FinishRestore);
|
||||
eStartUp: (eColdStart, eReadAxisFeedbackType, eCheckReadDone, eExecuteRestore, eCheckRestore, eFinishRestore);
|
||||
bPositionRestoreDone: BOOL := FALSE;
|
||||
bRestoreExecute: BOOL := FALSE;
|
||||
bExecuteReadEncRefSys: BOOL := FALSE;
|
||||
@@ -49,17 +48,17 @@ END_FOR]]></ST>
|
||||
</Action>
|
||||
<Action Name="CHECK_UPS" Id="{f0f28f50-53b8-4f73-b0f5-6d7ce4c1636f}" FolderPath="POSITION_RECOVERY\">
|
||||
<Implementation>
|
||||
<ST><![CDATA[fbUPS(eUpsMode := eUpsMode); (* call UPS-FB instance in first lines of the fastest PLC Task *)
|
||||
<ST><![CDATA[fbUPS(eUpsMode := eUpsMode);
|
||||
|
||||
IF eGlobalSUpsState = eSUPS_PowerFailure THEN
|
||||
(* first cycle of powerfailure *)
|
||||
(* execute code that should only be done once with each powerfailure, i.e. increase powerfailure counter *)
|
||||
//first cycle of powerfailure
|
||||
//execute code that should only be done once with each powerfailure, i.e. increase powerfailure counter
|
||||
bRestoreOnStartup := TRUE;
|
||||
STORE_PERSISTENT();
|
||||
RETURN;
|
||||
ELSIF eGlobalSUpsState <> eSUPS_PowerOK THEN
|
||||
(* next cycles of powerfailure *)
|
||||
(* skip regular code execution for the remaining cycles of the powerfailure/writing of persistent data/quick shutdown ... *)
|
||||
//next cycles of powerfailure
|
||||
//skip regular code execution for the remaining cycles of the powerfailure/writing of persistent data/quick shutdown...
|
||||
RETURN;
|
||||
END_IF]]></ST>
|
||||
</Implementation>
|
||||
@@ -75,9 +74,7 @@ END_IF]]></ST>
|
||||
</Action>
|
||||
<Action Name="PROG" Id="{5d03ebbb-2a47-4890-ad6d-e82daf72dc51}">
|
||||
<Implementation>
|
||||
<ST><![CDATA[//
|
||||
(* Program any sequence, safety or feature (if necessary) application specific in thsi section*)
|
||||
//]]></ST>
|
||||
<ST><![CDATA[//Program any sequence, safety or feature (if necessary) application specific in thsi section]]></ST>
|
||||
</Implementation>
|
||||
</Action>
|
||||
<Action Name="RESTORE_POSITIONS" Id="{0c7ee537-7bd9-4833-b428-c17cbb57e893}" FolderPath="POSITION_RECOVERY\">
|
||||
@@ -86,7 +83,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.axes[i].config.eRestorePosition is non-zero.
|
||||
// By default an axis will not restore the position unless it is set to opt-in, i.e. gvl.axes[GVL.iAxis].config.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.
|
||||
@@ -105,9 +102,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 i:= 1 TO gvl_app.nAxisNum DO
|
||||
aFbReadEncRefSys[i](
|
||||
Axis := gvl.axes[i].Axis,
|
||||
FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
|
||||
aFbReadEncRefSys[GVL.iAxis](
|
||||
Axis := gvl.axes[GVL.iAxis].Axis,
|
||||
Enable := bExecuteReadEncRefSys,
|
||||
ParameterNumber := MC_AxisParameter.AxisEncoderReferenceSystem,
|
||||
Value=>,
|
||||
@@ -115,11 +112,11 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
|
||||
END_FOR
|
||||
|
||||
// Cycle through set position function blocks for each axis
|
||||
FOR i:= 1 TO gvl_app.nAxisNum DO
|
||||
aFbRestorePosition[i](
|
||||
Axis := gvl.axes[i].Axis,
|
||||
FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
|
||||
aFbRestorePosition[GVL.iAxis](
|
||||
Axis := gvl.axes[GVL.iAxis].Axis,
|
||||
Execute := ,
|
||||
Position := axesPersistent[i].iPositionAtShutdown);
|
||||
Position := axesPersistent[GVL.iAxis].iPositionAtShutdown);
|
||||
END_FOR
|
||||
|
||||
CASE eStartUp OF
|
||||
@@ -139,13 +136,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 i:= 1 TO gvl_app.nAxisNum DO
|
||||
IF aFbReadEncRefSys[i].Valid = FALSE THEN
|
||||
IF aFbReadEncRefSys[i].Busy = TRUE THEN
|
||||
FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
|
||||
IF aFbReadEncRefSys[GVL.iAxis].Valid = FALSE THEN
|
||||
IF aFbReadEncRefSys[GVL.iAxis].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[i] misses the rising edge. If the code gets here it means
|
||||
// Sometimes the code gets here and the aFbReadEncRefSys[GVL.iAxis] 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;
|
||||
@@ -160,10 +157,10 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
|
||||
|
||||
eExecuteRestore:
|
||||
// Execute position restore by setting aFbRestorePosition.execute = TRUE
|
||||
FOR i:= 1 TO gvl_app.nAxisNum DO
|
||||
IF aFbReadEncRefSys[i].Valid = TRUE AND aFbReadEncRefSys[i].Value = 0 AND NOT(axesPersistent[i].bMovingAtShutdown) THEN
|
||||
IF GVL.axes[i].config.eRestorePosition = RestorePosition.RestoreWithoutHome THEN
|
||||
aFbRestorePosition[i].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(axesPersistent[GVL.iAxis].bMovingAtShutdown) THEN
|
||||
IF GVL.axes[GVL.iAxis].config.eRestorePosition = RestorePosition.RestoreWithoutHome THEN
|
||||
aFbRestorePosition[GVL.iAxis].Execute := TRUE;
|
||||
END_IF
|
||||
END_IF
|
||||
END_FOR
|
||||
@@ -173,21 +170,21 @@ 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 i:= 1 TO gvl_app.nAxisNum DO
|
||||
IF aFbReadEncRefSys[i].Valid = TRUE AND aFbReadEncRefSys[i].Value = 0 AND NOT(axesPersistent[i].bMovingAtShutdown) THEN
|
||||
IF GVL.axes[i].config.eRestorePosition = RestorePosition.RestoreWithoutHome THEN
|
||||
IF NOT aFbRestorePosition[i].Done THEN
|
||||
FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
|
||||
IF aFbReadEncRefSys[GVL.iAxis].Valid = TRUE AND aFbReadEncRefSys[GVL.iAxis].Value = 0 AND NOT(axesPersistent[GVL.iAxis].bMovingAtShutdown) THEN
|
||||
IF GVL.axes[GVL.iAxis].config.eRestorePosition = RestorePosition.RestoreWithoutHome THEN
|
||||
IF NOT aFbRestorePosition[GVL.iAxis].Done THEN
|
||||
RETURN;
|
||||
END_IF
|
||||
END_IF
|
||||
END_IF
|
||||
END_FOR
|
||||
eStartUp := FinishRestore;
|
||||
eStartUp := eFinishRestore;
|
||||
|
||||
FinishRestore:
|
||||
eFinishRestore:
|
||||
// Remove execute = TRUE for aFbRestorePosition
|
||||
FOR i:= 1 TO gvl_app.nAxisNum DO
|
||||
aFbRestorePosition[i].Execute := FALSE;
|
||||
FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
|
||||
aFbRestorePosition[GVL.iAxis].Execute := FALSE;
|
||||
END_FOR
|
||||
bPositionRestoreDone := TRUE;
|
||||
bRestoreExecute := FALSE;
|
||||
@@ -197,14 +194,14 @@ END_IF]]></ST>
|
||||
</Action>
|
||||
<Action Name="STORE_PERSISTENT" Id="{cb5c9254-2e5f-47b1-9baa-10e728a961b0}" FolderPath="POSITION_RECOVERY\">
|
||||
<Implementation>
|
||||
<ST><![CDATA[FOR i:= 1 TO gvl_app.nAxisNum DO
|
||||
axesPersistent[i].iPositionAtShutdown := gvl.axes[i].Axis.NcToPlc.ActPos;
|
||||
IF gvl.axes[i].Axis.NcToPlc.ActVelo <> 0 THEN
|
||||
axesPersistent[i].bMovingAtShutdown := TRUE;
|
||||
<ST><![CDATA[FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
|
||||
axesPersistent[GVL.iAxis].iPositionAtShutdown := gvl.axes[GVL.iAxis].Axis.NcToPlc.ActPos;
|
||||
IF gvl.axes[GVL.iAxis].Axis.NcToPlc.ActVelo <> 0 THEN
|
||||
axesPersistent[GVL.iAxis].bMovingAtShutdown := TRUE;
|
||||
ELSE
|
||||
axesPersistent[i].bMovingAtShutdown := FALSE;
|
||||
axesPersistent[GVL.iAxis].bMovingAtShutdown := FALSE;
|
||||
END_IF
|
||||
axesPersistent[i].bMovingAtShutdown := axesPersistent[i].bMovingAtShutdown OR gvl.axes[i].Axis.Status.Moving;
|
||||
axesPersistent[GVL.iAxis].bMovingAtShutdown := axesPersistent[GVL.iAxis].bMovingAtShutdown OR gvl.axes[GVL.iAxis].Axis.Status.Moving;
|
||||
END_FOR]]></ST>
|
||||
</Implementation>
|
||||
</Action>
|
||||
@@ -228,8 +225,6 @@ END_FOR]]></ST>
|
||||
</LineIds>
|
||||
<LineIds Name="MAIN.PROG">
|
||||
<LineId Id="2" Count="0" />
|
||||
<LineId Id="1" Count="0" />
|
||||
<LineId Id="3" Count="0" />
|
||||
</LineIds>
|
||||
<LineIds Name="MAIN.RESTORE_POSITIONS">
|
||||
<LineId Id="99" Count="0" />
|
||||
|
||||
Reference in New Issue
Block a user