diff --git a/solution/_Config/PLC/tc_project_app.xti b/solution/_Config/PLC/tc_project_app.xti index 30060c1..e29aaf0 100644 --- a/solution/_Config/PLC/tc_project_app.xti +++ b/solution/_Config/PLC/tc_project_app.xti @@ -1,7 +1,7 @@ - + tc_project_app Instance {08500001-0000-0000-F000-000000000064} diff --git a/solution/solution.tsproj b/solution/solution.tsproj index f495754..44582e8 100644 --- a/solution/solution.tsproj +++ b/solution/solution.tsproj @@ -18,5 +18,9 @@ + + + + diff --git a/solution/tc_project_app/POUs/MAIN.TcPOU b/solution/tc_project_app/POUs/MAIN.TcPOU index dfb07a0..2c2978f 100644 --- a/solution/tc_project_app/POUs/MAIN.TcPOU +++ b/solution/tc_project_app/POUs/MAIN.TcPOU @@ -20,8 +20,8 @@ VAR afbReadEncRefSys: ARRAY [1..GVL_APP.nAXIS_NUM] OF MC_ReadParameter; afbRestorePosition: ARRAY [1..GVL_APP.nAXIS_NUM] OF MC_SetPosition; afbReadPositionBias: ARRAY [1..GVL_APP.nAXIS_NUM] OF MC_ReadParameter; - afbWritePositionBias: ARRAY [1..GVL_APP.nAXIS_NUM] OF MC_WriteParameter; - fbGetDeviceIdentification: FB_GetDeviceIdentificationEx; + afbWritePositionBias: ARRAY [1..GVL_APP.nAXIS_NUM] OF MC_WriteParameter; + fbGetDeviceIdentification: FB_GetDeviceIdentificationEx; END_VAR VAR PERSISTENT @@ -53,13 +53,13 @@ END_FOR]]> //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." -//Encoder Reference system types: INCREMENTAL=0; INCREMENTAL (singleturn absolute)=4; -// ABSOLUTE=1; ABSOLUTE MULTITURN RANGE (with single overflow)=3; ABSOLUTE SINGLETURN RANGE (with single overflow)=5; -// ABSOLUTE (modulo)=2; +//Encoder Reference system types: INCREMENTAL=0; INCREMENTAL (singleturn absolute)=4; +// ABSOLUTE=1; ABSOLUTE MULTITURN RANGE (with single overflow)=3; ABSOLUTE SINGLETURN RANGE (with single overflow)=5; +// ABSOLUTE (modulo)=2; IF bRestoreOnStartup AND eGlobalSUpsState = eSUPS_PowerOK THEN bRestoreOnStartup := FALSE; @@ -128,11 +128,11 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN afbRestorePosition[iAxes]( Axis := GVL.astAxes[iAxes].Axis, Position := astAxesPersistent[iAxes].fPositionAtShutdown); - - afbWritePositionBias[iAxes]( - Axis:= GVL.astAxes[iAxes].Axis, - ParameterNumber:= E_AxisParameters.AxisEncoderOffset, - Value:= astAxesPersistent[iAxes].fBiasAtShutdown); + + afbWritePositionBias[iAxes]( + Axis:= GVL.astAxes[iAxes].Axis, + ParameterNumber:= E_AxisParameters.AxisEncoderOffset, + Value:= astAxesPersistent[iAxes].fBiasAtShutdown); END_FOR CASE eStartUp OF @@ -173,30 +173,30 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN eExecuteRestore: //Execute position restore by setting afbRestorePosition.execute = TRUE - FOR iAxes := 1 TO GVL_APP.nAXIS_NUM DO - //Restore position value for incremental encoders - IF afbReadEncRefSys[iAxes].Valid = TRUE AND NOT astAxesPersistent[iAxes].bMovingAtShutdown AND - (afbReadEncRefSys[iAxes].Value = 0 OR afbReadEncRefSys[iAxes].Value = 4 OR afbReadEncRefSys[iAxes].Value = 2) THEN + FOR iAxes := 1 TO GVL_APP.nAXIS_NUM DO + //Restore position value for incremental encoders + IF afbReadEncRefSys[iAxes].Valid = TRUE AND NOT astAxesPersistent[iAxes].bMovingAtShutdown AND + (afbReadEncRefSys[iAxes].Value = 0 OR afbReadEncRefSys[iAxes].Value = 4 OR afbReadEncRefSys[iAxes].Value = 2) THEN IF GVL.astAxes[iAxes].stConfig.eRestorePosition = E_RestorePosition.eRestoreWithoutHome THEN afbRestorePosition[iAxes].Execute := TRUE; END_IF - //Restore encoder position BIAS for absolute encoders - ELSIF afbReadEncRefSys[iAxes].Valid = TRUE THEN - IF GVL.astAxes[iAxes].stConfig.eRestorePosition = E_RestorePosition.eRestoreWithoutHome THEN + //Restore encoder position BIAS for absolute encoders + ELSIF afbReadEncRefSys[iAxes].Valid = TRUE THEN + IF GVL.astAxes[iAxes].stConfig.eRestorePosition = E_RestorePosition.eRestoreWithoutHome THEN afbWritePositionBias[iAxes].Execute := TRUE; - END_IF - END_IF - END_FOR - + END_IF + END_IF + END_FOR + 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.nAXIS_NUM DO - IF afbReadEncRefSys[iAxes].Valid = TRUE AND NOT astAxesPersistent[iAxes].bMovingAtShutdown AND - (afbReadEncRefSys[iAxes].Value = 0 OR afbReadEncRefSys[iAxes].Value = 4 OR afbReadEncRefSys[iAxes].Value = 2) THEN + FOR iAxes := 1 TO GVL_APP.nAXIS_NUM DO + IF afbReadEncRefSys[iAxes].Valid = TRUE AND NOT astAxesPersistent[iAxes].bMovingAtShutdown AND + (afbReadEncRefSys[iAxes].Value = 0 OR afbReadEncRefSys[iAxes].Value = 4 OR afbReadEncRefSys[iAxes].Value = 2) THEN IF GVL.astAxes[iAxes].stConfig.eRestorePosition = E_RestorePosition.eRestoreWithoutHome THEN IF NOT afbRestorePosition[iAxes].Done OR NOT afbWritePositionBias[iAxes].Done THEN RETURN; @@ -210,7 +210,7 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN //Remove execute = TRUE for afbRestorePosition FOR iAxes := 1 TO GVL_APP.nAXIS_NUM DO afbRestorePosition[iAxes].Execute := FALSE; - afbWritePositionBias[iAxes].Execute := FALSE; + afbWritePositionBias[iAxes].Execute := FALSE; END_FOR bPositionRestoreDone := TRUE; bRestoreExecute := FALSE; @@ -222,12 +222,12 @@ END_IF]]>