/****************************************************************************
Module
SimpleDriveToBSM.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
RunSimpleDriveToBSM
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
Chih-Wei Tang, 2/11/05, 10:45AM
****************************************************************************/
initialize leftDriveSpeed, rightDriveSpeed, currentKp, currentKd
switch CurrentState
case ST_DriveToB
run during function for this state
switch EventType
case EV_FRONT_WALL_REACHED
set ST_Stop_B as NextState
mark that we are taking a transition
consume return event
case ES_TIMEOUT
if event parameter is PID_TIMER
PD Control Driving Forward
reset and start PID_TIMER
consume return event
}
if event parameter is ULTRASONIC_TIMER
Check if in range of wall in front and rear
query game state from GameSM
set matchUnderway according to the game state
if in range
slow down for leftDriveSpeed and rightDriveSpeed
adjust Kp, Kd
if not in range
start Ultrasonic Timer
if pass the red tape and the match is underway
sent event EV_START_JOUSTING to the MasterSM
end switch event type
case ST_Stop_B
run during function for this state
end switch CurrentEvent
If we are making a state transition
Execute exit function for current state
set NextState as CurrentState
set ES_ENTRY as event type of CurrentEvent
run entry function for the current state
/****************************************************************************
Function
StartSimpleDriveToBSM
Parameters
None
Returns
None
Description
Does any required initialization for this state machine
Notes
Author
Chih-Wei Tang, 2/18/99, 10:38AM
****************************************************************************/
if not entering in ES_ENTRY_HISTORY type
set CurrentEvent to ST_DriveToA
call entry function for the state
/****************************************************************************
Function
QueryTemplateSM
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
***************************************************************************/
/******************************************************/
DuringDriveToB
/******************************************************/
if entering as ES_ENTRY_HISTORY or ES_ENTRY
start PID timer
drive forward
Start Ultrasonic Timer
if event type ES_EXIT
StopMotor();
/******************************************************/
DuringStop
/******************************************************/
No during function for this state
Module
SimpleDriveToBSM.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
RunSimpleDriveToBSM
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
Chih-Wei Tang, 2/11/05, 10:45AM
****************************************************************************/
initialize leftDriveSpeed, rightDriveSpeed, currentKp, currentKd
switch CurrentState
case ST_DriveToB
run during function for this state
switch EventType
case EV_FRONT_WALL_REACHED
set ST_Stop_B as NextState
mark that we are taking a transition
consume return event
case ES_TIMEOUT
if event parameter is PID_TIMER
PD Control Driving Forward
reset and start PID_TIMER
consume return event
}
if event parameter is ULTRASONIC_TIMER
Check if in range of wall in front and rear
query game state from GameSM
set matchUnderway according to the game state
if in range
slow down for leftDriveSpeed and rightDriveSpeed
adjust Kp, Kd
if not in range
start Ultrasonic Timer
if pass the red tape and the match is underway
sent event EV_START_JOUSTING to the MasterSM
end switch event type
case ST_Stop_B
run during function for this state
end switch CurrentEvent
If we are making a state transition
Execute exit function for current state
set NextState as CurrentState
set ES_ENTRY as event type of CurrentEvent
run entry function for the current state
/****************************************************************************
Function
StartSimpleDriveToBSM
Parameters
None
Returns
None
Description
Does any required initialization for this state machine
Notes
Author
Chih-Wei Tang, 2/18/99, 10:38AM
****************************************************************************/
if not entering in ES_ENTRY_HISTORY type
set CurrentEvent to ST_DriveToA
call entry function for the state
/****************************************************************************
Function
QueryTemplateSM
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
***************************************************************************/
/******************************************************/
DuringDriveToB
/******************************************************/
if entering as ES_ENTRY_HISTORY or ES_ENTRY
start PID timer
drive forward
Start Ultrasonic Timer
if event type ES_EXIT
StopMotor();
/******************************************************/
DuringStop
/******************************************************/
No during function for this state