大概意思吧,还有些异常报警处理没写,你自己看着弄下
// 初始化定时器
IF NOT StartTime.IN THEN
StartTime(IN := TRUE, PT := T#0S);
END_IF
IF NOT ShutdownTime.IN THEN
ShutdownTime(IN := AutoMode AND (PressureBar <= PressureLow OR PressureBar >= PressureHigh), PT := StandbyTime);
END_IF
// 初始化休眠时间定时器
FOR i := 1 TO 4 DO
IF NOT SleepTime[i].IN THEN
SleepTime[i](IN := TRUE, PT := SleepIntervals[i]);
END_IF
END_FOR
// 根据压力值判断电机台数
IF AutoMode THEN
MotorCount := 0;
IF PressureBar < PressureLow THEN
MotorCount := 1;
ELSIF PressureBar < PressureMedium THEN
MotorCount := 2;
ELSIF PressureBar < PressureHigh THEN
MotorCount := 3;
ELSE
MotorCount := 4;
END_IF
// 初始化电机启用状态
FOR i := 1 TO 4 DO
MotorEnabled[i] := FALSE;
END_FOR
// 根据休眠时间长的优先启动
FOR i := 1 TO MotorCount DO
MaxSleepTimeIndex := 1;
FOR j := 1 TO 4 DO
IF NOT MotorEnabled[j] AND (SleepTime[j].ET > SleepTime[MaxSleepTimeIndex].ET) THEN
MaxSleepTimeIndex := j;
END_IF
END_FOR
MotorEnabled[MaxSleepTimeIndex] := TRUE;
END_FOR
// 更新电机状态
FOR i := 1 TO 4 DO
IF MotorEnabled[i] THEN
IF NOT MotorState[i] THEN
MotorState[i] := TRUE;
RunTime[i](IN := TRUE, PT := T#MAX); // 开始计时
END_IF
ELSE
IF MotorState[i] THEN
MotorState[i] := FALSE;
RunTime[i](IN := FALSE); // 停止计时
END_IF
END_IF
MotorCommand[i] := MotorState[i];
END_FOR
// 切换轮休电机
IF ShutdownTime.Q THEN
MaxRunTimeIndex := 1;
FOR i := 1 TO 4 DO
IF MotorEnabled[i] AND (RunTime[i].ET > RunTime[MaxRunTimeIndex].ET) THEN
MaxRunTimeIndex := i;
END_IF
END_FOR
MotorEnabled[MaxRunTimeIndex] := FALSE;
MotorState[MaxRunTimeIndex] := FALSE;
RunTime[MaxRunTimeIndex](IN := FALSE);
ShutdownTime(IN := FALSE); // 重置停机定时器
END_IF
ELSE
// 手动模式下,所有电机停止
FOR i := 1 TO 4 DO
MotorCommand[i] := FALSE;
MotorState[i] := FALSE;
RunTime[i](IN := FALSE);
END_FOR
END_IF