/**************************************************************************** Module Gameplay_GameTasks_CollectBallsSM.c Revision 2.0.1 Description This is a sub state machine (3rd level) called CollectBalls within the GameTasks level 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 BackingUpTime CurrentState ES_Event_t RunCollectBallsSM(ES_Event_t CurrentEvent) ----------------------- // default to normal entry to new state // based on our current state: // if current state is Idle // execute During function for DuringDrivingForward state // process any events // based on the event type: // if our robot has bumped into a wall in front left corner // post MOTOR_COMMAND with EventParam BACKWARDS // start timer to allow robot to back away from wall // we want to move to BackingUp state // mark that we are taking a transition // consume this event for the upper state machines // if our robot has bumped into a wall in front right corner // post MOTOR_COMMAND with EventParam BACKWARDS // start timer to allow robot to back away from wall // we want to move to BackingUp state // mark that we are taking a transition // consume this event for the upper state machines // if current state is BackingUp // execute During function for BackingUp // process any events // based on the event type: // if our robot has finished backing up a bit // check that the correct timer timed out (GameplayTimer) // post MOTOR_COMMAND with EventParam CCW90 // we want to move to TurningCCW90 state // mark that we are taking a transition // consume this event for the upper state machines // if current state is TurningCCW90 // Execute During function for GoingAroundRobot // process any events // based on the event type: // if our robot has finished driving around robot // check that the correct timer timed out (MotorTimer) // post MOTOR_COMMAND with EventParam FORWARD // we want to move to DrivingForward state // mark that we are taking a transition // we will not consume this event so the upper state machines // can react on this event // if we are making a state transition // Execute exit function for current state // Modify state variable // Execute entry function for new state void StartCollectBallsSM(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 CollectBallsState_t QueryCollectBallsSM(void) ------------------------------- // return CurrentState variable static ES_Event_t DuringDrivingForward(ES_Event_t Event) -------------------- // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // no tasks to do for entry into DrivingForward // no lower level state machine to start // process ES_EXIT event // no lower level state machine to pass the exit to // no tasks to do for exit from DrivingForward // process other events // this state doesn't have a lower state machine to run // 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 DuringBackingUp(ES_Event_t Event) ------------------------- // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // no tasks to do for entry into BackingUp // no lower level state machine to start // process ES_EXIT event // no lower level state machine to pass the exit to // no tasks to do for exit from BackingUp // process other events // this state doesn't have a lower state machine to run // 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 DuringTurningCW90(ES_Event_t Event) // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // no tasks to do for entry into TurningCW90 // no lower level state machine to start // process ES_EXIT event // no lower level state machine to pass the exit to // no tasks to do for exit from TurningCW90 // process other events // this state doesn't have a lower state machine to run // 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. /***************************************************************************/