Controller B - Main Game Pseudo Code
This code is used to control the main game play of Controller B and to move through the different stages in the game. Controller A is the master, and communicates most timing and stage end events to Controller B.
InitBMainSM
CurrentState = InitState
Initialize the servo
RunBMainSM
switch(CurrentState)
case (InitState)
Turn the servo to 0
NextState = Lockdown
case (Lockdown)
if ThisEvent = AccessCardDetected
Run Start of Game LED Show
Initialize all sub-state machines (TargetFSM, BalanceFSM)
Turn servo to 0
NextState = WaitForReady
case(WaitForReady)
switch (ThisEvent)
case (BPush)
Send BReady message to A
Turn off all LEDs
NextState = BReady
case (AccessCardRemoved)
NextState = Lockdown
Turn off all LEDs
Vibration off
Turn servo to 0
case (BReady)
if ThisEvent = Stage End
Post Begin event to Target and Balance FSMs
Turn on practice target
NextState = WaitTargetPractice
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Vibration off
Turn servo to 0
case (WaitTargetPractice)
if ThisEvent = StageEnd
Turn off target
Turn vibration on
Blink Target
NextState = BalancedBPractice
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Turn servo to 0 degrees
else if ThisEvent = GameTimeout
NextState = Celebration
Turn servo to 90 degrees
Start End of Game Show
case (BalancedBPractice)
switch (ThisEvent)
case (StageEnd)
Vibration off
Turn LEDs off
Start Synchro Targets
Post Balance Complete message to BalanceFSM
Post Begin to TargetFSM
NextState = WaitingTargetSynchro
case(AccessCardRemoved)
NextState = Lockdown
Turn off all LEDs
Turn servo to 0 degrees
case(GameTimeout)
NextState = Celebration
Turn servo to 90 degrees
Start End of Game Show
case (WaitingTargetSynchro)
switch (ThisEvent)
case (AdvanceTarget)
AdvanceTarget
case(AccessCardRemoved)
NextState = Lockdown
Turn off all LEDs
Turn servo to 0 degrees
case(GameTimeout)
NextState = Celebration
Turn servo to 90 degrees
Start End of Game Show
case (Celebration)
if ThisEvent = StageEnd
Run Waiting for Start Show
Turn servo to 0
NextState = WaitForReady
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Turn servo to 0 degrees
end switch case
CurrentState = NextState
CurrentState = InitState
Initialize the servo
RunBMainSM
switch(CurrentState)
case (InitState)
Turn the servo to 0
NextState = Lockdown
case (Lockdown)
if ThisEvent = AccessCardDetected
Run Start of Game LED Show
Initialize all sub-state machines (TargetFSM, BalanceFSM)
Turn servo to 0
NextState = WaitForReady
case(WaitForReady)
switch (ThisEvent)
case (BPush)
Send BReady message to A
Turn off all LEDs
NextState = BReady
case (AccessCardRemoved)
NextState = Lockdown
Turn off all LEDs
Vibration off
Turn servo to 0
case (BReady)
if ThisEvent = Stage End
Post Begin event to Target and Balance FSMs
Turn on practice target
NextState = WaitTargetPractice
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Vibration off
Turn servo to 0
case (WaitTargetPractice)
if ThisEvent = StageEnd
Turn off target
Turn vibration on
Blink Target
NextState = BalancedBPractice
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Turn servo to 0 degrees
else if ThisEvent = GameTimeout
NextState = Celebration
Turn servo to 90 degrees
Start End of Game Show
case (BalancedBPractice)
switch (ThisEvent)
case (StageEnd)
Vibration off
Turn LEDs off
Start Synchro Targets
Post Balance Complete message to BalanceFSM
Post Begin to TargetFSM
NextState = WaitingTargetSynchro
case(AccessCardRemoved)
NextState = Lockdown
Turn off all LEDs
Turn servo to 0 degrees
case(GameTimeout)
NextState = Celebration
Turn servo to 90 degrees
Start End of Game Show
case (WaitingTargetSynchro)
switch (ThisEvent)
case (AdvanceTarget)
AdvanceTarget
case(AccessCardRemoved)
NextState = Lockdown
Turn off all LEDs
Turn servo to 0 degrees
case(GameTimeout)
NextState = Celebration
Turn servo to 90 degrees
Start End of Game Show
case (Celebration)
if ThisEvent = StageEnd
Run Waiting for Start Show
Turn servo to 0
NextState = WaitForReady
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Turn servo to 0 degrees
end switch case
CurrentState = NextState