You are on page 1of 8

Data

private to the module: CurrentState, TeamColor, LastCaptureGoal,


LastCaptureReload, NumGoalEdges, NumReloadEdges

RunPlayService(CurrentEvent)

Set MakeTransiDon to false


Set NextState to CurrentState
Set EventType of EntryEventKind to ES_ENTRY
Set EventType of ReturnEvent to ES_NO_EVENT

Switch on CurrentState
Case WAITING_TO_START:
Set ReturnEvent and CurrentEvent to return value of
DuringWaiDngToStart funcDon with parameter CurrentEvent
If EventType of CurrentEvent is not ES_NO_EVENT
Switch on EventType of CurrentEvent
Case EV_STATE_CHANGE:
Set NextState to EventParam of CurrentEvent
Set MakeTransiDon to true
Break
Case ES_TIMEOUT
If EventParam of CurrentEvent is LED_TIMER
Start LED_TIMER
Toggle LED pin
Endif
Break
Endswitch
Endif
Break
Case FACE_OFF:
Set ReturnEvent and CurrentEvent to return value of
DuringFaceOff funcDon with parameter CurrentEvent
If EventType of CurrentEvent is not ES_NO_EVENT
Switch on EventType of CurrentEvent
Case EV_STATE_CHANGE:
Set NextState to EventParam of CurrentEvent
Set MakeTransiDon to true
Set EventType of EntryEventKind to ES_ENTRY
Break
Endswitch
Endif
Break
Case OFFENSE:
Set ReturnEvent and CurrentEvent to return value of
DuringOffense funcDon with parameter CurrentEvent
If EventType of CurrentEvent is not ES_NO_EVENT
Switch on EventType of CurrentEvent
Case EV_STATE_CHANGE:
Set NextState to EventParam of CurrentEvent
Set MakeTransiDon to true
Break
Case EV_EARLY_DEFENSE
Set NextState to DEFENSE
Set MakeTransiDon to true
Break
Case ES_TIMEOUT
If EventParam of CurrentEvent is GAME_TIMER
Set NextState to EventParam of CurrentEvent
If return value of GetShotClock funcDon is
greater than or equal to 5.5 seconds
Start GAME_TIMER_2
Endif
Elseif EventParam of CurrentEvent is GAME_TIMER_2
Set NextState to EvenParam of CurrentEvent
If return value of GetRedScore funcDon is
return value of GetBlueScore funcDon
Declare OverDmeEvent as type ES_Event_t
Set EventType of OverDmeEvent as
EV_STATE_CHANGE
Set EventParam of OverDmeEvent as OVERTIME
Call PostMasterSM with parameter OverDmeEvent
Endif
Endif
Break
Endswitch
Endif
Break
Case DEFENSE:
Set ReturnEvent and CurrentEvent to return value of
DuringDefense funcDon with parameter CurrentEvent
If EventType of CurrentEvent is not ES_NO_EVENT
Switch on EventType of CurrentEvent
Case EV_STATE_CHANGE:
If EventParam of CurrentEvent is not DEFENSE
Set NextState to EventParam of CurrentEvent
Set MakeTransiDon to true
Endif
Break
Endswitch
Endif
Break
Case GAME_OVER:
Set ReturnEvent and CurrentEvent to return value of
DuringGameOver funcDon with parameter CurrentEvent
If EventType of CurrentEvent is not ES_NO_EVENT
Switch on EventType of CurrentEvent
Case EV_STATE_CHANGE:
Set NextState to EventParam of CurrentEvent
Set MakeTransiDon to true
Break
Endswitch
Endif
Break
Case OVERTIME:
Set ReturnEvent and CurrentEvent to return value of
DuringOverDme funcDon with parameter CurrentEvent
If EventType of CurrentEvent is not ES_NO_EVENT
Switch on EventType of CurrentEvent
Case EV_STATE_CHANGE:
If EventType of CurrentEvent is not OVERTIME
Set MakeTransiDon to true
Set NextState to EventParam of CurrentEvent
Endif
Break
Endswitch
Endif
Break
Endswitch

If MakeTransiDon is true
Set EventType of CurrentEvent to ES_EXIT
Call RunPlayService funcDon with parameter CurrentEvent
Set CurrentState to NextState
Call RunPlayService with parameter EntryEventKind
Endif

Return ReturnEvent

End of funcDon

StartPlayService(CurrentEvent)

If EventType of CurrentEvent is not ES_ENTRY_HISTORY


Set CurrentState to TOP_STATE
Endif
Call RunPlayService with parameter CurrentEvent

End of funcDon

QueryPlayService
Return CurrentState

End of funcDon

GetTeamColor

Return TeamColor

End of funcDon

ResetGoalEdges

Set NumGoalEdges to 0

End of funcDon

ResetReloadEdges

Set NumReloadEdges to 0

End of funcDon

ReadTeamColor

Set Color to Bit 7 of Port D


If Color is 1
Set TeamColor to RedTeam
Set Compare A register on PWM2 to value for red flag
Else
Set TeamColor to BlueTeam
Set Compare A register on PWM2 to value for blue flag

DuringWaiDngToStart(Event)

Set ReturnEvent to Event


If EventType of Event is ES_ENTRY or EventType of Event is ES_ENTRY_HISTORY
Call StopMotors funcDon
Call ReadTeamColor funcDon
Start LED_TIMER
Call SetNumBalls funcDon with parameter STARTING_NUM_BALLS
Call ResetFlag funcDon
Elseif EventType of Event is ES_EXIT

Else

Endif
Return ReturnEvent

