Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function block FB_VRC_NC_ClsLS for ChemRIXS single limit switch v… #83

Merged
merged 2 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions L2SIVacuum/L2SIVacuum.plcproj
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@
<SubType>Code</SubType>
<LinkAlways>true</LinkAlways>
</Compile>
<Compile Include="POUs\Functions\Valves\FB_VRC_NC_ClsLS.TcPOU">
<SubType>Code</SubType>
</Compile>
<Compile Include="POUs\Functions\Valves\FB_VRC_NO.TcPOU">
<SubType>Code</SubType>
<LinkAlways>true</LinkAlways>
Expand Down
54 changes: 31 additions & 23 deletions L2SIVacuum/L2SIVacuum.tmc

Large diffs are not rendered by default.

Binary file removed L2SIVacuum/LineIDs.dbg
Binary file not shown.
264 changes: 264 additions & 0 deletions L2SIVacuum/POUs/Functions/Valves/FB_VRC_NC_ClsLS.TcPOU
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4022.18">
<POU Name="FB_VRC_NC_ClsLS" Id="{c8e0c1f7-5d63-4e08-9f94-8c1d7ca472c0}" SpecialFunc="None">
<Declaration><![CDATA[(* This Function Block Implements Basic Functionality for ChemRIX NC valve, which has one NC LS mounting at Open position.
Valve considers CLOSED when the LS is closed.
This function block is interloked by an input (i_xExtILK_OK). This is so developers can interface with custom
interlocking logic outside this function block.*)
(* Note Interlock Logic is External *)
{attribute 'no_check'}
FUNCTION_BLOCK FB_VRC_NC_ClsLS EXTENDS FB_Valve
VAR_IN_OUT

END_VAR
VAR_INPUT
i_xExtILK_OK : BOOL; //Connect to Interlock logic condition(e.g F_TURBO_VRC_ILK Function), otherwise, Set to True if the valve is not interlocked
i_xOverrideMode : BOOL; (*To be linked to global override bit. This Overrides Vacuum logic only, EPS, MPS and PMPS are still enforces*)
END_VAR
VAR_OUTPUT
{attribute 'pytmc' := '
pv:
'}
iq_stValve : ST_VRC;
END_VAR
VAR
{attribute 'instance-path'}
{attribute 'noinit'}
sPath: STRING;
xFirstPass : BOOL;
fbFSInit : R_TRIG;
tonOvrd : TON;
tonDelOK : TON;
rtOK : R_TRIG;
tOvrd : TIME := T#10s;
(* Timeouts*)
tTimeOutDuration: TIME:= T#30S;
tOPNtimeout: TON;
tCLStimeout:TON;


(*IO*)
// i_xOpnLS AT%I*: BOOL;
i_xClsLS AT%I*: BOOL;
q_xOPN_DO AT%Q*: BOOL;

END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[
(* On first PLC pass, put valve into vented state, which implies a closed valve *)
fbFSInit( CLK := TRUE, Q => xFirstPass);
IF xFirstPass THEN
iq_stValve.eVGC_State := Vented;
iq_stValve.pv_xOPN_SW := FALSE;
ePrevState := INVALID;
END_IF




///Check valve position
(*IF iq_stValve.i_xClsLS AND iq_stValve.i_xOpnLS THEN
iq_stValve.eState:=INVALID;
ELSIF NOT iq_stValve.i_xClsLS AND iq_stValve.i_xOpnLS AND iq_stValve.q_xOPN_DO THEN
iq_stValve.eState:=OPEN;
ELSIF NOT iq_stValve.i_xClsLS AND iq_stValve.i_xOpnLS AND NOT iq_stValve.q_xOPN_DO THEN
iq_stValve.eState:=OPEN_F;
ELSIF iq_stValve.i_xClsLS AND NOT iq_stValve.i_xOpnLS AND NOT iq_stValve.q_xOPN_DO THEN
iq_stValve.eState:=CLOSED;
ELSIF NOT iq_stValve.i_xClsLS AND NOT iq_stValve.i_xOpnLS THEN
iq_stValve.eState:=MOVING;
ELSE
iq_stValve.eState:=INVALID;
END_IF
*)

IF NOT iq_stValve.i_xClsLS AND iq_stValve.q_xOPN_DO THEN
iq_stValve.eState:=OPEN;
ELSIF NOT iq_stValve.i_xClsLS AND NOT iq_stValve.q_xOPN_DO THEN
iq_stValve.eState:=OPEN_F;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not Sure we can have OPEN_F state. This might be an invalid state. We are not reading the CLS_LS but we are not opening it either. The cable might be unplugged?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. The valve cannot force open. It should be invalid state.

ELSIF iq_stValve.i_xClsLS AND NOT iq_stValve.q_xOPN_DO THEN
iq_stValve.eState:=CLOSED;
ELSIF iq_stValve.i_xClsLS AND iq_stValve.q_xOPN_DO THEN
iq_stValve.eState:=INVALID;
ELSE
iq_stValve.eState:=INVALID;
END_IF


(*evaluate Valve open external interlock*)
iq_stValve.xOPN_OK := i_xExtILK_OK;
iq_stValve.xEXT_OK := i_xExtILK_OK;
IF NOT iq_stValve.xOPN_OK and NOT tonOvrd.Q THEN
iq_stValve.pv_xOPN_SW := FALSE;
iq_stValve.eVGC_State := ERR_ExtFault;
END_IF

IF (iq_stValve.q_xOPN_DO) AND (iq_stValve.xOPN_OK) THEN
iq_stValve.eVGC_State := AtVacuum;
END_IF


(* Override logic *)
(* Goal: give ability to override, but do so in a way that people won't forget it.
Solution: Override only after ten seconds of override, protect against blips,
when the valve permission goes true for more than ten seconds consistently, remove override
*)

tonDelOK(IN:=iq_stValve.xOPN_OK, PT:=T#10S);
rtOK(CLK:=tonDelOK.Q);
IF rtOK.Q AND iq_stValve.pv_xOvrdOpn THEN
iq_stValve.pv_xOvrdOpn :=FALSE;
if (iq_stValve.eState=OPEN) AND (i_xOverrideMode) THEN iq_stValve.pv_xOPN_SW := TRUE; END_IF
//Log
fbLogger(sMsg:='Override expired', eSevr:=TcEventSeverity.Warning);
END_IF
// Release the Force Open bit when the system override is false
IF NOT(i_xOverrideMode) THEN iq_stValve.pv_xOvrdOpn :=FALSE; END_IF
//Override timer
tonOvrd(IN:=iq_stValve.pv_xOvrdOpn, PT:=tOvrd);

(* Here's where the valve opens *)
iq_stValve.q_xOPN_DO := (iq_stValve.pv_xOPN_SW AND iq_stValve.xOPN_OK) OR (tonOvrd.Q AND i_xOverrideMode);


///Check valve moving position timout
IF NOT iq_stValve.i_xClsLS AND tCLStimeout.Q THEN
iq_stValve.bErrorPresent := TRUE;
iq_stValve.sErrorMessage := ' Close Timeout';
ELSIF iq_stValve.i_xClsLS AND tOPNtimeout.Q THEN
iq_stValve.bErrorPresent := TRUE;
iq_stValve.sErrorMessage := ' Open Timeout';
END_IF
IF (iq_stValve.eState=INVALID) THEN
iq_stValve.bErrorPresent := TRUE;
iq_stValve.sErrorMessage := CONCAT(sPath,' Invalid Valve Position');
END_IF

(*Timers*)
tOPNtimeout(IN:= iq_stValve.q_xOPN_DO, PT := tTimeOutDuration );
tCLStimeout(IN:= NOT iq_stValve.q_xOPN_DO, PT := tTimeOutDuration);


(*Soft IO Mapping*)
ACT_IO();

// Log States and triggers
ACT_Logger();
]]></ST>
</Implementation>
<Action Name="ACT_IO" Id="{832e9930-252e-428d-9c38-91f508d96ae4}">
<Implementation>
<ST><![CDATA[(*inputs*)
//iq_stValve.i_xOpnLS := i_xOpnLS;
iq_stValve.i_xClsLS:= i_xClsLS;
iq_stValve.xOverrideMode := i_xOverrideMode;
(*outputs*)
q_xOPN_DO:= iq_stValve.q_xOPN_DO;]]></ST>
</Implementation>
</Action>
<Action Name="ACT_Logger" Id="{2cc9c349-f382-4e27-b96c-1d4dc1b8826e}">
<Implementation>
<ST><![CDATA[// ILK logger

IF NOT i_xExtILK_OK AND ePrevState = OPEN THEN
fbLogger(sMsg:='Lost external interlock while valve was open.', eSevr:=TcEventSeverity.Critical);
END_IF


//STATE Logger

IF ePrevState <> iq_stValve.eState THEN
CASE iq_stValve.eState OF
INVALID:
fbLogger(sMsg:='Valve invalid position.', eSevr:=TcEventSeverity.Critical);
MOVING:
fbLogger(sMsg:='Valve moving', eSevr:=TcEventSeverity.Warning);
OPEN:
fbLogger(sMsg:='Valve Open.', eSevr:=TcEventSeverity.Info);
CLOSED:
fbLogger(sMsg:='Valve closed.', eSevr:=TcEventSeverity.Info);
END_CASE
ePrevState := iq_stValve.eState;
END_IF



// Log valve timeouts
tErrorPresent(CLK:=iq_stValve.bErrorPresent);
IF tErrorPresent.Q THEN fbLogger(sMsg:=iq_stValve.sErrorMessage, eSevr:=TcEventSeverity.Warning); END_IF

// Log valve open
tAction(CLK:= iq_stValve.q_xOPN_DO);
IF tAction.Q THEN fbLogger(sMsg:='Valve commanded open', eSevr:=TcEventSeverity.Info); END_IF

// Log override mode enabled
tOverrideActivated(CLK:= (tonOvrd.Q AND i_xOverrideMode));
IF tOverrideActivated.Q THEN fbLogger(sMsg:='Valve override mode activated', eSevr:=TcEventSeverity.Warning); END_IF
]]></ST>
</Implementation>
</Action>
<Method Name="M_IsClosed" Id="{7ad446ad-fd8e-4a3a-ad72-0269439a7470}">
<Declaration><![CDATA[METHOD PUBLIC M_IsClosed : BOOL
VAR_INPUT
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[M_IsClosed := (This^.iq_stValve.eState = E_ValvePositionState.CLOSED);]]></ST>
</Implementation>
</Method>
<Method Name="M_IsOpen" Id="{b3af6188-c4e9-47f3-a44d-062a6e242d0d}">
<Declaration><![CDATA[METHOD PUBLIC M_IsOpen : BOOL
VAR_INPUT
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[M_IsOpen := (This^.iq_stValve.eState = E_ValvePositionState.OPEN);]]></ST>
</Implementation>
</Method>
<Method Name="M_Set_OPN_SW" Id="{fa5ecad4-0273-4dee-a535-13ef6fc6d5d2}">
<Declaration><![CDATA[// Use this Methode to Open or close the valve by setting the OPN_SW to the input value.
METHOD PUBLIC M_Set_OPN_SW : BOOL
VAR_INPUT
value:BOOL;
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[This^.iq_stValve.pv_xOPN_SW := value;]]></ST>
</Implementation>
</Method>
<LineIds Name="FB_VRC_NC_ClsLS">
<LineId Id="3" Count="16" />
<LineId Id="224" Count="1" />
<LineId Id="20" Count="7" />
<LineId Id="268" Count="0" />
<LineId Id="271" Count="5" />
<LineId Id="282" Count="0" />
<LineId Id="278" Count="3" />
<LineId Id="267" Count="0" />
<LineId Id="28" Count="2" />
<LineId Id="183" Count="0" />
<LineId Id="31" Count="17" />
<LineId Id="50" Count="5" />
<LineId Id="135" Count="1" />
<LineId Id="57" Count="29" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="FB_VRC_NC_ClsLS.ACT_IO">
<LineId Id="2" Count="4" />
<LineId Id="1" Count="0" />
</LineIds>
<LineIds Name="FB_VRC_NC_ClsLS.ACT_Logger">
<LineId Id="2" Count="35" />
<LineId Id="1" Count="0" />
</LineIds>
<LineIds Name="FB_VRC_NC_ClsLS.M_IsClosed">
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="FB_VRC_NC_ClsLS.M_IsOpen">
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="FB_VRC_NC_ClsLS.M_Set_OPN_SW">
<LineId Id="2" Count="0" />
</LineIds>
</POU>
</TcPlcObject>