0% found this document useful (0 votes)
128 views4 pages

Gameplay HSM Pseudo Code

1. The document defines functions and variables for a state machine that controls a propeller bot. 2. The RunGameplaySM function implements the state machine logic, switching between states like ALIGN_STATE, TAPE_FOLLOW_FORWARD_STATE, and handling different events. 3. Auxiliary functions like DuringAlign, DuringInRepo, and DuringTapeFollowForward are called to perform actions during state transitions and handle state-specific events.

Uploaded by

api-644185248
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views4 pages

Gameplay HSM Pseudo Code

1. The document defines functions and variables for a state machine that controls a propeller bot. 2. The RunGameplaySM function implements the state machine logic, switching between states like ALIGN_STATE, TAPE_FOLLOW_FORWARD_STATE, and handling different events. 3. Auxiliary functions like DuringAlign, DuringInRepo, and DuringTapeFollowForward are called to perform actions during state transitions and handle state-specific events.

Uploaded by

api-644185248
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Gameplay_HSM.

c
Define OPTO_CHECK_TIME and PUSH_TIME variables
Module level function definitions
Module level variables: CurrentState with type GameplayState_t

RunGameplaySM
Returns ES_NO_EVENT if no errors

Set MakeTransistion boolean to false


Set local next state variable to CurrentState
Set entry event kind to the default ES_ENTRY
Set return event to ES_NO_EVENT
Switch statement with CurrentState variable
CurrentState is ALIGN_STATE
Set CurrentEvent to the return value from the DuringAlign
function, passing CurrentEvent to DuringAlign
If there is an event, enter the switch statement with
CurrentEvent.EventType
ALIGNED event
Set NextState to TAPE_FOLLOW_FORWARD_STATE
Set MakeTransistion to true
Consume the event by setting ReturnEvent to ES_NO_EVENT
End ALIGNED event
End of ALIGN_STATE
CurrentState is IN_REPO_STATE
Set CurrentEvent to the return value from the DuringInRepo
function, passing CurrentEvent to DuringInRepo
BRANCH_FOUND event
Set NextState to TAPE_FOLLOW_FORWARD_STATE
Set MakeTransistion to true
Consume the event by setting ReturnEvent to ES_NO_EVENT
End BRANCH_FOUND event
End of IN_REPO_STATE
CurrentState is TAPE_FOLLOW_FORWARD_STATE
Set CurrentEvent to the return value from the
DuringTapeFollowForward function, passing CurrentEvent to
DuringTapeFollowForward
ES_TIMEOUT event
If the opto timer expired
If left opto sees tape, send command to follower to
adjust left duty cycle
If right opto sees tape, send command to follower to
adjust right duty cycle
If right and left opto do not see tape, send command
to follower to drive forward
Re-initialize OPTO_CHECK timer
Consume the event by setting ReturnEvent to
ES_NO_EVENT
If tape following push timer expires
Set NextState to TAPE_FOLLOW_REVERSE_STATE
Set MakeTransistion to true
Consume the event by setting ReturnEvent to
ES_NO_EVENT
End ES_TIMEOUT event
End of TAPE_FOLLOW_FORWARD_STATE
CurrentState is TAPE_FOLLOW_REVERSE_STATE
Set CurrentEvent to the return value from the
DuringTapeFollowReverse function, passing CurrentEvent to
DuringTapeFollowReverse
ES_TIMEOUT event
If the opto timer expired
If left opto sees tape, send command to follower to
adjust left duty cycle
If right opto sees tape, send command to follower to
adjust right duty cycle
If right and left opto do not see tape, send command
to follower to drive reverse
Re-initialize OPTO_CHECK timer
Consume the event by setting ReturnEvent to
ES_NO_EVENT
End ES_TIMEOUT event
LIMIT_SWITCH_HIT event
Send command to follower to stop motors
Set NextState to IN_REPO_STATE
Consume the event by setting ReturnEvent to ES_NO_EVENT
End LIMIT_SWITCH_HIT event
End of TAPE_FOLLOW_REVERSE_STATE
If MakeTransistion is true
Post an ES_EXIT event to the propeller bot service
Update the CurrentState variable to NextState
Recursively call RunGameplaySM
Return the ReturnEvent variable
End of RunGameplaySM

StartGameplaySM
Takes an event as a parameter

Initialize the CurrentState variable to ALIGN_STATE


Call RunGameplaySM and pass the CurrentEvent variable
End of StartGameplaySM
QueryGameplaySM
Returns the CurrentState, module level variable of type
GameplayState_t
End of QueryGameplaySM

DuringAlign
Takes an event as a parameter and returns an event
Set the ReturnEvent to the event that was passed into the function
If the event is ES_ENTRY
Call the StartAlignSM function
Else if the event is ES_EXIT
Call the RunAlignSM function
Else set the ReturnEvent variable to the returned value from the
RunAlignSM
Return ReturnEvent
End of DuringAlign

DuringInRepo
Takes an event as a parameter and returns an event
Set the ReturnEvent to the event that was passed into the function
If the event is ES_ENTRY
Send command to follower to turn on green interaction LED
Initialize the button timer (how often to check button between
presses)
Call the StartInRepoSM function
Else if the event is ES_EXIT
Call the RunInRepoSM function
Send command to follower to turn off green interaction LED
Else set the ReturnEvent variable to the returned value from the
RunInRepoSM
Return ReturnEvent
End of DuringInRepo

DuringTapeFollowForward
Takes an event as a parameter and returns an event
Set the ReturnEvent to the event that was passed into the function
If the event is ES_ENTRY
Send command to follower to drive forwards
Initialize the push timer
Initialize the check opto timer
Else if the event is ES_EXIT
Send command to follower to communicate the end of tape following
forward
Return ReturnEvent
End of DuringTapeFollowForward
DuringTapeFollowReverse
Takes an event as a parameter and returns an event
Set the ReturnEvent to the event that was passed into the function
If the event is ES_ENTRY
Initialize the check opto timer
Return ReturnEvent
End of DuringTapeFollowForward

You might also like