/**************************************************************************** Module Gameplay_GameTasks_DumpTrashSM.c Revision 2.0.1 Description This is a sub state machine (3rd level) called DumpTrash 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 ReleaseTrashTime SquaringUpTime BackingUpTime ReAlignTime AngleAdjustmentTime CurrentState ES_Event_t RunDumpTrashSM(ES_Event_t CurrentEvent) -------------------------- // default to normal entry to new state // based on our current state: // if current state is T_AligningWithRecycling // Execute During function for T_AligningWithRecycling // process any events // based on the event type: // if we detected the correct beacon in the rear detector // check that it's the correct beacon (rear) // post MOTOR_COMMAND with EventParam BACKWARDS // we want to move to T_DrivingTowardsRecycling state // mark that we are taking a transition // consume this event for the upper state machines // if current state is T_DrivingTowardsRecycling // Execute During function for T_DrivingTowardsRecycling // process any events // based on the event type: // if we hit the wall in rear left corner // we want to back away from the wall (will be forward since we // approach beacons by driving backwards) // start a backing up timer // we want to move to T_BackingUp state // mark that we are taking a transition // consume this event for the upper state machines // if we hit the wall in rear right corner // we want to back away from the wall (will be forward since we // approach beacons by driving backwards) // start a backing up timer // we want to move to T_BackingUp state // mark that we are taking a transition // consume this event for the upper state machines // if current state is T_BackingUp // Execute During function for T_BackingUp // process any events // based on the event type: // if our backing up timer ran out // make sure it is the right timer // turn CW so we can align with the beacon // set frequency to look for our assigned landfill // enable interrupts for rear beacon sensor // we want to move to T_AligningWithLandfill state // we are making a transition // consume this event for the upper state machines // if current state is T_AligningWithLandfill // Execute During function for T_AligningWithLandfill // process any events // based on the event type: // if we detected the correct beacon in the rear detector // check that it's the correct beacon detector (rear) // we want to turn a litle bit more since we are able to see // the beacon within a wide angle. so start an angle // adjustment timer // make sure the motors are still turning clockwise // we do not want to change states // we are not transitioning out of this state // consume this event for the upper state machines // if our re-adjustment timer timed out // check that it is the correct timer // start a timer for us to re-align with beacon after a bit // post MOTOR_COMMAND with EventParam BACKWARDS // we want to move to T_DrivingTowardsLandfill state // mark that we are taking a transition // consume this event for the upper state machines // if current state is T_DrivingTowardsLandfill // Execute During function for T_DrivingTowardsLandfill // process any events // based on the event type: // if we hit the wall in rear left corner // post MOTOR_COMMAND with EventParam LEFT_STOP_RIGHT_BACK // start a timer in case the other limit switch never hits // we want to move to T_SquaringWithWallCCW state // mark that we are taking a transition // consume this event for the upper state machines // if we hit the wall in rear right corner // post MOTOR_COMMAND with EventParam RIGHT_STOP_LEFT_BACK // start a timer in case the other limit switch never hits // we want to move to T_SquaringWithWallCW state // mark that we are taking a transition // consume this event for the upper state machines // if it is time for us to re-align bc we've driven a bit // check it is from the correct timer // post MOTOR_COMMAND with EventParam CW // enable interrupts for rear beacon sensor // we want to go back to T_AligningWithLandfill state // mark that we are taking a transition // consume this event for the upper state machines // if current state is T_SquaringWithWallCW // Execute During function for T_SquaringWithWallCW // process any events // based on the event type: // if we hit the wall in rear left corner // post MOTOR_COMMAND with EventParam STOP // set trash servo to open position // set timer to allow balls to go into landfill // we want to move to ReleasingTrash state // mark that we are taking a transition // consume this event for the upper state machines // if our squaring up timer timed out // check that it is the correct timer // post MOTOR_COMMAND with EventParam STOP // set trash servo to open position // set timer to allow balls to go into landfill // we want to move to ReleasingTrash state // mark that we are taking a transition // consume this event for the upper state machines // if current state is T_SquaringWithWallCCW // Execute During function for T_SquaringWithWallCCW // process any events // based on the event type: // if we hit the wall in rear right corner // post MOTOR_COMMAND with EventParam STOP // set trash servo to open position // set timer to allow balls to go into landfill // we want to move to ReleasingTrash state // mark that we are taking a transition // consume this event for the upper state machines // if our squaring up timer timed out // check that it is the correct timer // post MOTOR_COMMAND with EventParam STOP // set trash servo to open position // set timer to allow balls to go into landfill // we want to move to ReleasingTrash state // mark that we are taking a transition // consume this event for the upper state machines // if current state is ReleasingTrash // Execute During function for ReleasingTrash // process any events // based on the event type: // if our timer for dispensing balls timed out // check that it's the correct timer (GameplayTimer) // set trash servo to closed position // back away from the wall (will be forward since we approach // beacons by driving backwards) // start a backing up timer // set next state to BackingUp // mark that we are taking a transition // consume this event for the upper state machines // if current state is T_BackingUp2 // Execute During function for T_BackingUp2 // process any events // based on the event type: // if our backing up timer ran out // make sure it is the right timer // stop our motors // post TRASH_EMPTY to Gameplay // we don't need to change states // we are not making 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 void StartDumpTrashSM(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 DumpTrashState_t QueryDumpTrashSM(void) ------------------------------------- // return CurrentState variable static ES_Event_t DuringT_AligningWithRecycling(ES_Event_t Event) ----------- // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // no tasks to do for entry into AligningWithRecycling // 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 AligningWithRecycling // 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 DuringT_DrivingTowardsRecycling(ES_Event_t Event) --------- // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // no tasks to do for entry into DrivingTowardsRecycling // 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 DrivingTowardsRecycling // 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 DuringT_BackingUp(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 DuringT_AligningWithLandfill(ES_Event_t Event) ------------ // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // no tasks to do for entry into AligningWithLandfill // 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 AligningWithLandfill // 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 DuringT_DrivingTowardsLandfill(ES_Event_t Event) ---------- // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // no tasks to do for entry into DrivingTowardsLandfill // 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 DrivingTowardsLandfill // 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 DuringT_SquaringWithWallCW(ES_Event_t Event) -------------- // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // no tasks to do for entry into SquaringWithWallCW // 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 SquaringWithWallCW // 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 DuringT_SquaringWithWallCCW(ES_Event_t Event) ------------- // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // no tasks to do for entry into SquaringWithWallCCW // 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 SquaringWithWallCCW // 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 DuringReleasingTrash(ES_Event_t Event) -------------------- // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // no tasks to do for entry into ReleasingTrash // 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 ReleasingTrash // 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 DuringT_BackingUp2(ES_Event_t Event) ---------------------- // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // no tasks to do for entry into BackingUp2 // 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 BackingUp2 // 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. /***************************************************************************/