From ac37748fbe6375a0675101f2fc1dad6509297cba Mon Sep 17 00:00:00 2001 From: Paul Barron Date: Tue, 10 Dec 2019 13:27:05 +0100 Subject: [PATCH] Add comments to MAIN.STARTUP Slight tidy of code but no structural changes. --- solution/tc_project_app/POUs/MAIN.TcPOU | 67 +++++++++++++++++++------ 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/solution/tc_project_app/POUs/MAIN.TcPOU b/solution/tc_project_app/POUs/MAIN.TcPOU index 5eba679..b2e3e5b 100644 --- a/solution/tc_project_app/POUs/MAIN.TcPOU +++ b/solution/tc_project_app/POUs/MAIN.TcPOU @@ -143,7 +143,20 @@ END_FOR]]> - ReadMode:= E_READMODE.READMODE_ONCE); END_FOR +// Cycle through set position function blocks for each axis +// Only axes with RestorePosition=RestoreWithoutHome (mode 1) will be utilised FOR i:=1 TO gvl_app.axisNum DO fbRestorePosition[i]( Axis:= gvl.axes[i].Axis, @@ -159,19 +174,21 @@ FOR i:=1 TO gvl_app.axisNum DO Position:= iPositionAtShutdown[i]); END_FOR +// Upon startup bColdStartDone will be set to FALSE, after the following initialisation it is set to TRUE +// and should stay TRUE for the rest of the time the PLC is operational, thus this routine should only be completed once IF bColdstartDone = FALSE THEN CASE eStartUp OF - ColdStart: // First cycle + ColdStart: // First cycle of the PLC, do nothing just give one cycle for variables to initialise IF NOT bColdstartDone THEN eStartUp:=eStartUp+1; iRetry:=0; END_IF - ReadEncRefSys: // Read Enc Ref Sys - incremental or absolute + ReadEncRefSys: // Exectute the function blocks to read the encoder reference system (inc or abs) bExecuteReadEncRefSys:=TRUE; eStartUp:=eStartUp+1; tmrRetry(in:=FALSE); - CheckRead: // Check if Enc Ref Sys has been read for all axis -> if not read again - tmrRetry(in:=TRUE, pt:=T#100MS); + CheckRead: // Check encoder reference system has been read for all axis -> if not read again + tmrRetry(in:=TRUE, pt:=T#100MS); // Timer gives the axis enough PLC cycles to initialise FOR i:=1 TO gvl_app.axisNum DO IF fbReadEncRefSys[i].Valid = FALSE THEN IF tmrretry.Q THEN @@ -185,17 +202,15 @@ IF bColdstartDone = FALSE THEN EXIT; END_IF END_FOR - CheckFeedbackType: // Check if axis is incremental, opt-in/restore home and not moving at shutdown -> if so restore + CheckFeedbackType: // Prepare to home for axes that opt in for mode 2 RestoreWithHome i.e. normal direct home FOR i:=1 TO gvl_app.axisNum DO - IF fbReadEncRefSys[i].Value=0 AND NOT(bMovingAtShutdown[i]) THEN - IF gvl.axes[i].config.eRestorePosition=2 THEN - gvl.axes[i].config.nHomeSeq:=15; - gvl.axes[i].control.eCommand:=10; - END_IF + IF fbReadEncRefSys[i].Value=0 AND NOT(bMovingAtShutdown[i]) AND gvl.axes[i].config.eRestorePosition=2 THEN + gvl.axes[i].config.nHomeSeq:=15; + gvl.axes[i].control.eCommand:=10; END_IF END_FOR eStartUp:=eStartUp+1; - ExecutePosRestore: // Execute position restore with or without bHome set + ExecutePosRestore: // Execute position restore using either fbRestorePosition or normal direct homing (depending on mode) FOR i:=1 TO gvl_app.axisNum DO IF fbReadEncRefSys[i].Value = 0 THEN CASE GVL.axes[i].config.eRestorePosition OF @@ -205,7 +220,7 @@ IF bColdstartDone = FALSE THEN END_IF END_FOR eStartUp:=eStartUp+1; - CheckFinished: // Check set position or direct homing is finished on axes that were opt-in + CheckFinished: // Check mode 1: fbRestorePosition or mode 2: direct homing is finished on axes that were opt-in FOR i:=1 TO gvl_app.axisNum DO IF fbReadEncRefSys[i].Value = 0 THEN CASE gvl.axes[i].config.eRestorePosition OF @@ -221,7 +236,7 @@ IF bColdstartDone = FALSE THEN END_IF END_FOR eStartUp:=eStartUp+1; - FinsishSetPosition: // Reset set position FBs and Finish + FinsishSetPosition: // Remove execute = TRUE for fbRestorePosition FOR i:=1 TO gvl_app.axisNum DO fbRestorePosition[i].Execute:=FALSE; END_FOR @@ -275,8 +290,28 @@ END_IF]]> - - + + + + + + + + + + + + + + + + + + + + + +