我花了很多时间和大量的纸质素描,我无法偶然发现任何事情让我解决这个问题。
我们有两个装满水的水箱和两个水泵。我们……
希望这就是你的意思。我把它写成一个“工作”的伪代码。 在现实生活中,这段代码不是最好的,因为从那时起你有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