
Abbos N. answered 01/10/24
Full Stack Developer
I can provide you with simplified example to get you started. For more I will need more information
PROGRAM MainProgram
VAR
DoorState: BOOL;
OpeningMotor: BOOL;
ClosingMotor: BOOL;
WarningLight: BOOL;
StatusLightsOn: BOOL;
CycleCounter: INT;
MaintenanceNeeded: BOOL;
FloorOccupancy: ARRAY[1..3] OF INT;
AverageOccupancy: INT;
METHOD OpenDoor
DoorState := True;
StatusLightsOn := True;
OpeningMotor := True;
ClosingMotor := False;
SetTimer(Timer_OpeningLight, 8000);
END_METHOD
METHOD CloseDoor
DoorState := False;
StatusLightsOn := True;
ClosingMotor := True;
OpeningMotor := False;
SetTimer(Timer_ClosingLight, 8000);
END_METHOD
METHOD ToggleDirection
IF OpeningMotor THEN
ClosingMotor := True;
SetTimer(Timer_OpeningLight, GetTimer(Timer_ClosingLight));
ELSE
OpeningMotor := True;
SetTimer(Timer_ClosingLight, GetTimer(Timer_OpeningLight));
END_IF
END_METHOD
METHOD ObstructionDetected
WarningLight := True;
ToggleDirection();
SetTimer(Timer_WarningLight, 8000);
END_METHOD
METHOD MaintenanceDone
MaintenanceNeeded := False;
AmberLight := False;
END_METHOD
METHOD CheckOccupancy
FOR i := 1 TO 3 DO
IF FloorOccupancy[i] >= 5 THEN
FloorFull[i] := True;
ELSE
FloorFull[i] := False;
END_IF
END_FOR
AverageOccupancy := (FloorOccupancy[1] + FloorOccupancy[2] + FloorOccupancy[3]) / 3;
IF AverageOccupancy > 3 THEN
OccupancyYellowLight := True;
ELSE
OccupancyYellowLight := False;
END_IF
END_METHOD
METHOD MainLogic
IF OpeningMotor = False AND ClosingMotor = False AND GetTimerDone(Timer_OpeningLight) THEN
StatusLightsOn := False;
END_IF
IF GetTimerDone(Timer_WarningLight) THEN
WarningLight := False;
END_IF
IF CycleCounter >= 2 AND DoorState = True THEN
MaintenanceNeeded := True;
AmberLight := True;
END_IF
END_METHOD
END_PROGRAM