Professional Documents
Culture Documents
Squaringtowall
Squaringtowall
Module
SquaringToWall.c
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
// Basic includes for a program using the Events and Services Framework
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "ES_DeferRecall.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/gpio.h"
#include "termio.h"
#include "hw_nvic.h"
#include "hw_pwm.h"
#include "hw_timer.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_ssi.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 "SquaringToWall.h"
#include "MotorDrive.h"
#include "MasterSM.h"
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 RunSquaringToWall(ES_Event_t CurrentEvent)
{
bool MakeTransition = false;/* are we making a state transition?
*/
SquaringToWallState_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)
{
//TODO: decide which squaring approach is best.
//while we're driving one side back
case DRIVING_BACK:
{
ReturnEvent = CurrentEvent = DuringDriveBack(CurrentEvent);
if (CurrentEvent.EventType != ES_NO_EVENT)
{
if (((SideHit > 0) && (CurrentEvent.EventType == RIGHT_BUMPER_HIT)) ||
((SideHit == 0) && (CurrentEvent.EventType == LEFT_BUMPER_HIT)))
{
StopDrive();
NextState = DRIVING_FOR;
MakeTransition = true;
ES_Timer_StopTimer(SQUARE_TIMER);
ReturnEvent.EventType = ES_NO_EVENT;
}
else if ((CurrentEvent.EventType == ES_TIMEOUT) && (CurrentEvent.EventParam
== SQUARE_TIMER)) //If timer times out.
{
printf("Timer Timerout!\r\n");
StopDrive();
NextState = DRIVING_FOR;
MakeTransition = true;
ReturnEvent.EventType = ES_NO_EVENT;
}
}
}
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 StartSquaringToWall(ES_Event_t CurrentEvent)
{
if (CurrentEvent.EventType != ES_ENTRY)
{
printf("WARNING: Squaring to wall started with a non-ES_ENTRY event.\r\n");
}
if (CurrentEvent.EventParam > 0)
{
printf("Starting squaring to wall because left bumper was hit \r\n");
BumperEvent = RIGHT_BUMPER_HIT;
SideHit = 1;
}
else
{
printf("Starting squaring to wall because right bumper was hit \r\n");
BumperEvent = LEFT_BUMPER_HIT;
SideHit = 0;
}
CurrentState = ENTRY_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
****************************************************************************/
SquaringToWallState_t QuerySquaringToWall(void)
{
return CurrentState;
}
/***************************************************************************
private functions
***************************************************************************/
bool Check4LeftBumper(void)
{
bool ReturnVal = false;
uint8_t CurrentInput_LeftBumper;
ES_Event_t BumperEvent;
ReturnVal = true;
}
LastInput_LeftBumper = CurrentInput_LeftBumper;
return ReturnVal;
}
bool Check4RightBumper(void)
{
bool ReturnVal = false;
uint8_t CurrentInput_RightBumper;
ES_Event_t BumperEvent;
ReturnVal = true;
}
LastInput_RightBumper = CurrentInput_RightBumper;
return ReturnVal;
}
void InitBumpers(void)
{
if ((HWREG(SYSCTL_PRGPIO) & BIT3HI) != BIT3HI) // if haven't enabled the port
yet
{
// Set up port D by enabling the peripheral clock
HWREG(SYSCTL_RCGCGPIO) |= BIT3HI;