/**************************************************************************** Module Gameplay_GameTasksSM.c Revision 2.0.1 Description This is a sub state machine (2nd level) called GameTasks within the Gameplay module for ME 218B project for Team 3. Implements a hierarchical state machine under the Gen2 Events and Services Framework. Notes Private Definitions ENTRY_STATE CollectBalls CurrentState BeaconRearFreq ES_Event_t RunGameTasksSM(ES_Event_t CurrentEvent) -------------------------- // default to normal entry to new state // based on our current state: // if current state is CollectBalls // execute During function for CollectBalls state // process any events // based on the event type: // if our robot has reached max recycle capacity // we want to move to DumpRecycling state // mark that we are taking a transition // consume this event for the upper state machines // if our robot has reached max trash capacity // we want to move to DumpTrash state // mark that we are taking a transition // consume this event for the upper state machines // if there is only enough time left to dump // if we have any recycling balls, then we want to do that first. // we will have to query the BallSortingService if we have // recycling balls -- if so: // we want to move to DumpRecycling state // mark that we are taking a transition // consume this event for the upper state machines // otherwise, if we have trash balls, then we will want to dump // trash. we will have to query the BallSortingService if we // have trash balls -- if so: // we want to move to DumpTrash state // mark that we are taking a transition // consume this event for the upper state machines // otherwise, even if there is little time left, we don't have to // dump because our robot is empty; we will stay in CollectBalls // If current state is DumpRecycling // Execute During function for DumpRecycling // process any events // based on the event type: // if the recycling center has changed // we want to exit and re-enter our DumpRecycling state // mark that we are taking a transition // consume this event for the upper state machines // if we emptied our recycling // if we still have no trash balls, then we don't want to go to // DumpTrash and would instead CollectBalls. Ask // BallSortingService -- if we have no trash balls: // we want to move to CollectBalls state // mark that we are taking a transition // consume this event for the upper state machines // if we still have a good bit of time left in the game, then we // want to go back to collecting balls, regardless of if we have // trash balls or not. Ask GameControl service -- if still time: // we want to move to CollectBalls state // mark that we are taking a transition // consume this event for the upper state machines // the last case is that we have little time left in the game and // we have trash balls to dump. In this case, we want to go to // DumpTrash. // we want to move to DumpTrash state // mark that we are taking a transition // consume this event for the upper state machines // If current state is DumpTrash // Execute During function for DumpTrash // process any events // based on the event type: // if we emptied our trash // if we still have no recycling balls, then we don't want to go // to DumpRecycling and would instead CollectBalls. Ask // BallSortingService -- if we have no recycling balls: // we want to move to CollectBalls state // mark that we are taking a transition // consume this event for the upper state machines // if we still have a good bit of time left in the game, then we // want to go back to collecting balls, regardless of if we have // recycling balls or not. Ask GameControl service if time: // we want to move to CollectBalls state // mark that we are taking a transition // consume this event for the upper state machines // the last case is that we have little time left in the game and // we have recycling balls to dump. In this case, we want to go // to DumpRecycling. // we want to move to DumpRecycling state // mark that we are taking a transition // consume this event for the upper state machines // if we are making a state transition // Execute exit function for current state // Modify state variable // Execute entry function for new state (this defaults to ES_ENTRY) void StartGameTasksSM(ES_Event_t CurrentEvent) ------------------------------ // to implement entry to a history state or directly to a substate // you can modify the initialization of the CurrentState variable // otherwise just start in the entry state every time the state machine // is started // call the entry function (if any) for the ENTRY_STATE GameTasksState_t QueryGameTasksSM(void) ------------------------------------- // return CurrentState variable uint16_t QueryBeaconRearFreq(void) ------------------------------------------ // return BeaconRearFreq; void SetBeaconRearFreq(uint16_t NewFreq) ------------------------------------ // set BeaconRearFreq to passed in parameter static ES_Event_t DuringCollectBalls(ES_Event_t Event) ---------------------- // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // post MOTOR_COMMAND with EventParam FORWARD // now start the lower level machine that runs in this state // process ES_EXIT event // on exit, give the lower levels a chance to clean up first // no tasks to do for exit from CollectBalls // process other events // run any lower level state machine // 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. static ES_Event_t DuringDumpRecycling(ES_Event_t Event) --------------------- // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // start turning clockwise // set BeaconRearFreq to north landfill beacon frequency // enable interrupts for rear beacon sensor // now start the lower level machine that runs in this state // process ES_EXIT event // on exit, give the lower levels a chance to clean up first // no tasks to do for exit from DumpRecycling // process other events // run any lower level state machine // 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; static ES_Event_t DuringDumpTrash(ES_Event_t Event) ------------------------- // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // start turning clockwise // set BeaconRearFreq based on which team we are // if we are North, then we want to drive to the east recycling center // otherwise we want to drive to the west recycling center // enable interrupts for rear beacon sensor // now start the lower level machine that runs in this state // process ES_EXIT // on exit, give the lower levels a chance to clean up first // no tasks to do for exit from DumpTrash // process other events // run any lower level state machine // 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. /***************************************************************************/