/****************************************************************************
Module
Recess2SM.c
Revision
2.0.1
Description
This is a template file for implementing state machines.
Notes
****************************************************************************/
/*---------------------------- Module Variables ---------------------------*/
// everybody needs a state variable, you may need others as well
CurrentState;
/*------------------------------ Module Code ------------------------------*/
/****************************************************************************
Function
RunRound2DriveSM
Parameters
ES_Event: the event to process
Returns
ES_Event: an event to return
Description
add your description here
Notes
uses nested switch/case to implement the machine.
Author
J. Edward Carryer, 2/11/05, 10:45AM
****************************************************************************/
ES_Event RunRecess2SM( ES_Event CurrentEvent )
{
switch CurrentState
case ST_DrivingToA
run during function for current state
switch event type
case EV_BACK_WALL_REACHED
Set NextState to ST_WaitToReload
Mark that we are taking a transition
end switch event type
case ST_WaitToReload
run during function for current state
switch event type
case ES_TIMEOUT
if event parameter is RELOAD_TIMER
Set NextState to ST_RequestingBall
Mark that we are taking a transition
end switch event type
case ST_RequestingBall
run during function for current state
switch event type
case ES_TIMEOUT
if event parameter is RELOAD_TIMER
Set NextState to ST_WaitingForBall
Mark that we are taking a transition
end switch event type
case ST_WaitingForBall:
run during function for current state
switch event type
case ES_TIMEOUT
if event parameter is RELOAD_TIMER
Set NextState to ST_RequestingBall
Mark that we are taking a transition
end switch event type
end switch CurrentState
if we are making a state transition
Execute exit function for current state
Set CurrentState to NextState
Execute entry function for the new current state
/****************************************************************************
Function
StartRound2DriveSM
Parameters
None
Returns
None
Description
Does any required initialization for this state machine
Notes
Author
J. Edward Carryer, 2/18/99, 10:38AM
****************************************************************************/
void StartRecess2SM ( ES_Event CurrentEvent )
{
// local variable to get debugger to display the value of CurrentEvent
ES_Event LocalEvent = CurrentEvent;
// to implement entry to a history state or directly to a substate
// you can modify the initialization of the CurrentState variable
// otherwise just start in the entry state every time the state machine
// is started
if ( ES_ENTRY_HISTORY != CurrentEvent.EventType )
{
SimpleDriveToAState_t simpleToAState = QuerySimpleDriveToASM();
if(simpleToAState == ST_DriveToA){
CurrentState = ST_DrivingToA;
}else{
CurrentState = ST_WaitToReload;
}
}
// call the entry function (if any) for the ENTRY_STATE
RunRecess2SM(CurrentEvent);
}
/****************************************************************************
Function
QueryRound2DriveSM
Parameters
None
Returns
TemplateState_t The current state of the Template state machine
Description
returns the current state of the Template state machine
Notes
Author
J. Edward Carryer, 2/11/05, 10:38AM
****************************************************************************/
return CurrentState
/***************************************************************************
private functions
***************************************************************************/
/**********************************************************************/
DuringDrivingToA
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Start SimpleDriveToA state machine
if the event type is ES_EXIT
run exit function on the lower level state machine and allow re-mapping of the event
else
run the lower level state machine and allow re-mapping of the event
/**********************************************************************/
DuringWaitToReload
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Start RELOAD_TIMER
/**********************************************************************/
DuringRequestingBall
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
if allow to reload
Turn on the reload IR LED array
start RELOAD_TIMER
if the event type is ES_EXIT
turn off reload IR LED array
/**********************************************************************/
DuringRequestingBall
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
start RELOAD_TIMER
Module
Recess2SM.c
Revision
2.0.1
Description
This is a template file for implementing state machines.
Notes
****************************************************************************/
/*---------------------------- Module Variables ---------------------------*/
// everybody needs a state variable, you may need others as well
CurrentState;
/*------------------------------ Module Code ------------------------------*/
/****************************************************************************
Function
RunRound2DriveSM
Parameters
ES_Event: the event to process
Returns
ES_Event: an event to return
Description
add your description here
Notes
uses nested switch/case to implement the machine.
Author
J. Edward Carryer, 2/11/05, 10:45AM
****************************************************************************/
ES_Event RunRecess2SM( ES_Event CurrentEvent )
{
switch CurrentState
case ST_DrivingToA
run during function for current state
switch event type
case EV_BACK_WALL_REACHED
Set NextState to ST_WaitToReload
Mark that we are taking a transition
end switch event type
case ST_WaitToReload
run during function for current state
switch event type
case ES_TIMEOUT
if event parameter is RELOAD_TIMER
Set NextState to ST_RequestingBall
Mark that we are taking a transition
end switch event type
case ST_RequestingBall
run during function for current state
switch event type
case ES_TIMEOUT
if event parameter is RELOAD_TIMER
Set NextState to ST_WaitingForBall
Mark that we are taking a transition
end switch event type
case ST_WaitingForBall:
run during function for current state
switch event type
case ES_TIMEOUT
if event parameter is RELOAD_TIMER
Set NextState to ST_RequestingBall
Mark that we are taking a transition
end switch event type
end switch CurrentState
if we are making a state transition
Execute exit function for current state
Set CurrentState to NextState
Execute entry function for the new current state
/****************************************************************************
Function
StartRound2DriveSM
Parameters
None
Returns
None
Description
Does any required initialization for this state machine
Notes
Author
J. Edward Carryer, 2/18/99, 10:38AM
****************************************************************************/
void StartRecess2SM ( ES_Event CurrentEvent )
{
// local variable to get debugger to display the value of CurrentEvent
ES_Event LocalEvent = CurrentEvent;
// to implement entry to a history state or directly to a substate
// you can modify the initialization of the CurrentState variable
// otherwise just start in the entry state every time the state machine
// is started
if ( ES_ENTRY_HISTORY != CurrentEvent.EventType )
{
SimpleDriveToAState_t simpleToAState = QuerySimpleDriveToASM();
if(simpleToAState == ST_DriveToA){
CurrentState = ST_DrivingToA;
}else{
CurrentState = ST_WaitToReload;
}
}
// call the entry function (if any) for the ENTRY_STATE
RunRecess2SM(CurrentEvent);
}
/****************************************************************************
Function
QueryRound2DriveSM
Parameters
None
Returns
TemplateState_t The current state of the Template state machine
Description
returns the current state of the Template state machine
Notes
Author
J. Edward Carryer, 2/11/05, 10:38AM
****************************************************************************/
return CurrentState
/***************************************************************************
private functions
***************************************************************************/
/**********************************************************************/
DuringDrivingToA
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Start SimpleDriveToA state machine
if the event type is ES_EXIT
run exit function on the lower level state machine and allow re-mapping of the event
else
run the lower level state machine and allow re-mapping of the event
/**********************************************************************/
DuringWaitToReload
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Start RELOAD_TIMER
/**********************************************************************/
DuringRequestingBall
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
if allow to reload
Turn on the reload IR LED array
start RELOAD_TIMER
if the event type is ES_EXIT
turn off reload IR LED array
/**********************************************************************/
DuringRequestingBall
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
start RELOAD_TIMER