沙发坐空了!
FUNCTION_BLOCK FB1026
VAR_INPUT
CarData1:DINT;//目标穿梭车1位置值
CarData2:DINT;//目标穿梭车2位置值
CarData3:DINT;//目标穿梭车3位置值
CarData4:DINT;//目标穿梭车4位置值
CarData5:DINT;//目标穿梭车5位置值
CarLocaL:DINT;//本地穿梭车位置值
Warning_JL1:DINT;//警告距离1设定
Warning_JL2:DINT;//警告距离2设定
Decelerate_JL1:DINT;//减速距离1设定
Decelerate_JL2:DINT;//减速距离2设定
StopCar_JL1:DINT;//停车距离1设定
StopCar_JL2:DINT;//停车距离2设定
END_VAR
VAR
I:INT;
InData:ARRAY[1..5] OF DINT;
END_VAR
VAR_OUTPUT
Out_Warning:BOOL;//警告启动
Out_Decelerate:BOOL;//减速启动
Out_Stop:BOOL;//停车启动
D_Value:DINT;//两车之间值
END_VAR;
InData[1]:=CarData1;
InData[2]:=CarData2;
InData[3]:=CarData3;
InData[4]:=CarData4;
InData[5]:=CarData5;
FOR I:= 1 TO 5 BY 1 DO
IF (InData[I]>0)
AND(((CarLocaL-InData[I]<0)
AND(CarLocaL-InData[I]>=Warning_JL1))
OR( CarLocaL-InData[I]>=Warning_JL2))THEN//判定是否已到警告距离
Out_Warning:=1;//警告启动
D_Value:=CarLocaL-InData[I];
ELSE
Out_Warning:=0;
Out_decelerate:=0;
Out_Stop:=0;
D_Value:=0;
END_IF;
IF OUT_Warning THEN
IF ((CarLocaL-InData[I]<0)
AND(CarLocaL-InData[I]>=Decelerate_JL1))
OR( CarLocaL-InData[I]>=Decelerate_JL2)THEN//判定是否已到减速距离
Out_decelerate:=1;//减速启动
ELSE
Out_decelerate:=0;
END_IF;
IF((CarLocaL-InData[I]<0)
AND(CarLocaL-InData[I]>=StopCar_JL1))
OR( CarLocaL-InData[I]>=StopCar_JL2)THEN//判定是否已到停车距离
Out_Stop:=1;//停车启动
ELSE
Out_Stop:=0;
END_IF;
EXIT;
END_IF;
END_FOR;
END_FUNCTION_BLOCK
这样看起来舒服些-------