我花了很多时间和大量的纸质素描,而我却无法偶然发现任何事情让我解决这个问题。
我们有两个装满水的水箱和两个水泵。如果h> hmax(罐1)和H,我们需要使用这些泵自动将水推到第二罐
我无法弄清楚一件事。第一序列假设如果H> Hmax,泵1或2将起作用(它们不能同时工作)。当水被泵送到第二个水箱并且第一个水箱将下降时,在第一个水箱中补充水之后重复该顺序。我无法弄清楚如何在每个序列之后仅使用电位计对泵进行自动更换。我需要做的更多是包括其中一个泵的故障。我将近一个星期处理这个问题。
答案 0 :(得分:0)
希望这就是你的意思。我把它写成了一个"工作"伪代码。 在现实生活中,这段代码不是最好的,因为从那时起你有2个以上的泵应该是复杂的,但是这个非常详细。 还缺少紧急开关(如果他必须手动停止泵,则可以按下某个按钮)。 更好的方法是使用一些function_blocks和方法...
声明:
VAR
//INPUT
levelTank1 AT %I* : INT; //potentiometer 1
levelTank2 AT %I* : INT; //potentiometer 2
pump1Malfunction AT %I* : BOOL; //TRUE=pump has no malfunction || FALSE=malfunction
pump2Malfunction AT %I* : BOOL;
//OUTPUT
pump1Operation AT %Q* : BOOL; //TRUE=pump should run
pump2Operation AT %Q* : BOOL;
lastPumpInOperation : BYTE := 1;
nState : UINT := 0;
END_VAR
在某处您应该定义最小和最大级别,我将其作为常量值:
VAR CONSTANT
tank1Hmax : INT := 32000;
tank1Hmin : INT := 5000;
tank2Hmax : INT := 25000;
tank2Hmin : INT := 2000;
END_VAR
备注:模拟输入通常是INT值,因此最大值。等于32767
现在程序:
CASE nState OF
0: //wait till tank 1 is filled and make sure tank2 is not overcharged
IF (levelTank1 >= tank1Hmax) AND NOT (levelTank2 >= tank2Hmax) THEN
nState := 1;
END_IF
1: //start one pump
//first check worst case - both pumps are broken
IF NOT pump1Malfunction AND NOT pump2Malfunction THEN
nState := 100; //emergency
//last time pump1 was used, and now pump 2 should start when it has no malfunction
ELSIF lastPumpInOperation = 1 AND pump2Malfunction THEN
pump2Operation := TRUE;
lastPumpInOperation := 2;
nState := 2;
//last time pump2 was used, and now pump 1 should start when it has no malfunction
ELSIF lastPumpInOperation = 2 AND pump1Malfunction THEN
pump1Operation := TRUE;
pump2Operation := FALSE;
lastPumpInOperation := 1;
nState := 2;
//now we have to define what happens when one pump is in malfunction
ELSIF NOT pump1Malfunction THEN
pump2Operation := TRUE;
pump1Operation := FALSE;
lastPumpInOperation := 2;
nState := 2;
ELSIF NOT pump2Malfunction THEN
pump1Operation := TRUE;
lastPumpInOperation := 1;
nState := 2;
END_IF
2: //pump operation till tank1 is "empty", tank2 is "full" or pump failure occurs
IF (levelTank1 <= tank1Hmin) OR (levelTank2 >= tank2Hmax) THEN
nState := 3; //stop pumps
ELSIF (pump1Operation AND NOT pump1Malfunction) THEN //pump has gone in malfunction during operation
nState := 1; //go back to step2 to start another pump
ELSIF (pump2Operation AND NOT pump2Malfunction) THEN
nState := 1;
END_IF
3: //stop pumps
pump1Operation := FALSE;
pump2Operation := FALSE;
nState := 0;
100: //emergency
//do what you can do - close the valve to tank1 or run as fast as you can
pump1Operation := FALSE;
pump2Operation := FALSE;
IF (pump1Malfunction OR pump2Malfunction) THEN
nState := 0;
END_IF
END_CASE