eSUPS_PowerOK THEN //next cycles of powerfailure //skip regular code execution for the remaining cycles of the powerfailure/writing of persistent data/quick shutdown... RETURN; END_IF]]> '') THEN CHECK_UPS(); RESTORE_POSITIONS(); END_IF]]> 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 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 //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. afbReadEncRefSys[iAxes].Enable := FALSE; eStartUp := eReadAxisFeedbackType; 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 have .valid=TRUE for all axes eStartUp := eExecuteRestore; eExecuteRestore: //Execute position and encoder BIAS restore by setting Execute = TRUE FOR iAxes := 1 TO GVL_APP.nAXIS_NUM DO IF GVL.astAxes[iAxes].stConfig.eRestorePosition = E_RestorePosition.eRestoreWithoutHome THEN //Restore position value for incremental encoders IF NOT astAxesPersistent[iAxes].bMovingAtShutdown AND (afbReadEncRefSys[iAxes].Value = 0 OR afbReadEncRefSys[iAxes].Value = 2 OR afbReadEncRefSys[iAxes].Value = 4) THEN afbSetPosition[iAxes].Execute := TRUE; //Restore encoder position BIAS for absolute encoders ELSIF afbReadEncRefSys[iAxes].Value = 1 OR afbReadEncRefSys[iAxes].Value = 3 OR afbReadEncRefSys[iAxes].Value = 5 THEN afbWritePositionBias[iAxes].Execute := TRUE; END_IF ELSE RETURN; END_IF END_FOR eStartUp := eCheckRestore; eCheckRestore: //Check the set position and write enocder BIAS 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 GVL.astAxes[iAxes].stConfig.eRestorePosition = E_RestorePosition.eRestoreWithoutHome THEN IF NOT astAxesPersistent[iAxes].bMovingAtShutdown AND (afbReadEncRefSys[iAxes].Value = 0 OR afbReadEncRefSys[iAxes].Value = 2 OR afbReadEncRefSys[iAxes].Value = 4) THEN IF NOT afbSetPosition[iAxes].Done THEN afbSetPosition[iAxes].Execute := FALSE; eStartUp := eExecuteRestore; RETURN; END_IF ELSIF afbReadEncRefSys[iAxes].Value = 1 OR afbReadEncRefSys[iAxes].Value = 3 OR afbReadEncRefSys[iAxes].Value = 5 THEN IF NOT afbWritePositionBias[iAxes].Done THEN afbWritePositionBias[iAxes].Execute := FALSE; eStartUp := eExecuteRestore; RETURN; END_IF END_IF ELSE RETURN; END_IF END_FOR eStartUp := eFinishRestore; eFinishRestore: //Remove execute = TRUE for afbRestorePosition and fbWritePositionBias FOR iAxes := 1 TO GVL_APP.nAXIS_NUM DO afbSetPosition[iAxes].Execute := FALSE; afbWritePositionBias[iAxes].Execute := FALSE; bPositionRestoreDone := TRUE; bRestoreExecute := FALSE; END_FOR END_CASE END_IF]]>