/****************************************************************************
Module
Round3DriveSM.c
Revision
2.0.1
Description
This is a template file for implementing state machines.
/*---------------------------- Module Variables ---------------------------*/
// everybody needs a state variable, you may need others as well
CurrentState;
/*------------------------------ Module Code ------------------------------*/
/****************************************************************************
Function
RunRound3DriveSM
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
****************************************************************************/
switch CurrentState
case ST_DriveToBTape
run during function for this state
//process any events
switch event type
case ES_TIMEOUT
if event paramter is PID_TIMER
PD Control Driving Forward
Init PID Timer
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
else if event paramter is ULTRASONIC_TIMER
Query Distance to front wall
if within range
Set NextState to ST_TurnToGoal;
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
Mark that we are making state transition
if not within range
start ULTRASONIC_TIMER
end switch event type
case ST_TurnToGoal
run during function for this state
switch (CurrentEvent.EventType)
{
switch event type
case ES_TIMEOUT
if event paramter is TURN_TIMER
Set NextState to ST_Shoot
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
Mark that we are making state transition
end switch event type
case ST_Shoot:
run during function for this state
switch (CurrentEvent.EventType)
{
switch event type
case ES_TIMEOUT
if event paramter is SHOOTING_TIMER
Set NextState to ST_TurnToWire
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
Mark that we are making state transition
end switch event type
case ST_TurnToWire:
run during function for this state
switch (CurrentEvent.EventType)
{
switch event type
case ES_TIMEOUT
if event paramter is TURN_TIMER
Set NextState to ST_BounceToATape
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
Mark that we are making state transition
end switch event type
case ST_BounceToATape:
run during function for this state
//process any events
switch event type
case ES_TIMEOUT
if event paramter is PID_TIMER
PD Control Driving Backward
Init PID Timer
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
else if event paramter is ULTRASONIC_TIMER
Query Distance to back wall
if within range
Set NextState to ST_BounceToBTape;
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
Mark that we are making state transition
if not within range
start ULTRASONIC_TIMER
end switch event type
case ST_BounceToBTape:
run during function for this state
//process any events
switch event type
case ES_TIMEOUT
if event paramter is PID_TIMER
PD Control Driving Forward
Init PID Timer
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
else if event paramter is ULTRASONIC_TIMER
Query Distance to front wall
if within range
Set NextState to ST_BounceToATape;
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
Mark that we are making state transition
if not within range
start ULTRASONIC_TIMER
end switch event type
case ST_DrivingToB:
run the during function for this state
end switch CurrentState
if we are making a state transition
Execute exit function for current state
Set CurrentState to NextState
Set CurrentState Event type to ES_ENTRY and run entry function for the new state
/****************************************************************************
Function
StartRound3DriveSM
Parameters
None
Returns
None
Description
Does any required initialization for this state machine
Notes
Author
J. Edward Carryer, 2/18/99, 10:38AM
****************************************************************************/
if not entering in ES_ENTRY_HISTORY
Set CurrentState to ST_DriveToBTape
run entry function for the current state
/****************************************************************************
Function
QueryRound3DriveSM
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
***************************************************************************/
/**********************************************************************/
DuringDriveToBTape
/**********************************************************************/
// process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Post a Joust Event to MasterSM
Drive forward
Start PID timer
Start ULTRASONIC timer
if the event type is ES_EXIT
StopMotor
/**********************************************************************/
DuringTurnToGoal
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Start turning
Start launcher motor
Start TURN_TIMER
if the event type is ES_EXIT
StopMotor
/**********************************************************************/
DuringShooting
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Open gate and turn on launcher motor
Start SHOOTING_TIMER
if the event type is ES_EXIT
Turn Off launcher and close gate
/**********************************************************************/
DuringTurnToWire
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Start turning clockwie
Start TURN_TIMER
if the event type is ES_EXIT
stop motors
/**********************************************************************/
DuringBounceToATape
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Post Joust event to MasterSM
Drive backward
Start PID_TIMER
Start ULTRASONIC_TIMER
if the event type is ES_EXIT
stop motors
/**********************************************************************/
DuringBounceToBTape
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Post Joust event to MasterSM
Drive forward
Start PID_TIMER
Start ULTRASONIC_TIMER
if the event type is ES_EXIT
stop motors
/**********************************************************************/
DuringDrivingToB
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Start SimpleDriveToB state machine
if the event type is ES_EXIT
stop motors
Module
Round3DriveSM.c
Revision
2.0.1
Description
This is a template file for implementing state machines.
/*---------------------------- Module Variables ---------------------------*/
// everybody needs a state variable, you may need others as well
CurrentState;
/*------------------------------ Module Code ------------------------------*/
/****************************************************************************
Function
RunRound3DriveSM
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
****************************************************************************/
switch CurrentState
case ST_DriveToBTape
run during function for this state
//process any events
switch event type
case ES_TIMEOUT
if event paramter is PID_TIMER
PD Control Driving Forward
Init PID Timer
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
else if event paramter is ULTRASONIC_TIMER
Query Distance to front wall
if within range
Set NextState to ST_TurnToGoal;
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
Mark that we are making state transition
if not within range
start ULTRASONIC_TIMER
end switch event type
case ST_TurnToGoal
run during function for this state
switch (CurrentEvent.EventType)
{
switch event type
case ES_TIMEOUT
if event paramter is TURN_TIMER
Set NextState to ST_Shoot
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
Mark that we are making state transition
end switch event type
case ST_Shoot:
run during function for this state
switch (CurrentEvent.EventType)
{
switch event type
case ES_TIMEOUT
if event paramter is SHOOTING_TIMER
Set NextState to ST_TurnToWire
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
Mark that we are making state transition
end switch event type
case ST_TurnToWire:
run during function for this state
switch (CurrentEvent.EventType)
{
switch event type
case ES_TIMEOUT
if event paramter is TURN_TIMER
Set NextState to ST_BounceToATape
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
Mark that we are making state transition
end switch event type
case ST_BounceToATape:
run during function for this state
//process any events
switch event type
case ES_TIMEOUT
if event paramter is PID_TIMER
PD Control Driving Backward
Init PID Timer
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
else if event paramter is ULTRASONIC_TIMER
Query Distance to back wall
if within range
Set NextState to ST_BounceToBTape;
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
Mark that we are making state transition
if not within range
start ULTRASONIC_TIMER
end switch event type
case ST_BounceToBTape:
run during function for this state
//process any events
switch event type
case ES_TIMEOUT
if event paramter is PID_TIMER
PD Control Driving Forward
Init PID Timer
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
else if event paramter is ULTRASONIC_TIMER
Query Distance to front wall
if within range
Set NextState to ST_BounceToATape;
set ReturnEvent to ES_NO_EVENT to disable event re-mapping
Mark that we are making state transition
if not within range
start ULTRASONIC_TIMER
end switch event type
case ST_DrivingToB:
run the during function for this state
end switch CurrentState
if we are making a state transition
Execute exit function for current state
Set CurrentState to NextState
Set CurrentState Event type to ES_ENTRY and run entry function for the new state
/****************************************************************************
Function
StartRound3DriveSM
Parameters
None
Returns
None
Description
Does any required initialization for this state machine
Notes
Author
J. Edward Carryer, 2/18/99, 10:38AM
****************************************************************************/
if not entering in ES_ENTRY_HISTORY
Set CurrentState to ST_DriveToBTape
run entry function for the current state
/****************************************************************************
Function
QueryRound3DriveSM
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
***************************************************************************/
/**********************************************************************/
DuringDriveToBTape
/**********************************************************************/
// process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Post a Joust Event to MasterSM
Drive forward
Start PID timer
Start ULTRASONIC timer
if the event type is ES_EXIT
StopMotor
/**********************************************************************/
DuringTurnToGoal
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Start turning
Start launcher motor
Start TURN_TIMER
if the event type is ES_EXIT
StopMotor
/**********************************************************************/
DuringShooting
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Open gate and turn on launcher motor
Start SHOOTING_TIMER
if the event type is ES_EXIT
Turn Off launcher and close gate
/**********************************************************************/
DuringTurnToWire
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Start turning clockwie
Start TURN_TIMER
if the event type is ES_EXIT
stop motors
/**********************************************************************/
DuringBounceToATape
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Post Joust event to MasterSM
Drive backward
Start PID_TIMER
Start ULTRASONIC_TIMER
if the event type is ES_EXIT
stop motors
/**********************************************************************/
DuringBounceToBTape
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Post Joust event to MasterSM
Drive forward
Start PID_TIMER
Start ULTRASONIC_TIMER
if the event type is ES_EXIT
stop motors
/**********************************************************************/
DuringDrivingToB
/**********************************************************************/
if the event type is ES_ENTRY or ES_ENTRY_HISTORY
Start SimpleDriveToB state machine
if the event type is ES_EXIT
stop motors