278 lines
9.6 KiB
XML
278 lines
9.6 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
|
|
<POU Name="MAIN" Id="{33eb6f49-7781-4211-a70b-87ada6d80cb7}" SpecialFunc="None">
|
|
<Declaration><![CDATA[PROGRAM MAIN
|
|
VAR
|
|
sVersion: STRING:='1.0.0';
|
|
i : UINT; //index variable for AXES()
|
|
aFbAxes: ARRAY [1..gvl_app.axisNum] OF FB_Axis;
|
|
hmiAxisSelection : INT:=1; //Not possible to use local hmi variables for array indexes
|
|
|
|
(******Outputs: Power for Limit switches and Home Sensors (every 4th output)********)
|
|
|
|
bOutput1 AT %Q*: BOOL:= TRUE;
|
|
//bOutput2 AT %Q*: BOOL:= TRUE;
|
|
//bOutput3 AT %Q*: BOOL:= TRUE;
|
|
//bOutput4 AT %Q*: BOOL:= TRUE;
|
|
//bOutput5 AT %Q*: BOOL:= TRUE;
|
|
//bOutput6 AT %Q*: BOOL:= TRUE;
|
|
//bOutput7 AT %Q*: BOOL:= TRUE;
|
|
//bOutput8 AT %Q*: BOOL:= TRUE;
|
|
//bOutput9 AT %Q*: BOOL:= TRUE;
|
|
//bOutput13 AT %Q*: BOOL:= TRUE;
|
|
//bOutput17 AT %Q*: BOOL:= TRUE;
|
|
//bOutput21 AT %Q*: BOOL:= TRUE;
|
|
//bOutput24 AT %Q*: BOOL:= TRUE;
|
|
//bOutput28 AT %Q*: BOOL:= TRUE;
|
|
|
|
(******Error Handling********)
|
|
fbErrorSystem: FB_ErrorSystem;
|
|
aFbAxesError: ARRAY [1..gvl_app.axisNum] OF FB_NC_Error;
|
|
|
|
//fbEL1018 : EL1018;
|
|
//fbEL2808 : EL2808;
|
|
//fbEL5101 : EL5101;
|
|
//fbEL9505 : EL9505;
|
|
//fbEL1252 : EL1252;
|
|
//fbEL9410 : EL9410;
|
|
//fbEL7037 : EL7037;
|
|
//fbEK1110 : EK1110;
|
|
|
|
(******Startup, Shutdown and UPS********)
|
|
eStartUp: (ColdStart, ReadEncRefSys, CheckRead, CheckFeedbackType, ExecutePosRestore, CheckFinished, FinsishSetPosition);
|
|
bColdstartDone : BOOL := FALSE; // First cycle of the PLC after being reset/power cycled
|
|
bExecuteReadEncRefSys : BOOL := TRUE;
|
|
tmrRetry : TON;
|
|
iRetry : INT;
|
|
fbReadEncRefSys : ARRAY [1..gvl_app.axisNum] OF MC_ReadParameter;
|
|
fbUPS : FB_S_UPS_CX51x0;
|
|
eUpsMode : E_S_UPS_Mode := eSUPS_WrPersistData_Shutdown;
|
|
fbRestorePosition : ARRAY [1..GVL_app.axisNum] OF MC_SetPosition;
|
|
|
|
END_VAR
|
|
VAR PERSISTENT
|
|
iPositionAtShutdown : ARRAY [1..gvl_app.axisNum] OF LREAL;
|
|
bMovingAtShutdown : ARRAY [1..gvl_app.axisNum] OF BOOL;
|
|
END_VAR]]></Declaration>
|
|
<Implementation>
|
|
<ST><![CDATA[fbUPS(eUpsMode := eUpsMode); (* call UPS-FB instance in first lines of the fastest PLC Task *)
|
|
|
|
IF eGlobalSUpsState = eSUPS_PowerFailure THEN
|
|
(* first cycle of powerfailure *)
|
|
(* execute code that should only be done once with each powerfailure, i.e. increase powerfailure counter *)
|
|
SHUTDOWN();
|
|
ELSIF eGlobalSUpsState > 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
|
|
|
|
STARTUP();
|
|
PROG();
|
|
AXES();
|
|
ERROR();]]></ST>
|
|
</Implementation>
|
|
<Action Name="AXES" Id="{7eb32732-9b53-4934-8cd9-20ba971dd8ff}">
|
|
<Implementation>
|
|
<ST><;
|
|
END_FOR
|
|
|
|
|
|
]]></ST>
|
|
</Implementation>
|
|
</Action>
|
|
<Action Name="ERROR" Id="{35f2cf38-f81e-4aa3-9534-be5fb417817d}">
|
|
<Implementation>
|
|
<ST><;
|
|
END_FOR
|
|
|
|
|
|
|
|
(*call all the necessary instance (input assistance F2 or right click) according to the terminals that you have in your hardware and
|
|
add "TRUE" in the input En, the corresponding number of termianl to the iTerminal_ID and
|
|
the variable "fbErrorSystem.pErrorSystem" to the input ErrorSystem in each FB E. g. :
|
|
fbEL1808(
|
|
En:= TRUE,
|
|
iTerminal_ID:= 01,
|
|
ErrorSystem:= fbErorSystem.pErrorSystem,
|
|
EnO=> ,
|
|
bError=> );
|
|
*)
|
|
|
|
]]></ST>
|
|
</Implementation>
|
|
</Action>
|
|
<Action Name="PROG" Id="{5d03ebbb-2a47-4890-ad6d-e82daf72dc51}">
|
|
<Implementation>
|
|
<ST><![CDATA[//
|
|
(* Program any sequence, safety or feature (if necessary) application specific in thsi section*)
|
|
//]]></ST>
|
|
</Implementation>
|
|
</Action>
|
|
<Action Name="SHUTDOWN" Id="{cb5c9254-2e5f-47b1-9baa-10e728a961b0}">
|
|
<Implementation>
|
|
<ST><![CDATA[FOR i:=1 TO gvl_app.axisNum DO
|
|
iPositionAtShutdown[i]:=gvl.axes[i].Axis.NcToPlc.ActPos;
|
|
bMovingAtShutdown[i]:=gvl.axes[i].Axis.Status.Moving;
|
|
END_FOR]]></ST>
|
|
</Implementation>
|
|
</Action>
|
|
<Action Name="STARTUP" Id="{0c7ee537-7bd9-4833-b428-c17cbb57e893}">
|
|
<Implementation>
|
|
<ST><;
|
|
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 eStartUp OF
|
|
ColdStart: // First cycle
|
|
IF NOT bColdstartDone THEN
|
|
eStartUp:=eStartUp+1;
|
|
iRetry:=0;
|
|
END_IF
|
|
ReadEncRefSys: // Read Enc Ref Sys - incremental or absolute
|
|
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);
|
|
FOR i:=1 TO gvl_app.axisNum DO
|
|
IF fbReadEncRefSys[i].Valid = FALSE THEN
|
|
IF tmrretry.Q THEN
|
|
bExecuteReadEncRefSys:=FALSE;
|
|
eStartUp:=eStartUp-1;
|
|
iRetry:=iRetry+1;
|
|
END_IF
|
|
RETURN;
|
|
ELSE
|
|
eStartUp:=eStartUp+1;
|
|
EXIT;
|
|
END_IF
|
|
END_FOR
|
|
CheckFeedbackType: // 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;
|
|
END_IF
|
|
END_IF
|
|
END_FOR
|
|
eStartUp:=eStartUp+1;
|
|
ExecutePosRestore: // 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
|
|
eStartUp:=eStartUp+1;
|
|
CheckFinished: // 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
|
|
eStartUp:=eStartUp+1;
|
|
FinsishSetPosition: // 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]]></ST>
|
|
</Implementation>
|
|
</Action>
|
|
<LineIds Name="MAIN">
|
|
<LineId Id="124" Count="9" />
|
|
<LineId Id="2" Count="0" />
|
|
<LineId Id="189" Count="0" />
|
|
<LineId Id="135" Count="0" />
|
|
<LineId Id="134" Count="0" />
|
|
<LineId Id="81" Count="1" />
|
|
</LineIds>
|
|
<LineIds Name="MAIN.AXES">
|
|
<LineId Id="3" Count="0" />
|
|
<LineId Id="1" Count="0" />
|
|
<LineId Id="4" Count="0" />
|
|
<LineId Id="10" Count="0" />
|
|
<LineId Id="7" Count="0" />
|
|
<LineId Id="16" Count="0" />
|
|
<LineId Id="11" Count="0" />
|
|
</LineIds>
|
|
<LineIds Name="MAIN.ERROR">
|
|
<LineId Id="31" Count="0" />
|
|
<LineId Id="10" Count="1" />
|
|
<LineId Id="34" Count="8" />
|
|
<LineId Id="1" Count="0" />
|
|
<LineId Id="90" Count="1" />
|
|
<LineId Id="88" Count="1" />
|
|
<LineId Id="92" Count="2" />
|
|
<LineId Id="87" Count="0" />
|
|
<LineId Id="79" Count="1" />
|
|
<LineId Id="12" Count="0" />
|
|
<LineId Id="44" Count="8" />
|
|
<LineId Id="62" Count="0" />
|
|
<LineId Id="14" Count="0" />
|
|
<LineId Id="33" Count="0" />
|
|
</LineIds>
|
|
<LineIds Name="MAIN.PROG">
|
|
<LineId Id="2" Count="0" />
|
|
<LineId Id="1" Count="0" />
|
|
<LineId Id="3" Count="0" />
|
|
</LineIds>
|
|
<LineIds Name="MAIN.SHUTDOWN">
|
|
<LineId Id="2" Count="2" />
|
|
<LineId Id="1" Count="0" />
|
|
</LineIds>
|
|
<LineIds Name="MAIN.STARTUP">
|
|
<LineId Id="2" Count="47" />
|
|
<LineId Id="52" Count="35" />
|
|
<LineId Id="1" Count="0" />
|
|
</LineIds>
|
|
</POU>
|
|
</TcPlcObject> |