Controller A - Main Game Pseudo Code
This code is used to control the main game play of Controller A 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.
InitAMainSM
CurrentState = InitState
Initialize the servo
RunAMainSM
switch(CurrentState)
case (InitState)
Turn the servo to 0
NextState = Lockdown
case (Lockdown)
if ThisEvent = AccessCardDetected
Run Start of Game LED Show
Send Access Card Detected message to Controller B
Initialize all sub-state machines (TargetFSM, BalanceFSM)
NextState = WaitForReady
case(WaitForReady)
switch (ThisEvent)
case (APush)
LEDs off
NextState = AReady
case (BPush)
NextState = BReady
case (AccessCardRemoved)
NextState = Lockdown
Turn off all LEDs
Vibration off
Send Access Card Removed Event to Controller B
case (AReady)
if ThisEvent = BPush
Post Begin event to Target and Balance FSMs
Send End Stage Event to Controller B
Start game timer
Start clock LED countdown
Turn on practice target
NextState = WaitTargetPractice
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Vibration off
Send Access Card Removed Event to Controller B
case (BReady)
if ThisEvent = APush
Post Begin event to Target and Balance FSMs
Send End Stage Event to Controller B
Start game timer
Start clock LED countdown
Turn on practice target
NextState = WaitTargetPractice
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Vibration off
Send Access Card Removed Event to Controller B
case (WaitTargetPractice)
if ThisEvent = BothCovered
BoardState = QueryBalanceInterpreter
Turn off target
Turn vibration on
Send End Stage message to B
Blink Target
Turn Servo to 60 degrees
if BoardState = BothOnBalance
NextState = BalancedBPractice
Start balance timer
else
NextState = BothOffBalance
TurnOffAllTargets
Vibration on
Comm B
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Vibration off
Restart the clock
Turn servo to 0 degrees
Send Access Card Removed Event to Controller B
else if ThisEvent = GameTimeout
NextState = Celebration
Start power down timer
Send End of Game message to B
Start End of Game Show
case (BalancedBPractice)
switch (ThisEvent)
case (Unbalanced)
//from Balance Interpreter
NextState = NotBalancedBPractice
case (BalanceTimeout)
Vibration off
Send End Stage message to B
Turn servo to 120 degrees
NextState = WaitingTargetSynchro
case(AccessCardRemoved)
NextState = Lockdown
Turn off all LEDs
Vibration off
Restart the clock
Turn servo to 0 degrees
Send Access Card Removed Event to Controller B
case( GameTimeout)
NextState = Celebration
Start power down timer
Send End of Game message to B
Start End of Game Show
case (NotBalancedBPractice)
if ThisEvent = BothBalanced
start balance timer
NextState = BalancedBPractice
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Vibration off
Restart the clock
Turn servo to 0 degrees
Send Access Card Removed Event to Controller B
else if ThisEvent = GameTimeout
NextState = Celebration
Start power down timer
Send End of Game message to B
Start End of Game Show
case (WaitingTargetSynchro)
switch (ThisEvent)
case (BothCovered)
AdvanceTarget
Send Advance Target message to B
case (TargetTimeout)
AdvanceTarget
Send Advance Target message to B
case (Unbalanced)
NextState = OffBalanceSynchro
case(AccessCardRemoved)
NextState = Lockdown
Turn off all LEDs
Vibration off
Restart the clock
Turn servo to 0 degrees
Send Access Card Removed Event to Controller B
case( GameTimeout)
NextState = Celebration
Start power down timer
Send End of Game message to B
Start End of Game Show
case (OffBalanceSynchro)
if ThisEvent = TargetTimeout
AdvanceTarget
Send Advance Target message to B
else if ThisEvent = BothRebalanced
NextState = WaitingTargetSynchro
if BothCovered
Advance Target
Send Advance Target message to B
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Vibration off
Restart the clock
Turn servo to 0 degrees
Send Access Card Removed Event to Controller B
else if ThisEvent = GameTimeout
NextState = Celebration
Start power down timer
Send End of Game message to B
Start End of Game Show
case (Celebration)
if ThisEvent = PowerDownTimeout
Run Waiting for Start Show
Turn servo to 0
Reinitialize clock
NextState = WaitForReady
Comm B
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Vibration off
Restart the clock
Turn servo to 0 degrees
Send Access Card Removed Event to Controller B
end switch case
CurrentState = NextState
CurrentState = InitState
Initialize the servo
RunAMainSM
switch(CurrentState)
case (InitState)
Turn the servo to 0
NextState = Lockdown
case (Lockdown)
if ThisEvent = AccessCardDetected
Run Start of Game LED Show
Send Access Card Detected message to Controller B
Initialize all sub-state machines (TargetFSM, BalanceFSM)
NextState = WaitForReady
case(WaitForReady)
switch (ThisEvent)
case (APush)
LEDs off
NextState = AReady
case (BPush)
NextState = BReady
case (AccessCardRemoved)
NextState = Lockdown
Turn off all LEDs
Vibration off
Send Access Card Removed Event to Controller B
case (AReady)
if ThisEvent = BPush
Post Begin event to Target and Balance FSMs
Send End Stage Event to Controller B
Start game timer
Start clock LED countdown
Turn on practice target
NextState = WaitTargetPractice
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Vibration off
Send Access Card Removed Event to Controller B
case (BReady)
if ThisEvent = APush
Post Begin event to Target and Balance FSMs
Send End Stage Event to Controller B
Start game timer
Start clock LED countdown
Turn on practice target
NextState = WaitTargetPractice
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Vibration off
Send Access Card Removed Event to Controller B
case (WaitTargetPractice)
if ThisEvent = BothCovered
BoardState = QueryBalanceInterpreter
Turn off target
Turn vibration on
Send End Stage message to B
Blink Target
Turn Servo to 60 degrees
if BoardState = BothOnBalance
NextState = BalancedBPractice
Start balance timer
else
NextState = BothOffBalance
TurnOffAllTargets
Vibration on
Comm B
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Vibration off
Restart the clock
Turn servo to 0 degrees
Send Access Card Removed Event to Controller B
else if ThisEvent = GameTimeout
NextState = Celebration
Start power down timer
Send End of Game message to B
Start End of Game Show
case (BalancedBPractice)
switch (ThisEvent)
case (Unbalanced)
//from Balance Interpreter
NextState = NotBalancedBPractice
case (BalanceTimeout)
Vibration off
Send End Stage message to B
Turn servo to 120 degrees
NextState = WaitingTargetSynchro
case(AccessCardRemoved)
NextState = Lockdown
Turn off all LEDs
Vibration off
Restart the clock
Turn servo to 0 degrees
Send Access Card Removed Event to Controller B
case( GameTimeout)
NextState = Celebration
Start power down timer
Send End of Game message to B
Start End of Game Show
case (NotBalancedBPractice)
if ThisEvent = BothBalanced
start balance timer
NextState = BalancedBPractice
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Vibration off
Restart the clock
Turn servo to 0 degrees
Send Access Card Removed Event to Controller B
else if ThisEvent = GameTimeout
NextState = Celebration
Start power down timer
Send End of Game message to B
Start End of Game Show
case (WaitingTargetSynchro)
switch (ThisEvent)
case (BothCovered)
AdvanceTarget
Send Advance Target message to B
case (TargetTimeout)
AdvanceTarget
Send Advance Target message to B
case (Unbalanced)
NextState = OffBalanceSynchro
case(AccessCardRemoved)
NextState = Lockdown
Turn off all LEDs
Vibration off
Restart the clock
Turn servo to 0 degrees
Send Access Card Removed Event to Controller B
case( GameTimeout)
NextState = Celebration
Start power down timer
Send End of Game message to B
Start End of Game Show
case (OffBalanceSynchro)
if ThisEvent = TargetTimeout
AdvanceTarget
Send Advance Target message to B
else if ThisEvent = BothRebalanced
NextState = WaitingTargetSynchro
if BothCovered
Advance Target
Send Advance Target message to B
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Vibration off
Restart the clock
Turn servo to 0 degrees
Send Access Card Removed Event to Controller B
else if ThisEvent = GameTimeout
NextState = Celebration
Start power down timer
Send End of Game message to B
Start End of Game Show
case (Celebration)
if ThisEvent = PowerDownTimeout
Run Waiting for Start Show
Turn servo to 0
Reinitialize clock
NextState = WaitForReady
Comm B
else if ThisEvent = AccessCardRemoved
NextState = Lockdown
Turn off all LEDs
Vibration off
Restart the clock
Turn servo to 0 degrees
Send Access Card Removed Event to Controller B
end switch case
CurrentState = NextState