Delete space after // from restor position actions
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<Declaration><![CDATA[PROGRAM MAIN
|
||||
VAR
|
||||
sVersion: STRING := '1.0.0';
|
||||
afbAxes: ARRAY [1..gvl_app.nAxisNum] OF FB_Axis;
|
||||
afbAxes: ARRAY [1..GVL_APP.nAxisNum] OF FB_Axis;
|
||||
hmiAxisSelection: INT := 1; //Not possible to use local hmi variables for array indexes
|
||||
|
||||
//Outputs: Power for Limit switches and Home Sensors (every 4th output)
|
||||
@@ -25,8 +25,8 @@ VAR
|
||||
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;
|
||||
afbReadEncRefSys: ARRAY [1..GVL_APP.nAxisNum] OF MC_ReadParameter;
|
||||
afbRestorePosition: ARRAY [1..GVL_APP.nAxisNum] OF MC_SetPosition;
|
||||
fbGetDeviceIdentification: FB_GetDeviceIdentification;
|
||||
|
||||
END_VAR
|
||||
@@ -42,7 +42,7 @@ AXES();]]></ST>
|
||||
<Folder Name="POSITION_RECOVERY" Id="{3561f6ef-e145-4ed3-9839-f17334bd2d97}" />
|
||||
<Action Name="AXES" Id="{7eb32732-9b53-4934-8cd9-20ba971dd8ff}">
|
||||
<Implementation>
|
||||
<ST><;
|
||||
END_FOR]]></ST>
|
||||
</Implementation>
|
||||
@@ -81,84 +81,81 @@ END_IF]]></ST>
|
||||
<Action Name="RESTORE_POSITIONS" Id="{0c7ee537-7bd9-4833-b428-c17cbb57e893}" FolderPath="POSITION_RECOVERY\">
|
||||
<Implementation>
|
||||
<ST><![CDATA[
|
||||
// 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[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.
|
||||
// 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."
|
||||
//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[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.
|
||||
//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."
|
||||
|
||||
IF bRestoreOnStartup AND eGlobalSUpsState = eSUPS_PowerOK THEN
|
||||
bRestoreOnStartup := FALSE;
|
||||
bRestoreExecute := TRUE;
|
||||
END_IF
|
||||
|
||||
// Upon startup bPositionRestoreDone will be set to FALSE, after successfully completing the following code it will be set TRUE
|
||||
// and should stay TRUE for the rest of the time the PLC is operational, thus this routine should only be completed once.
|
||||
//Upon startup bPositionRestoreDone will be set to FALSE, after successfully completing the following code it will be set TRUE
|
||||
//and should stay TRUE for the rest of the time the PLC is operational, thus this routine should only be completed once.
|
||||
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 iAxes:= 1 TO gvl_app.nAxisNum DO
|
||||
//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 iAxes := 1 TO GVL_APP.nAxisNum DO
|
||||
afbReadEncRefSys[iAxes](
|
||||
Axis := GVL.aAxes[iAxes].Axis,
|
||||
Enable := bExecuteReadEncRefSys,
|
||||
ParameterNumber := MC_AxisParameter.AxisEncoderReferenceSystem,
|
||||
Value=>,
|
||||
ReadMode := E_READMODE.READMODE_ONCE);
|
||||
END_FOR
|
||||
|
||||
// Cycle through set position function blocks for each axis
|
||||
FOR iAxes:= 1 TO gvl_app.nAxisNum DO
|
||||
//Cycle through set position function blocks for each axis
|
||||
FOR iAxes := 1 TO GVL_APP.nAxisNum DO
|
||||
afbRestorePosition[iAxes](
|
||||
Axis := GVL.aAxes[iAxes].Axis,
|
||||
Execute := ,
|
||||
Position := aAxesPersistent[iAxes].fPositionAtShutdown);
|
||||
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.nAxisNum is not set correctly
|
||||
FOR iAxes:= 1 TO gvl_app.nAxisNum DO
|
||||
//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 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
|
||||
//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[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.
|
||||
//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;
|
||||
eStartUp := eReadAxisFeedbackType;
|
||||
nRetry := nRetry+1; // counter used for troubleshooting to see how many cycles it takes before afbReadEncRefSys function blocks are read correctly
|
||||
nRetry := nRetry + 1; //counter used for troubleshooting to see how many cycles it takes before afbReadEncRefSys function blocks are read correctly
|
||||
RETURN;
|
||||
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 either have .valid=TRUE for all axes
|
||||
eStartUp := eExecuteRestore;
|
||||
|
||||
eExecuteRestore:
|
||||
// Execute position restore by setting afbRestorePosition.execute = TRUE
|
||||
FOR iAxes:= 1 TO gvl_app.nAxisNum DO
|
||||
//Execute position restore by setting afbRestorePosition.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;
|
||||
@@ -168,10 +165,10 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
|
||||
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
|
||||
FOR iAxes:= 1 TO gvl_app.nAxisNum DO
|
||||
//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.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
|
||||
@@ -183,8 +180,8 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
|
||||
eStartUp := eFinishRestore;
|
||||
|
||||
eFinishRestore:
|
||||
// Remove execute = TRUE for afbRestorePosition
|
||||
FOR iAxes:= 1 TO gvl_app.nAxisNum DO
|
||||
//Remove execute = TRUE for afbRestorePosition
|
||||
FOR iAxes := 1 TO GVL_APP.nAxisNum DO
|
||||
afbRestorePosition[iAxes].Execute := FALSE;
|
||||
END_FOR
|
||||
bPositionRestoreDone := TRUE;
|
||||
@@ -195,7 +192,7 @@ END_IF]]></ST>
|
||||
</Action>
|
||||
<Action Name="STORE_PERSISTENT" Id="{cb5c9254-2e5f-47b1-9baa-10e728a961b0}" FolderPath="POSITION_RECOVERY\">
|
||||
<Implementation>
|
||||
<ST><![CDATA[FOR iAxes:= 1 TO gvl_app.nAxisNum DO
|
||||
<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;
|
||||
@@ -228,7 +225,10 @@ END_FOR]]></ST>
|
||||
<LineId Id="2" Count="0" />
|
||||
</LineIds>
|
||||
<LineIds Name="MAIN.RESTORE_POSITIONS">
|
||||
<LineId Id="242" Count="109" />
|
||||
<LineId Id="242" Count="19" />
|
||||
<LineId Id="263" Count="6" />
|
||||
<LineId Id="271" Count="6" />
|
||||
<LineId Id="279" Count="72" />
|
||||
<LineId Id="1" Count="0" />
|
||||
</LineIds>
|
||||
<LineIds Name="MAIN.STORE_PERSISTENT">
|
||||
|
||||
Reference in New Issue
Block a user