Valve State Control with Boolean

I am new to Ignition and having a hard time figuring out where exactly to set this up.

I need to control the state property of a valve. I don't have a single tag I can bind with this property. I am using the 'open', 'closed' and 'failedToClose' states. I have a boolean tag to represent each one. That is to say I have a tag that is 'valveOpen', 'vavleClosed' and 'failedToClose'.

I thought I could use an expression binding for runScript(returnValveState, 1000, 'valveOpen', 'vavleClosed', 'failedToClose') and then have a script that would return 'open', 'closed' or 'failedToClose' based on the logic I wrote but it is not working.

Just use an expression binding with the following:

case(true, valveOpenedTag, "Opened", valveClosedTag, "Closed", FailtocloseTag, "Failed to Close", "Unknown") 

Substituting your tags appropriately in an expression binding.

case(
    true, 
    valveOpenedTag, "Opened", 
    valveClosedTag, "Closed", 
    FailtocloseTag, "Failed to Close", 
    "Unknown"
)

That's an interesting use of the case() function. At first glance I thought it wouldn't work. It does - but there may be a problem.

From case:

It takes the value argument and compares it to each of the case1 through caseN expressions. If value is equal to caseX, then case returns valueX. If value is not equal to any of the case1..N, then returnDefault is returned.

That means that if more than one status tag is true that it will return the first.

I would use binEnc to generate a unique integer for any combination of status bits and use that in the case() expression.

case(
    binEnc(
      {[~]valveOpen},     // 1 (LSB)
      {[~]valveClosed},   // 2 
      {[~]failedToClose}, // 4 (MSB)
    ),
    0, "Valve moving", 
    1, "Opened", 
    2, "Closed", 
    4, "Failed to Close", 
    "Error"
)

This way we get an "Error" if more than two states are on and the 0 option suppresses the error while the valve is changing state normally until the failedToClose turns on.

@Ryan_Hankins note that you have no failedToOpen warning.

Expressions are much faster than scripts. Use them in preference where possible.

2 Likes

I was originally going to suggest that but since they only asked for the individual bits in that order, I did the easiest way I could. (Thanks for reformatting my expression as I was on mobile and had no tab.)

Thanks for the help.

In our application, if our closed feedback isn't active then we are assuming its open as long as we aren't telling it to be closed.

I figured out the script method I was using. I was naming the script and the function the same thing and I never called the function. runScript(returnValveState, 1000, 'valveOpen', 'vavleClosed', 'failedToClose') changed to
runScript("myScripts.returnValveState", 1000, 'valveOpen', 'vavleClosed', 'failedToClose')

I tried the case option previously but I missed putting the true in the statement.

As explained, you shouldn't use scripts (or runScript from an expression) if you can do the job directly with an expression.

Please see Wiki - how to post code on this forum. (You have a typo in your code, 'vavle'.)

3 Likes

@Ryan_Hankins the state of a valve depends on what type of valve you have, either an open/close or % opening valve, so since you are trying to control the valve I ti should be assumed is a control valve.
The open/close valve says that is open or close, if it get stuck while opening, it will send a signal that is open, and viceversa.
I then case of a control valve with a actuator/positioner it will tell you what percent is open, which still send you a signal that is open. These valves are controlled with 4-20 mA signal in most cases.
If you want to know why the valve is stuck open or close, or partially either you have to go and check the valve to see the reason. I have to do that many times.
Hope this helps

I would recommend not treating those valves the same. There's so many differences usually. I know on many of the valves in gas plants that are modulating valves don't have any feedback at all unless it's over HART communications which is rarely utilized. In this case, you don't have any alarms for fail to open/close because we don't even know, but we also don't want to just show open/close on the screen and want to show the actual commanded position. Plus the operator doesn't just click an open/close button as these are usually controlled via PID loop or manual operator entry of a 0-100% position.

Michael what do you mean by modulating? I thought a valve is either a control valve or a manually operated valve on the field.
Thanks

Generally, a modulating valve would be a valve which has some type of analog driving signal, as opposed to a valve such as a solenoid which has a discrete driving signal (On/Off).

Generally we refer to modulating valves as Control Valves, and discrete valves as Functional Valves.

A "manually operated" valve can have many different meanings, for instance it is possible to have a control valve where the driving signal is being manually controlled from the HMI system. There are many control valves which do not have traditional position feedback, so the control system must assume, I told it to go to 50% its there, or it gets its feedback through some other mechanism such as a flow meter, tank level, or other device.

Or a "manually operated" valve could just mean a hand valve.

2 Likes

Yeah, different terms are used. Many times the term Control Valve (FCV, PCV, TCV, etc) is used for a modulating valve, but I try to avoid it as it could get confusing for anyone not using that term as any valve can really control flows, pressures, etc. and the term modulate means (abbreviated definition): to regulate by or adjust to a certain measure or proportion which truly defines it.

Our open/close valves many times are just referred to as shutdown valves (SDV) as they completely stop/isolate pressures, flows, etc., and are usually the larger assembly that uses one or two solenoid valves (SV).

Sometimes solenoid valves are also used for Control Valves but typically as a dump valve to dump the air pressure so the valve moves to its fail position (for safety).

All of these valves typically have an Auto/Program mode and a Manual/Operator mode depending on the terms you like to use.

1 Like