From 68498ae44fc1f25bf5eae0f03b7037156e28dd16 Mon Sep 17 00:00:00 2001 From: Federico Rojas Date: Tue, 17 Mar 2020 13:33:21 +0100 Subject: [PATCH] Delete local variable i in MAIN and substitute it with GVL.iAxis --- solution/tc_project_app/POUs/MAIN.TcPOU | 79 ++++++++++++------------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/solution/tc_project_app/POUs/MAIN.TcPOU b/solution/tc_project_app/POUs/MAIN.TcPOU index 09c49f9..58591cd 100644 --- a/solution/tc_project_app/POUs/MAIN.TcPOU +++ b/solution/tc_project_app/POUs/MAIN.TcPOU @@ -4,7 +4,6 @@ - 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]]> @@ -75,9 +74,7 @@ END_IF]]> - + @@ -86,7 +83,7 @@ END_IF]]> // 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]]> - 0 THEN - axesPersistent[i].bMovingAtShutdown := TRUE; + 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]]> @@ -228,8 +225,6 @@ END_FOR]]> - -