From ea525c4f49eb4b719f4702c29f875f5cf7cbc082 Mon Sep 17 00:00:00 2001 From: Paul Barron Date: Fri, 9 Aug 2019 15:08:12 +0200 Subject: [PATCH] Add a STARTUP and SHUTDOWN action to MAIN SHUTDOWN saves the current act pos of all axes and a bit to indicate whether the axes is moving. STARTUP checks all axes to see if they are incremental and not moving at previous shutdown and opt-in for value restore. If all are true then position is restored. UPS reference library from Beckhoff also added for the saving of values at shutdown. Might need to be modified as this one is specific for the particular CPU. --- solution/tc_project_app/POUs/MAIN.TcPOU | 142 +++++++++++++++++- solution/tc_project_app/tc_mca_std_lib | 2 +- .../tc_project_app/tc_project_app.plcproj | 4 + 3 files changed, 143 insertions(+), 5 deletions(-) diff --git a/solution/tc_project_app/POUs/MAIN.TcPOU b/solution/tc_project_app/POUs/MAIN.TcPOU index 1b367f8..f7387cc 100644 --- a/solution/tc_project_app/POUs/MAIN.TcPOU +++ b/solution/tc_project_app/POUs/MAIN.TcPOU @@ -1,5 +1,5 @@  - + - eSUPS_PowerFailure 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 + +PROG(); AXES(); ERROR();]]> @@ -106,8 +130,110 @@ fbEL1808( //]]> + + + + + + + + , + ReadMode:= E_READMODE.READMODE_ONCE); +END_FOR + +FOR i:=1 TO gvl_app.axisNum DO + fbRestorePosition[i]( + Axis:= gvl.axes[i].Axis, + Execute:= , + Position:= iPositionAtShutdown[i]); +END_FOR + +IF bColdstartDone = FALSE THEN + CASE iStartup OF + 0: // First cycle + IF NOT bColdstartDone THEN + iStartup:=iStartup+1; + iretry:=0; + END_IF + 1: // Read Enc Ref Sys - incremental or absolute + bExecuteReadEncRefSys:=TRUE; + iStartup:=iStartup+1; + tmrRetry(in:=FALSE); + 2: // Check if Enc Ref Sys has been read for all axis -> if not read again + tmrRetry(in:=TRUE, pt:=T#100MS); + FOR i:=1 TO gvl_app.axisNum DO + IF fbReadEncRefSys[i].Valid = FALSE THEN + IF tmrretry.Q THEN + bExecuteReadEncRefSys:=FALSE; + iStartup:=iStartup-1; + iRetry:=iRetry+1; + END_IF + RETURN; + ELSE + iStartup:=iStartup+1; + EXIT; + END_IF + END_FOR + 3: // Check if axis is incremental, opt-in/restore home and not moving at shutdown -> if so restore + FOR i:=1 TO gvl_app.axisNum DO + IF fbReadEncRefSys[i].Value=0 AND NOT(bMovingAtShutdown[i]) THEN + IF gvl.axes[i].config.iRestorePosition=2 THEN + gvl.axes[i].config.nHomeSeq:=15; + gvl.axes[i].control.eCommand:=10; + //Doesn't work yet because you can only home to zero position + //gvl.axes[i].config.######:=iPositionAtShutdown[i]; + END_IF + END_IF + END_FOR + iStartup:=iStartup+1; + 4: // Execute position restore with or without bHome set + FOR i:=1 TO gvl_app.axisNum DO + IF fbReadEncRefSys[i].Value = 0 THEN + CASE GVL.axes[i].config.iRestorePosition OF + 1: fbRestorePosition[i].Execute:=TRUE; + 2: gvl.axes[i].control.bExecute:=TRUE; + END_CASE + END_IF + END_FOR + iStartup:=iStartup+1; + 5: // Check set position or 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.iRestorePosition OF + 1: + IF NOT fbRestorePosition[i].Done THEN + RETURN; + END_IF + 2: + IF NOT gvl.axes[i].status.bHomed THEN + RETURN; + END_IF + END_CASE + END_IF + END_FOR + iStartup:=iStartup+1; + 6: // Reset set position FBs and Finish + FOR i:=1 TO gvl_app.axisNum DO + fbRestorePosition[i].Execute:=FALSE; + END_FOR + bColdstartDone:=TRUE; + END_CASE +END_IF]]> + + + + + @@ -140,5 +266,13 @@ fbEL1808( + + + + + + + + \ No newline at end of file diff --git a/solution/tc_project_app/tc_mca_std_lib b/solution/tc_project_app/tc_mca_std_lib index f2b1862..32b87da 160000 --- a/solution/tc_project_app/tc_mca_std_lib +++ b/solution/tc_project_app/tc_mca_std_lib @@ -1 +1 @@ -Subproject commit f2b186273119f71345ff25367b3145b07dfa66f4 +Subproject commit 32b87da57e91d57eaebbf927638554641a37c6b9 diff --git a/solution/tc_project_app/tc_project_app.plcproj b/solution/tc_project_app/tc_project_app.plcproj index 903cef5..6c2d7b0 100644 --- a/solution/tc_project_app/tc_project_app.plcproj +++ b/solution/tc_project_app/tc_project_app.plcproj @@ -308,6 +308,10 @@ Tc2_Standard, * (Beckhoff Automation GmbH) Tc2_Standard + + Tc2_SUPS, * (Beckhoff Automation GmbH) + Tc2_SUPS + Tc2_System, * (Beckhoff Automation GmbH) Tc2_System