Answer the question
In order to leave comments, you need to log in
Are there any extra conditions?
Good afternoon. Help a beginner process control system.
The essence of the question will be clearer on an abstract problem.
Let's say we have an engine that needs to be controlled: switching on - when 3 valves are opened and the temp. indoor 10.0'C; shutdown - if at least one valve closes or the air temperature drops below 5.0'C.
Below are 2 implementation options. Both of them are working, but in someone else's code, the 1st one is more common for me. Why and why are extra conditions needed? Is there an explanation for this and any recommendations?
Option 1
LoopFunc()
{
if (Valve1.IsOpen && Valve2.IsOpen && Valve3.IsOpen && Sensor.Value >= 10.0)
Motor.OnCmd = true;
if (!Valve1.IsOpen || !Valve2.IsOpen || !Valve3.IsOpen || Sensor.Value <= 5.0)
Motor.OnCmd = false;
}
LoopFunc()
{
if (Sensor.Value >= 10.0)
Motor.OnCmd = true;
if (!Valve1.IsOpen || !Valve2.IsOpen || !Valve3.IsOpen || Sensor.Value <= 5.0)
Motor.OnCmd = false;
}
// Global variables
bool TmpOnCmd = false;
TSensor Sensor;
TValve Valve1;
TValve Valve2;
TValve Valve3;
TMotor Motor;
LoopFunc()
{
if (Sensor.Value >= 10.0)
TmpOnCmd = true;
if (!Valve1.IsOpen || !Valve2.IsOpen || !Valve3.IsOpen || Sensor.Value <= 5.0)
TmpOnCmd = false;
Motor.OnCmd = TmpOnCmd;
}
Answer the question
In order to leave comments, you need to log in
From the first option, it is simple to immediately see under what conditions we turn on the motor, under which we turn it off. The only thing is that I would take out the check of klpons in a separate variable, so that I would not deal with copy-paste.
bool IsValvesOpen = Valve1.IsOpen && Valve2.IsOpen && Valve3.IsOpen;
if (IsValvesOpen && Sensor.Value > 10.0) {
Motor.Cmd = true;
}
if (!IsVelvesOpen || Sensor.Value < 5.0) {
Motor.Cmd = false;
}
Motor.Cmd = (Valve1.IsOpen && Valve2.IsOpen && Valve3.IsOpen) && (Sensor.Value > 10 || (Motor.Cmd && Sensor.Value >= 5))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question