Mastermachine C
Mastermachine C
Module
MasterMachine.c
Description
Top level state machine for robot project
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* 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 "ES_Configure.h"
#include "ES_Framework.h"
#include "DRS.h"
#include "MasterMachine.h"
#include "ActionMachine.h"
#include "DriveMotorService.h"
#include "InputCapture.h"
#include "TargetTracking.h"
#include "BallShooting.h"
#include "IRSensor.h"
#include "SendCommand.h"
#include "LED.h"
#include
#include
#include
#include
#include
#include
#include
#include
"inc/hw_memmap.h"
"inc/hw_gpio.h"
"inc/hw_ssi.h"
"inc/hw_sysctl.h"
"inc/hw_types.h"
"inc/hw_nvic.h"
"bitdefs.h"
"ADMulti.h"
ThisEvent.EventType = ES_ENTRY;
MyPriority = Priority;
//Initialize hardware
InitDriveMotorService();
InitTargetTrackingControl();
InitDRS();
InitBallShooting();
InitLED();
ADC_MultiInit(2);
//Read value from potentiometer
uint32_t PotReading[2];
ADC_MultiRead(PotReading);
uint8_t n = 0;
//Kart 1
if(PotReading[1] > 2400) {
n = 1;
}
//kart 2
else if(PotReading[1] > 1300) {
n = 2;
}
//kart 3
else {
n = 3;
}
printf("Kart number is: %d\r\n",n);
//write kart number
SetKartNumber(n);
// start state machine
StartMaster( ThisEvent );
printf("InitMaster Complete\r\n");
return true;
}
/****************************************************************************
Function
PostMasterSM
Parameters
ES_Event ThisEvent , the event to post to the queue
Returns
boolean False if the post operation failed, True otherwise
Description
Posts an event to this state machine's queue
****************************************************************************/
bool PostMaster( ES_Event ThisEvent )
{
return ES_PostToService( MyPriority, ThisEvent);
}
/****************************************************************************
Function
RunMasterSM
Parameters
CurrentEvent = DuringMaster(CurrentEvent);
// No events to process
// in the absence of an error the top level state machine should
// always return ES_NO_EVENT, which we initialized at the top of func
return(ReturnEvent);
}
/****************************************************************************
Function
StartMasterSM
Parameters
ES_Event CurrentEvent
Returns
nothing
Description
Does any required initialization for this state machine
Notes
Author
J. Edward Carryer, 02/06/12, 22:15
****************************************************************************/
void StartMaster( ES_Event CurrentEvent )
{
//call run master
RunMaster(CurrentEvent);
return;
}
/***************************************************************************
private functions
***************************************************************************/
static ES_Event DuringMaster( ES_Event Event)
{
ES_Event ReturnEvent = Event; // assme no re-mapping or comsumption
// process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events
if ( (Event.EventType == ES_ENTRY) ||
(Event.EventType == ES_ENTRY_HISTORY) )
{
// implement any entry actions required for this state machine
}else
// do the 'during' function for this state
{
// run any lower level state machine
ReturnEvent = RunAction(Event);
ReturnEvent = RunDRS(Event);
}
// return either Event, if you don't want to allow the lower level machine
// to remap the current event, or ReturnEvent if you do want to allow it.
return(ReturnEvent);