Sei sulla pagina 1di 3

Module level functions

DuringDrive4Offset
DuringWait4Reload

Module level variables:


CurrentState, TEAM

RunDefenseSM

set MakeTransition to false


set NextState to CurrentState
default EntryEventKind to normal entry to new state
assume we are not consuming event

If current state is DefDrive4Offense


Execute During function for this state. ES_ENTRY & ES_EXIT are
processed here allow the lower level state machines to re-map
or consume the event

process any events


If an event is active
If this event is EV_Y_TARGET_REACHED
stop the robot
Decide the next state to be Wait4Reload
for internal transitions, skip changing MakeTransition
mark that we are taking a transition
if transitioning to a state with history change kind of entry
optionally, consume or re-map this event for the upper
level state machine
end of this block
end of this block

If current state is Wait4Reload


Execute During function for state one. ES_ENTRY & ES_EXIT are
processed here allow the lower level state machines to re-map
or consume the event

process any events


If an event is active
If this event is ES_TIMEOUT from SHOTCLK
Decide the next state to be Wait4Reload
for internal transitions, skip changing MakeTransition
mark that we are not taking a transition
if transitioning to a state with history change kind of entry
optionally, consume or re-map this event for the upper
level state machine
we return EV_DEFENSE_RELOAD to upper level machine
so that we can transite to FaceOff state to reload
end of this block
end of this block

If we are making a state transition


Execute exit function for current state
Modify state variable

Execute entry function for new state


this defaults to ES_ENTRY
return ReturnEvent
End of RunDefenseSM

StartDefenseSM
set CurrentState to ENTRY_STATE
grab team color info
call the entry function (if any) for the ENTRY_STATE
End of StartDefenseSM

QueryDefenseSM
Return CurrentState

/***************************************************************************
private functions
***************************************************************************/
DuringDrive4Offset

assume no re-mapping or consumption

process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events


If ES_ENTRY
implement any entry actions required for this state machine
upon entering this state, we start a timer and start to drive the
robot

set the robot to move backward to (P5X, P5Y) which is roughly


the center of the field so that we can go to reload station later

If ES_EXIT
on exit, give the lower levels a chance to clean up first
now do any local exit functionality

else
do the 'during' function for this state
run any lower level state machine

return either Event, if you don't want to allow the lower level machine
to remap the current event, or ReturnEvent if you do want to allow it.
End of DuringDrive4Offset

DuringWait4Reload

assume no re-mapping or consumption

process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events


If ES_ENTRY
implement any entry actions required for this state machine
upon entering this state, we start a timer and start to drive the
robot

Start Timer for waiting for reload

If ES_EXIT
on exit, give the lower levels a chance to clean up first
now do any local exit functionality

else
do the 'during' function for this state
run any lower level state machine

return either Event, if you don't want to allow the lower level
machine
to remap the current event, or ReturnEvent if you do want to allow
it.
End of DuringWait4Reload

Potrebbero piacerti anche