Module
Defense.c
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
// Basic includes for a program using the Events and Services Framework
#include "ES_Configure.h"
#include "ES_Framework.h"
/* include header files for this state machine as well as any machines at the
next lower level in the hierarchy that are sub-machines to this machine
*/
#include "Defense.h"
#include "AligningToBeacon.h"
#include "MotorDrive.h"
#include "SquaringToWall.h"
#include "MasterSM.h"
/*----------------------------- Module Defines ----------------------------*/
// define constants for the states for this machine
// and any other local defines
//TODO: SWITCH BACK!!!!!!!
#define ENTRY_STATE BACKING_UP_SLIGHTLY
Parameters
ES_Event_t: the event to process
Returns
ES_Event_t: 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_t RunDefense(ES_Event_t CurrentEvent)
{
bool MakeTransition = false;/* are we making a state transition? */
DefenseState_t NextState = CurrentState;
ES_Event_t EntryEventKind = { ES_ENTRY, 0 }; // default to normal entry to
new state
ES_Event_t ReturnEvent = CurrentEvent; // assume we are not consuming
event
switch (CurrentState)
{
case BACKING_UP_SLIGHTLY: //use encoders to drive forward.
{ ReturnEvent = CurrentEvent = DuringBackingUpSlightly(CurrentEvent);
}
}
break;
/****************************************************************************
Function
StartTemplateSM
Parameters
None
Returns
None
Description
Does any required initialization for this state machine
Notes
Author
J. Edward Carryer, 2/18/99, 10:38AM
****************************************************************************/
void StartDefense(ES_Event_t CurrentEvent)
{
if (CurrentEvent.EventType != ES_ENTRY)
{
printf("Warning: Defense state machine was started with a non-entry
event.\r\n");
}
if (ES_ENTRY_HISTORY != CurrentEvent.EventType)
{
CurrentState = ENTRY_STATE;
}
if (CurrentEvent.EventParam == COMING_FROM_GOAL_SHOT)
{
CurrentState = ALIGNING_TO_OPPONENTS;
}
else if (CurrentEvent.EventParam == COMING_FROM_RELOAD_SHOT)
{
CurrentState = ALIGNING_DEFENSE;
}
//if we are coming from shooting and we are doing reload shot strat, we simply won't
back up
/****************************************************************************
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
****************************************************************************/
DefenseState_t QueryDefense(void)
{
return CurrentState;
}
/***************************************************************************
private functions
***************************************************************************/
return ReturnEvent;
}
return ReturnEvent;
}