End of funcDon

DuringFaceOff(Event)

Set ReturnEvent to Event


If EventType of Event is ES_ENTRY or EventType of Event is ES_ENTRY_HISTORY
Start 100-second Dmer
Turn on LED
Call StartReloadingSM funcDon with parameter Event
Elseif EventType of Event is ES_EXIT
Call RunReloadingSM funcDon with parameter Event
Else
Call RunReloadingSM funcDon with parameter Event and set
ReturnEvent to its return value
Endif

Return ReturnEvent

End of funcDon

DuringOffense(Event)

Set ReturnEvent to Event


If EventType of Event is ES_ENTRY or EventType of Event is ES_ENTRY_HISTORY
Declare ScoreEvent of type ES_EVENT_t
Set EventType of ScoreEvent as EV_SCORE_UPDATE
Call PostMasterSM with parameter ScoreEvent
Call StartOffenseSM with parameter Event
Elseif EventType of Event is ES_EXIT
Call RunOffenseSM funcDon with parameter Event and set
ReturnEvent to its return value
Else
Call RunOffenseSM funcDon with parameter Event and set
ReturnEvent to its return value
Endif

Return ReturnEvent

End of funcDon

DuringDefense(Event)

Set ReturnEvent to Event


If EventType of Event is ES_ENTRY or EventType of Event is ES_ENTRY_HISTORY
Call StartDefenseSM with parameter Event
Elseif EventType of Event is ES_EXIT
Call RunDefenseSM with parameter Event
Else
Call RunDefenseSM funcDon with parameter Event and set
ReturnEvent to its return value
Endif

Return ReturnEvent

End of funcDon

DuringDuringGameOver(Event)

Set ReturnEvent to Event


If EventType of Event is ES_ENTRY or EventType of Event is ES_ENTRY_HISTORY
Turn off LED
Lower flag
Elseif EventType of Event is ES_EXIT

Else

Endif

Return ReturnEvent

End of funcDon

DuringOverDme(Event)

Set ReturnEvent to Event


If EventType of Event is ES_ENTRY or EventType of Event is ES_ENTRY_HISTORY
Set EventParam of Event to OVERTIME_FLAG
Call StartReloadingSM funcDon with parameter Event
Elseif EventType of Event is ES_EXIT
Call RunReloadingSM funcDon with parameter Event
Else
Call RunReloadingSM funcDon with parameter Event and set
ReturnEvent to its return value
Endif

Return ReturnEvent

End of funcDon

OverDme_ISR

Clear source of interrupt


Start GAME_TIMER for 32.5 seconds

End of funcDon

Goal_Beacon_ISR

Declare ThisCapture as type uint32_t


Clear source of interrupt
Set ThisCapture to captured value
Set Period to ThisCapture - LastCaptureGoal

If (TeamColor is RedTeam AND absolute value of (Period -


RED_ATTACK_GOAL_PERIOD) is less than PERIOD_ERROR) OR
(TeamColor is BlueTeam AND absolute value of (Period -
BLUE_ATTACK_GOAL_PERIOD) is less than PERIOD_ERROR)
Increment NumGoalEdges by 1
If NumGoalEdges is greater than REQ_NUM_EDGES
Declare ThisEvent as type ES_Event_t
Set EventType of ThisEvent to EV_ATTACK_GOAL_DETECTED
Call PostMasterSM with parameter ThisEvent
Endif
Endif

Set LastCaptureGoal to ThisCapture

End of funcDon

Reload_Beacon_ISR

Declare ThisCapture as type uint32_t


Clear source of interrupt
Set ThisCapture to captured value
Set Period to ThisCapture - LastCaptureGoal

If (TeamColor is RedTeam AND absolute value of (Period -


RED_RELOAD_GOAL_PERIOD) is less than PERIOD_ERROR) OR
(TeamColor is BlueTeam AND absolute value of (Period -
BLUE_RELOAD_GOAL_PERIOD) is less than PERIOD_ERROR)
Increment NumGoalEdges by 1
If NumGoalEdges is greater than REQ_NUM_EDGES
Declare ThisEvent as type ES_Event_t
Set EventType of ThisEvent to EV_RELOADER_DETECTED
Call PostMasterSM with parameter ThisEvent
Endif
Endif

If (TeamColor is RedTeam AND absolute value of (Period -


BLUE_RELOAD_GOAL_PERIOD) is less than PERIOD_ERROR) OR
(TeamColor is BlueTeam AND absolute value of (Period -
RED_RELOAD_GOAL_PERIOD) is less than PERIOD_ERROR)
Increment NumGoalEdges by 1
If NumGoalEdges is greater than REQ_NUM_EDGES
Declare ThisEvent as type ES_Event_t
Set EventType of ThisEvent to EV_OPPONENT_RELOADER_DETECTED
Call PostMasterSM with parameter ThisEvent
Endif
Endif

If (TeamColor is RedTeam AND absolute value of (Period -


BLUE_ATTACK_GOAL_PERIOD) is less than PERIOD_ERROR) OR
(TeamColor is BlueTeam AND absolute value of (Period -
RED_ATTACK_GOAL_PERIOD) is less than PERIOD_ERROR)
Increment NumGoalEdges by 1
If NumGoalEdges is greater than REQ_NUM_EDGES
Declare ThisEvent as type ES_Event_t
Set EventType of ThisEvent to EV_DEFEND_GOAL_DETECTED
Call PostMasterSM with parameter ThisEvent
Endif
Endif

Set LastCaptureReload to ThisCapture

End of funcDon

You might also like