High-Level State Machine Pseudocode
Master State Machine Function: RunMasterSM State Running: Do during function for Running Function: DuringRunning Entry: Start Game State State Machine Start Offensive Coordinator State Machine Exit/Else: Run Game State State Machine Run Offensive Coordinator State Machine Game State State Machine Function: GameTimerInit Initialize output compare for game timer - don't start timer yet, since game is not on Function: RunGameSM State Paused: Run during function for Paused Event: New OC Response If the response was "game running" Set flag to start game Event: Game started event Transition to On state State On: Run during function for On Event: New OC Response If the response was "game paused" Set flag to pause game Event: Game paused event Transition to Paused state Function: DuringPaused Not Entry/Exit: If Command Queue length is 0 Add a "query game status" command to queue Set team color based on switch Set half court status based on switch Function: DuringOn Entry: Resume game timer by reenabling timer interrupt Start Gameplay State Machine Start Sensors State Machine Start Drivetrain State Machine Exit: Pause game timer by disabling interrupt Run child state machines Else: If 1 second has passed since last query, Add a "query game status" command to queue Run child state machines