/****************************************************************************
Module
JoustSM.c
Revision
2.0.1
/*---------------------------- Module Variables ---------------------------*/
CurrentState;
/*------------------------------ Module Code ------------------------------*/
/****************************************************************************
Function
RunJoustSM
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
****************************************************************************/
initialize static variable position
switch on CurrentState
case ST_Retracted
call the during function for this state
if the event is EV_START_JOUSTING
set NextState to ST_Deployed
mark that we are making state transition
set the return event type to ES_NO_EVENT
case ST_Deployed
call the during function for this state
if the event is ES_TIMEOUT
if the event parameter is JOUST_TIMER
set NextState to ST_HonorablePause
mark that we are making state transition
set the return event type to ES_NO_EVENT
else if the event parameter is SWING_TIMER and the current joust position is FORWARD_POSITION
adjust swing servo to backward
update position to BACKWARD_POSITION
else
adjust swing servo to forward swinging
update position to FORWARD_POSITION
start the timer for SWING_TIMER
case ST_HonorablePause
call the during function for this state
if the event is ES_TIMEOUT
if the event parameter is HONORABLE_PAUSE_TIMER
set NextState to ST_Retracted
mark that we are making state transition
set the return event type to ES_NO_EVENT
else if the event parameter is SWING_TIMER
Retract the jousting lance
end switch on CurrentState
if we are making state transition
Set the event type of CurrentEvent to ES_EXIT
Pass the CurrentEvent to the current RunJoustSM
Set the NextState to CurrentState
Run entry functions for the new state
/****************************************************************************
Function
StartJoustSM
Parameters
None
Returns
None
Description
Does any required initialization for this state machine
Notes
Author
J. Edward Carryer, 2/18/99, 10:38AM
****************************************************************************/
Set the CurrentState to ST_Retracted
Pass the CurrentState into the RunJoustSM function to call the entry function
/****************************************************************************
Function
QueryJoustSM
Parameters
None
Returns
JoustState_t The current state of the JoustSM
Description
returns the current state of the JoustSM
Notes
Author
J. Edward Carryer, 2/11/05, 10:38AM
****************************************************************************/
return the CurrentEvent
/***************************************************************************
/**************************************************************************/
DuringRetracted
/**************************************************************************/
No during functions for this state
return the event
/**************************************************************************/
DuringDeployed
/**************************************************************************/
if entry event
start Joust timer for deploy interval
start swing timer for swinging
set lance position to DEPLOYED_POSITION
set swing servo position to FORWARD_POSITION
else if ES_EXIT event
set swing servo to FORWARD_POSITION
start timer SWING_TIMER
start timer HONORABLE_PAUSE_TIMER
/**************************************************************************/
DuringHonorablePause
/**************************************************************************/
no during functions for this state
return the event
Module
JoustSM.c
Revision
2.0.1
/*---------------------------- Module Variables ---------------------------*/
CurrentState;
/*------------------------------ Module Code ------------------------------*/
/****************************************************************************
Function
RunJoustSM
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
****************************************************************************/
initialize static variable position
switch on CurrentState
case ST_Retracted
call the during function for this state
if the event is EV_START_JOUSTING
set NextState to ST_Deployed
mark that we are making state transition
set the return event type to ES_NO_EVENT
case ST_Deployed
call the during function for this state
if the event is ES_TIMEOUT
if the event parameter is JOUST_TIMER
set NextState to ST_HonorablePause
mark that we are making state transition
set the return event type to ES_NO_EVENT
else if the event parameter is SWING_TIMER and the current joust position is FORWARD_POSITION
adjust swing servo to backward
update position to BACKWARD_POSITION
else
adjust swing servo to forward swinging
update position to FORWARD_POSITION
start the timer for SWING_TIMER
case ST_HonorablePause
call the during function for this state
if the event is ES_TIMEOUT
if the event parameter is HONORABLE_PAUSE_TIMER
set NextState to ST_Retracted
mark that we are making state transition
set the return event type to ES_NO_EVENT
else if the event parameter is SWING_TIMER
Retract the jousting lance
end switch on CurrentState
if we are making state transition
Set the event type of CurrentEvent to ES_EXIT
Pass the CurrentEvent to the current RunJoustSM
Set the NextState to CurrentState
Run entry functions for the new state
/****************************************************************************
Function
StartJoustSM
Parameters
None
Returns
None
Description
Does any required initialization for this state machine
Notes
Author
J. Edward Carryer, 2/18/99, 10:38AM
****************************************************************************/
Set the CurrentState to ST_Retracted
Pass the CurrentState into the RunJoustSM function to call the entry function
/****************************************************************************
Function
QueryJoustSM
Parameters
None
Returns
JoustState_t The current state of the JoustSM
Description
returns the current state of the JoustSM
Notes
Author
J. Edward Carryer, 2/11/05, 10:38AM
****************************************************************************/
return the CurrentEvent
/***************************************************************************
/**************************************************************************/
DuringRetracted
/**************************************************************************/
No during functions for this state
return the event
/**************************************************************************/
DuringDeployed
/**************************************************************************/
if entry event
start Joust timer for deploy interval
start swing timer for swinging
set lance position to DEPLOYED_POSITION
set swing servo position to FORWARD_POSITION
else if ES_EXIT event
set swing servo to FORWARD_POSITION
start timer SWING_TIMER
start timer HONORABLE_PAUSE_TIMER
/**************************************************************************/
DuringHonorablePause
/**************************************************************************/
no during functions for this state
return the event