ES_Event Run_RWD_FSM (ES_Event CurrentEvent) { if (CurrentEvent is 80_Seconds_Expire event) { Change the state to Find_Deposit_Beacon state } switch (CurrentState) if CurrentState is Move_Forward state { if CurrentEvent is Front_Left_Front_Bumper_Hit or Front_Left_Left_Bumper_Hit event { proceed to Rotate_Clockwise state Rotate the vehicle clockwise set counter to a rotation time of 1 seconds } if CurrentEvent is Front_Right_Front_Bumper_Hit or Front_Right_Right_Bumper_Hit event { proceed to Rotate_CClockwise state Rotate the vehicle counter clockwise set counter to a rotation time of 1 seconds } } if CurrentState is Rotate_Clockwise state { if CurrentEvent is Timer_1MS_Expire event { decrement the counter if counter reaches zero, proceed to Move_Forward state } } if CurrentState is Rotate_CClockwise state { if CurrentEvent is Timer_1MS_Expire event { decrement the counter if counter reaches zero, proceed to Move_Forward state } } if (CurrentState is Find_Deposit_Beacon state) { if CurrentEvent is Beacon_3_Detected event || Beacon_4_Detected event (Back IR sensors) { Check if detected signal correspond to beacon that we are interested in if yes, proceed to Move_Backward state Move the vehicle backward Set counter to a move backward time of 5 seconds } } if (CurrentState is Move_Backward state) { if CurrentEvent is Back_Left_Back_Bumper_Hit or Back_Left_Left_Bumper_Hit event { Proceed to Deposit_Move_Clockwise state Rotate the vehicle clockwise Set counter to a rotation time of 2 seconds } else if CurrentEvent is Back_Right_Back_Bumper_Hit or Back_Right_Right_Bumper_Hit event { Proceed to Deposit_Move_CClockwise state Rotate the vehicle counter clockwise Set counter to a rotation time of 2 seconds } if CurrentEvent is Timer_1_MS_Expire event { Decrement the counter if counter reaches zero, proceed to Find_Deposit_Beacon state } } if (CurrentState is Deposit_Move_Clockwise state) { if CurrentEvent is Back_Right_Back_Bumper_Hit or Back_Right_Right_Bumper_Hit event { Proceed to Move_Tray_Up state Stop the vehicle Move the Tray up } if CurrentEvent is Timer_1_MS_Expire event { Decrement the counter if counter reaches zero, proceed to Find_Deposit_Beacon state Rotate the vehicle clockwise } } if (CurrentState is Deposit_Move_CClockwise state) { if CurrentEvent is Back_Left_Back_Bumper_Hit or Back_Left_Left_Bumper_Hit event { Proceed to Move_Tray_Up state Stop the vehicle Move the Tray up } if CurrentEvent is Timer_1_MS_Expire event { Decrement the counter if counter reaches zero, proceed to Find_Deposit_Beacon state Rotate the vehicle clockwise } } if (CurrentState is Move_Tray_Up state { if CurrentEvent is Tray_Upper_Limit_Reached event { Proceed to Wait_Tray_Up state Set the counter to a wait time of 4 seconds Stop the tray movement } } if (CurrentState is Wait_Tray_Up state { if CurrentEvent is Timer_1_MS_Expire event { Decrement the counter if counter reaches zero, proceed to Move_Tray_Down state Move the tray downward } } if (CurrentState is Move_Tray_Down state { if CurrentEvent is Tray_Lower_Limit_Reached event { Proceed to Move_Forward state Move the vehicle forward } } }