Skip to content

Commit

Permalink
Merge pull request #80 from ghalym/auto_recover
Browse files Browse the repository at this point in the history
Auto recover
  • Loading branch information
jyin999 authored Sep 2, 2021
2 parents b6b86b2 + 236a582 commit 26e2b9a
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 73 deletions.
4 changes: 2 additions & 2 deletions L2SIVacuum/DUTs/Gauges/E_PressureState.TcDUT
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<Declaration><![CDATA[TYPE E_PressureState :
(
// Invalid states
PressInvalid,// //gc_GaugeValidState - 1,
Off,// //gc_GaugeValidState - 1,
GaugeDisconnected, //gc_GaugeValidState -2,
OoR, //gc_GaugeValidState -6,
// Ion gauges
Off, //gc_GaugeValidState - 3,
PressInvalid, //gc_GaugeValidState - 3,
Starting, //gc_GaugeValidState - 4
//Valid States (Positive)
Expand Down
17 changes: 14 additions & 3 deletions L2SIVacuum/DUTs/Gauges/ST_VG.TcDUT
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ STRUCT
xPRESS_OK: BOOL;
{attribute 'pytmc' := '
pv: STATE;
field: ZRST PressInvalid;
field: ZRST Off;
field: ONST GaugeDisconnected;
field: TWST OoR;
field: THST Off;
field: THST PressInvalid;
field: FRST Starting;
field: FVST Valid;
field: SXST ValidHi;
Expand All @@ -50,7 +50,18 @@ STRUCT
field: ONAM ON;
'}
xHV_SW: BOOL; // High Voltage Switch from epics
{attribute 'pytmc' := '
pv: Auto_On;
field: ZNAM FALSE;
field: ONAM TRUE;
io:io;
'}
xAutoOn : BOOL := TRUE;
{attribute 'pytmc' := '
pv: AutoOn_timer;
io:i;
'}
iAutoOnTimer : INT;
/// Controls and I/Os
{attribute 'pytmc' := '
pv: PRESS_AI;
Expand Down
10 changes: 8 additions & 2 deletions L2SIVacuum/DUTs/Pumps/ST_PIP.TcDUT
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ STRUCT
pv: Auto_On;
field: ZNAM FALSE;
field: ONAM TRUE;
io:i;
io:io;
'}
xAutoOn : BOOL;
xAutoOn : BOOL:=TRUE;
{attribute 'pytmc' := '
pv: AutoOn_timer;
io:i;
'}
iAutoOnTimer : INT;
{attribute 'pytmc' := '
pv: OVRD_ON ;
field: ZNAM Override OFF ;
Expand Down
4 changes: 2 additions & 2 deletions L2SIVacuum/GVLs/Global_Variables.TcGVL
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4022.18">
<GVL Name="Global_Variables" Id="{a6c265d3-24f0-4c94-8227-7e6ead61f239}">
<Declaration><![CDATA[VAR_GLOBAL
g_iSizeOfGGOArray : INT := 50;
Expand All @@ -12,7 +12,7 @@
fbGetCurTaskIdx : GETCURTASKINDEX;
TaskInfo:PlcTaskSystemInfo;
END_VAR
Expand Down
79 changes: 45 additions & 34 deletions L2SIVacuum/L2SIVacuum.tmc

Large diffs are not rendered by default.

Binary file modified L2SIVacuum/LineIDs.dbg
Binary file not shown.
3 changes: 3 additions & 0 deletions L2SIVacuum/POUs/Functions/Gauges/FB_GaugeBase.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ VAR
// For Persistent Data
bRestorePersistentData : BOOL:=TRUE;
stateTimer:TON;
fbGetCurTaskIdx : GETCURTASKINDEX;
fbWritePersistentData : WritePersistentData;
tRecover: TON;
END_VAR
VAR PERSISTENT
rVAC_SP : REAL;
Expand Down
62 changes: 48 additions & 14 deletions L2SIVacuum/POUs/Functions/Gauges/FB_MKS422.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ END_VAR
VAR_INPUT
PG : ST_VG; // Pirani Gauge Structure used to Interlock the Cold Cathode
b937A :BOOL:=FALSE; // True if this gauge is connected to MKS937A controller, False if connected to MKS937B controller
tRecoverDelay:TIME:=T#600S; (*Delay Time after the first cycle to start the device. Default is 600S*)
END_VAR
VAR_OUTPUT
{attribute 'pytmc' := '
Expand All @@ -19,20 +20,25 @@ VAR_OUTPUT
END_VAR
VAR
rV : REAL;
timer:TON;
(*IOs to be linked*)
/// Controls and I/Os
i_iPRESS_R AT %I* :INT; // input Pressure // Link to analog Input
q_xHV_DIS AT %Q* : BOOL := True; // Disable Gauge High Voltage when True // 'TcLinkTo' (EL2794) ^Output
stPump: INT;
END_VAR
VAR CONSTANT
MinPressure: REAL := 1E-10;
MinPressure: REAL := 1E-11;
vDisconnected : REAL:= 0.18;
vMaxValid : REAL:=9.6;
vMax : REAL:=9.9;
vValidLo:REAL :=0.22;
vMin : REAL:=0.6;
cDefaultPressure : REAL := 0;
END_VAR
VAR PERSISTENT
bWasOn : BOOL;
bAutoRecover:BOOL;
bAutoRecoverWrite:BOOL;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[(* 937B Logarithmic Output Conversion *)
Expand All @@ -54,17 +60,20 @@ END_IF
(* Pressure gauge State checks *)
IF (rV <=9.6 ) AND (rV>=0.6) THEN
IF (rV <= vMaxValid ) AND (rV>=vMin) AND (IG.xHV_SW) THEN
IG.eState := Valid; // normal
ELSIF rV >= 0.18 AND rV <= 0.22 THEN
ELSIF rV >= vDisconnected AND rV <= vValidLo AND (IG.xHV_SW) THEN
IG.eState := ValidLo; //LO
ELSIF rV > 9.6 AND rV<= 9.9 THEN
ELSIF rV > vMaxValid AND rV<= vMax AND (IG.xHV_SW) THEN
IG.eState := ValidHi; //HIGH
ELSIF rV < 0.18 THEN //
IG.eState := GaugeDisconnected; //not on
ELSIF rV < vDisconnected THEN //
IG.eState := GaugeDisconnected; //other fault - gauge disconnected, controller powering up etc
IG.rPRESS :=cDefaultPressure;
ELSIF NOT (IG.xHV_SW) THEN
IG.eState := Off; //not on
IG.rPRESS :=cDefaultPressure;
ELSE
IG.eState := PressInvalid; //other fault - could be no gauge, controller powering up etc
ELSIF IG.rPRESS < MinPressure THEN
IG.eState := PressInvalid; //
IG.rPRESS :=cDefaultPressure;
END_IF
Expand Down Expand Up @@ -92,7 +101,7 @@ END_IF
(* Pressure gauge OK checks *)
IG.xPRESS_OK := (rV <=9.6 ) AND (rV>=0.6);
IG.xPRESS_OK := (rV <=vMax ) AND (rV>=vMin);
(* Setpoint evaluation *)
Expand All @@ -107,7 +116,8 @@ IO();
(*Load or save the persistent variables*)
ACT_Persistent();
timer(IN:= NOT IG.q_xHV_DIS, PT:= T#2s);
(*Run Auto Recovery*)
ACT_Recover();
]]></ST>
</Implementation>
<Action Name="ACT_Logger" Id="{81455e48-69be-44cd-8f73-e6a424a8f2a9}">
Expand Down Expand Up @@ -166,6 +176,9 @@ IF (SUPER^.bRestorePersistentData) THEN
IF ( rHYS_PR <> 0) THEN
IG.rHYS_PR := rHYS_PR;
END_IF;
IF ( bAutoRecoverWrite) THEN
IG.xAutoOn := bAutoRecover;
END_IF;
END_IF
(*Check if a new value has been written in the structure variable copy it to the persistent variable*)
IF NOT (IG.rVAC_SP = rVAC_SP) THEN
Expand All @@ -179,13 +192,32 @@ END_IF;
IF NOT (IG.rHYS_PR = rHYS_PR) THEN
rHYS_PR:= IG.rHYS_PR;
END_IF;
IF NOT(bAutoRecoverWrite) OR NOT (IG.xAutoOn = bAutoRecover) THEN
bAutoRecover := IG.xAutoOn;
bAutoRecoverWrite := TRUE;
END_IF;
stateTimer(PT:=T#10S);
IF (ePrevState <> IG.eState) THEN
IF (stateTimer.Q) THEN
bWasOn := (IG.eState >=Valid );
stateTimer.IN := FALSE;
fbWritePersistentData(NETID:='', PORT:=851, START:=TRUE, TMOUT:=T#1s );
END_IF;]]></ST>
</Implementation>
</Action>
<Action Name="ACT_Recover" Id="{3e6e3bcf-7780-45ff-9848-62b6d7bc4a60}">
<Implementation>
<ST><![CDATA[fbGetCurTaskIdx();
IF (TwinCAT_SystemInfoVarList._TaskInfo[fbGetCurTaskIdx.index].FirstCycle) THEN
tRecover.IN := TRUE;
END_IF
tRecover(IN:= , PT:=tRecoverDelay);
IF NOT(bAutoRecoverWrite) OR (tRecover.Q AND bAutoRecover ) THEN
This^.M_Recover();
tRecover.IN := FALSE;
END_IF]]></ST>
</Implementation>
</Action>
<Action Name="IO" Id="{745bf75f-6d68-4d34-a177-a78f14818649}">
<Implementation>
<ST><![CDATA[(*soft link inputs*)
Expand All @@ -194,7 +226,9 @@ IG.i_iPRESS_R:= i_iPRESS_R;
(*soft link outputs*)
q_xHV_DIS := IG.q_xHV_DIS;
IG.sPath := sPath;]]></ST>
IG.sPath := sPath;
IG.iAutoOnTimer:= TIME_TO_INT(tRecover.PT);
]]></ST>
</Implementation>
</Action>
<Method Name="M_AutoOn" Id="{06245f08-bb9d-49ef-bd4d-3fe48276b865}">
Expand Down
58 changes: 48 additions & 10 deletions L2SIVacuum/POUs/Functions/Gauges/FB_MKS500.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ END_VAR
VAR_INPUT
PG : ST_VG;
bEP : BOOL :=FALSE; // Set to True if This Gauge is connected to EP BOX and not EL Terminals
tRecoverDelay:TIME:=T#600S; (*Delay Time after the first cycle to start the device. Default is 600S*)
END_VAR
VAR_OUTPUT
{attribute 'pytmc' := '
Expand All @@ -23,6 +24,7 @@ END_VAR
VAR
rV : REAL;
GaugeTurnOnTmr : TON;
tStartupTimer:TON;
iTermBits: UINT := 32767 ; // The terminal's maximum value in bits
(*IOs to be linked*)
/// Controls and I/Os
Expand All @@ -31,7 +33,7 @@ VAR
// only for EL and ES terminal
i_xHV_ON AT %I* : BOOL; // True when High Voltage is on // 'TcLinkTo' (EL1124) ^Input
i_xDisc_Active AT %I* : BOOL;// Discharge Current Active // 'TcLinkTo' (EL1124) ^Input
binit:BOOL:=TRUE;
END_VAR
VAR CONSTANT
Expand All @@ -48,30 +50,42 @@ VAR CONSTANT
END_VAR
VAR PERSISTENT
bWasOn : BOOL;
bAutoRecover:BOOL;
bAutoRecoverWrite:BOOL;
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[(* 500 Logarithmic Output Conversion, factory default configuration *)
<ST><![CDATA[(*Startup time*)
IF (bInit) THEN
tStartupTimer.IN:=TRUE;
bInit :=FALSE;
END_IF
tStartupTimer(PT:=T#3S);
(* 500 Logarithmic Output Conversion, factory default configuration *)
If (iTermBits=0) THEN iTermBits := 32767;END_IF
rV := 10*INT_TO_REAL(IG.i_iPRESS_R)/iTermBits;
(* Set Guage State based on the Analog voltage*)
IF rV < vDisconnected THEN
IF NOT (tStartupTimer.Q) THEN // Give time for the gauge controller to start
IG.eState := Off;
IG.rPRESS := cDefaultPressure;
ELSIF rV < vDisconnected THEN
IG.eState := GaugeDisconnected;
IG.rPRESS := cDefaultPressure;
ELSIF rV >= vDisconnected AND rV < (vNoDischarge -rDeadband) THEN
ELSIF rV >= vDisconnected AND rV < (vNoDischarge -rDeadband) AND (IG.xHV_SW) THEN
IG.eState := Valid;
IG.rPRESS := LREAL_TO_REAL(EXPT(10,((rV-vBase)/vSlope+LOG(pBase))));
ELSIF rV >= (vNoDischarge -rDeadband) AND rV <(vGaugeOff -rDeadband) THEN
ELSIF rV >= (vNoDischarge -rDeadband) AND rV <(vGaugeOff -rDeadband) AND (IG.xHV_SW) THEN
IG.eState := Starting;
IG.rPRESS := LREAL_TO_REAL(EXPT(10,((rV-vBase)/vSlope+LOG(pBase))));
ELSIF rV >= (vGaugeOff -rDeadband) THEN
IG.eState := Off;
//IG.rPRESS := LREAL_TO_REAL(EXPT(10,((rV-vBase)/vSlope+LOG(pBase))));
IG.rPRESS := cDefaultPressure;
ELSE
IG.eState := OoR;
ELSIF IG.rPRESS < MinPressure THEN
IG.eState := PressInvalid;
//IG.rPRESS := LREAL_TO_REAL(EXPT(10,((rV-vBase)/vSlope+LOG(pBase))));
IG.rPRESS := cDefaultPressure;
END_IF
Expand Down Expand Up @@ -127,7 +141,8 @@ ACT_Logger();
IO();
(*Load or save the persistent variables*)
ACT_Persistent();
]]></ST>
(*Run Auto Recovery*)
ACT_Recover();]]></ST>
</Implementation>
<Action Name="ACT_Logger" Id="{b6ae699a-8cbc-41c3-94fc-93d1d486cd97}">
<Implementation>
Expand Down Expand Up @@ -185,6 +200,9 @@ IF (SUPER^.bRestorePersistentData) THEN
IF ( rHYS_PR <> 0) THEN
IG.rHYS_PR := rHYS_PR;
END_IF;
IF ( bAutoRecoverWrite) THEN
IG.xAutoOn := bAutoRecover;
END_IF;
END_IF
(*Check if a new value has been written in the structure variable copy it to the persistent variable*)
IF NOT (IG.rVAC_SP = rVAC_SP) THEN
Expand All @@ -198,13 +216,32 @@ END_IF;
IF NOT (IG.rHYS_PR = rHYS_PR) THEN
rHYS_PR:= IG.rHYS_PR;
END_IF;
IF NOT(bAutoRecoverWrite) OR NOT (bAutoRecover = IG.xAutoOn) THEN
bAutoRecover := IG.xAutoOn;
bAutoRecoverWrite := TRUE;
END_IF;
stateTimer(PT:=T#10S);
IF (ePrevState <> IG.eState) THEN
IF (stateTimer.Q) THEN
bWasOn := (IG.eState >=Valid );
stateTimer.IN := FALSE;
fbWritePersistentData(NETID:='', PORT:=851, START:=TRUE, TMOUT:=T#1s );
END_IF;]]></ST>
</Implementation>
</Action>
<Action Name="ACT_Recover" Id="{ac0dd076-6f0a-4fff-a772-7158a547a40b}">
<Implementation>
<ST><![CDATA[fbGetCurTaskIdx();
IF (TwinCAT_SystemInfoVarList._TaskInfo[fbGetCurTaskIdx.index].FirstCycle) THEN
tRecover.IN := TRUE;
END_IF
tRecover(IN:= , PT:=tRecoverDelay);
IF NOT(bAutoRecoverWrite) OR (tRecover.Q AND bAutoRecover ) THEN
This^.M_Recover();
tRecover.IN := FALSE;
END_IF]]></ST>
</Implementation>
</Action>
<Action Name="IO" Id="{8ad71ac6-f961-40c8-a3be-ad3367f81f67}">
<Implementation>
<ST><![CDATA[(*soft link inputs*)
Expand All @@ -214,7 +251,8 @@ IG.i_xDisc_Active:=i_xDisc_Active;
(*soft link outputs*)
q_xHV_DIS := IG.q_xHV_DIS;
IG.sPath := sPath;]]></ST>
IG.sPath := sPath;
IG.iAutoOnTimer:= TIME_TO_INT(tRecover.PT);]]></ST>
</Implementation>
</Action>
<Method Name="M_HVE" Id="{5c5dd30f-1cf9-426d-9ab9-5103df771146}">
Expand Down
Loading

0 comments on commit 26e2b9a

Please sign in to comment.