playing_sm Module
Files:
Interface
Function: StartPlayingSM
Arguments: None.
Returns: None.
Does any required initialization for the playing state machine.
Function: RunPlayingSM
Arguments: Event_t: the event to process.
Returns: Event_t: an event to return.
Runs the tasks for the playing state machine.
Function: QueryPlayingSM
Arguments: None.
Returns: PlayingState_t The current state of the master state machine.
Runs the tasks for the playing state machine.
Pseudo-Code
StartPlayingSM Call RunPlayingSM(EV_ENTRY)
RunPlayingSM(Takes an Event_t and returns new Event_t)
Set static variable FlagsCaptured to 0
Initialize MakeTransition to FALSE
Set NextState to CurrentState
Switch between values of CurrentState:
If value is INITIAL_MVOING:
Call DuringInitialMoving(CurrentEvent) and store the return in CurrentEvent
Switch between values of CurrentEvent:
if value is EV_FLAG_SENSED:
Set NextState to HEADING_FOR_FLAG
Set MakeTransition to TRUE
Endif
Endswitch
Endif
If value is HEADING_FOR_FLAG:
Call DuringHeadingForFlag(CurrentEvent) and store the return in CurrentEvent
Switch between values of CurrentEvent:
if value is EV_GATE_BLOCKED:
Set NextState to CAPTURING_FLAG
Set MakeTransition to TRUE
Endif
if value is EV_FLAG_LOST:
Set NextState to LOOKING_FOR_FLAG
Set MakeTransition to TRUE
Endif
if value is EV_WARNING_TIMER_DONE:
Set NextState to GOING_TO_GOAL
Set MakeTransition to TRUE
Endif
Endswitch
Endif
If value is CAPTURING_FLAG:
Call DuringCapturingFlag(CurrentEvent) and store the return in CurrentEvent
Switch between values of CurrentEvent:
if value is EV_CAPTURING_TIMER_DONE:
Increment FlagsCaptured
If FlagsCaptured equals 3:
Set NextState to GOING_TO_GOAL
Else:
Set NextState to LOOKING_FOR_FLAG
Endif
Set MakeTransition to TRUE
Endif
if value is EV_FLAG_LOST:
Set NextState to LOOKING_FOR_FLAG
Set MakeTransition to TRUE
Endif
if value is EV_WARNING_TIMER_DONE:
Set NextState to GOING_TO_GOAL
Set MakeTransition to TRUE
Endif
Endswitch
Endif
If value is LOOKING_FOR_FLAG:
Call DuringLookingForFlag(CurrentEvent) and store the return in CurrentEvent
Switch between values of CurrentEvent:
if value is EV_GATE_BLOCKED:
Set NextState to CAPTURING_FLAG
Set MakeTransition to TRUE
Endif
if value is EV_FLAG_SENSED:
Set NextState to HEADING_FOR_FLAG
Set MakeTransition to TRUE
Endif
if value is EV_WARNING_TIMER_DONE:
Set NextState to GOING_TO_GOAL
Set MakeTransition to TRUE
Endif
Endswitch
Endif
If value is GOING_TO_GOAL:
Call DuringGoingToGoal(CurrentEvent) and store the return in CurrentEvent
Endif
Endswitch
If MakeTransition is TRUE:
Call RunPlayingSM(EV_EXIT)
Set CurrentState to NextState
Call RunPlayingSM(EV_ENTRY)
Endif
return CurrentEvent
QueryPlayingSM(Returns current PlayingState_t) return module variable CurrentState
DuringInitialMoving(Takes current event Event_t, returns new event Event_t)
If the event is EV_ENTRY:
Move straight
Endif
Return same event
DuringHeadingForFlag(Takes current event Event_t, returns new event Event_t)
If the event is not EV_ENTRY or EV_EXIT:
Call beacon moving control law
Endif
Return new event
DuringCapturingFlag(Takes current event Event_t, returns new event Event_t)
If the event is EV_ENTRY:
Move straight
Endif
Return same event
DuringGoingToGoal(Takes current event Event_t, returns new event Event_t)
If the event is EV_ENTRY:
Call StartGoalFindingSM()
Else:
Call RunGoalFindingSM(event) and store the return vale as the new event
Endif
Return the new event
DuringLookingForFlag(Takes current event Event_t, returns new event Event_t)
If the event is EV_ENTRY:
Turn left
Endif
Return same event