/**************************************************************************** Module DepositingSM.c Revision 1.0.1 Description Timer state machine for Depositing Sub State Machine. Notes History When Who What/Why -------------- --- -------- 02/06/12 23:13 jec converted to Gen2 Events and Services Framework 02/13/10 11:50 jec converted During functions to return Event_t so that they match the template 02/21/07 17:04 jec converted to pass Event_t to Start...() 02/20/07 21:37 jec converted to use enumerated type for events 02/21/05 12:21 jec Began Coding ****************************************************************************/ /*----------------------------- 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 */ /*----------------------------- Module Defines ----------------------------*/ // define constants for the states for this machine // and any other local defines //#define DEPOSITING_TIMER_CHAN 5 /*---------------------------- Module Functions ---------------------------*/ /* prototypes for private functions for this machine, things like during functions, entry & exit functions.They should be functions relevant to the behavior of this state machine */ /*---------------------------- Module Variables ---------------------------*/ // everybody needs a state variable, you may need others as well /*------------------------------ Module Code ------------------------------*/ /**************************************************************************** Function RunDepositingSM Parameters ES_Event CurrentEvent: the event to process Returns ES_Event Description Implements the timer state machine for the microwave oven Notes uses nested switch/case to implement the machine. Author J. Edward Carryer, 2/21/05, 12:30PM ****************************************************************************/ // make recursive call warning into info //ES_Event RunDepositingSM( ES_Event CurrentEvent ) { /* are we making a state transition? */ // assume we are not consuming event //In case we get stuck, set up appropriate position and orientation angles, and flags: //Base response on current state { //if the current state is Drive to beacon //process any events //If an event is active { //base response on current event { //If the event is an entry event //print an update to the screen // Select which quandrant & coordinates to deposit to { //if that quadrant is 1 //store the quadrant value, and set the target coordinates //if that quadrant is 2 //store the quadrant value, and set the target coordinates //if that quadrant is 3 //store the quadrant value, and set the target coordinates //if that quadrant is 4 //store the quadrant value, and set the target coordinates } // get the bin number at the desired quadrant //print an update to the screen //Drive to the chosen beacon //Decide the next state will be DriveToBeacon //mark that we are not making a transition // consume this event //if the event was losing condition C { //print an update to the screen // Select which quandrant & coordinates to deposit to //if that quadrant is 1 //store the quadrant value, and set the target coordinates //if that quadrant is 2 //store the quadrant value, and set the target coordinates //if that quadrant is 3 //store the quadrant value, and set the target coordinates //if that quadrant is 4 //store the quadrant value, and set the target coordinates } //Drive to the chosen beacon //Decide the next state will be DriveToBeacon //mark that we are not making a transition // consume this event //if the event was a motor stalled event //if the backing up flag has not been tripped { //print an update to the screen //set the backing up flag //start a 5s timer //Back up //set new coordinates to be directly behind bot //post appropriate calls to the driving state machine //Decide the next state will be DriveToBeacon //mark that we are not making a transition // consume this event } //If the event was a timeout event { // Select which quandrant & coordinates to deposit to { //if that quadrant is 1 //store the quadrant value, and set the target coordinates //if that quadrant is 2 //store the quadrant value, and set the target coordinates //if that quadrant is 3 //store the quadrant value, and set the target coordinates //if that quadrant is 4 //store the quadrant value, and set the target coordinates } //print an update to the screen //Drive to the chosen beacon //Decide the next state will be DriveToBeacon //mark that we are not making a transition // consume this event } //if the event was a target position reached event //If the backing up flag has not been tripped { //align the Robot to the beacon //post an appropriate event to the driving sm //Decide the next state will be AlignBeacon //mark that we are making a transition // consume this event //print an update to the screen }//otherwise we arrived at the coordinates specified for backing up { //print an appropriate message to the screen //select new desired quadrant to aligned with with the beacon { //if that quadrant is 1 //store the quadrant value, and set the target coordinates //if that quadrant is 2 //store the quadrant value, and set the target coordinates //if that quadrant is 3 //store the quadrant value, and set the target coordinates //if that quadrant is 4 //store the quadrant value, and set the target coordinates } //reset the backing up flag //Drive to the chosen beacon //Decide the next state will be DriveToBeacon //mark that we are not making a transition // consume this event } //if the event was a game over event { //print an appropraite message to the screen //Stop the bot //Post to DrivingSM //TurnOffRoller(); //mark that we are taking a transition //do not consume this event } } } //if we are in the AlignBeacon state //process any events //If an event is active { //if the backing up flag has been tripped //base the response on the event type { //if we arrived at the desired position //print an update to the screen //post a reverse to beacon event to the driving sm //Decide the next state will be Docking //mark that we are making a transition // consume this event //if the event was a game over event { //print an update to the screen //Stop the bot //Post to DrivingSM //TurnOffRoller(); //mark that we are taking a transition //do not consume the event } } } //if we are in the docking state //process any events //If an event is active { //base response on event type { //create a single bump flag //if we bump the left switch //if the single bump flag has not been set { //set the single bump flag //print an update to the screen //spin CW //post an approriate event to the driving sm //set a short timer //Decide the next state will be Docking //mark that we are not making a transition // consume this event } //if we bump the right switch //if the single bump flag has not been set { //set the single bump flag //print an update to the screen //spin CCW //post an approriate event to the driving sm //set a short timer //RightMotor(BeaconStraightening); //Decide the next state will be Docking //mark that we are not making a transition // consume this event } //if we stalled, assumed we docked //set a 5s timer //open hopper gate //Decide the next state will be Docking //mark that we are not making a transition // consume this event //if we hit both of the switches //print an update to the screen //set a 5s timer //open the hopper gate //stop the bot //Decide the next state will be Unloading //mark that we are making a transition // consume this event //if one of our set timers has expired //reset the single bump flag //print an update to the screen //set a 5s timer //open the hopper gate //stop the bot //post an approapraite call to the driving sm //Decide what the next state will be //mark that we are making a transition // consume this event //if the event was a game over event { //print an update to the screen //Stop the bot //Post to DrivingSM //TurnOffRoller(); //mark that we are not taking a transition //do not consume this event } } } //if we are in the unloading state //process any events //If an event is active { //base response on event type { //if we get a timeout event //print an update to the screen //close the hopper gate //Set reset locations based on bin locations //we we're at and sensing quad 1 { //set new locations & orientation } //we we're at and sensing quad 2 { //set new locations & orientation } //we we're at and sensing quad 3 { //set new locations & orientation } //we we're at and sensing quad 4 { //set new locations & orientation } //No longer sensing beacon for some reason, do not reset position { //set new locations & orientation } //print an update to the screen //post an appt event to the navigation to reset the location & orientation //mark that we are making a transition //return an exit event //if we get an exit event //mark that we not are making a transition //Consume the exit event as needed //if the event is a game over event { //print an update to the screen //Stop the bot //Post to DrivingSM //TurnOffRoller(); //mark that we are taking a transition //do not consume the event } } } } // If we are making a state transition { // Execute exit function for current state //Modify state variable // Execute entry function for new state } } /**************************************************************************** Function StartDepositingSM Parameters ES_Event CurrentEvent Returns None Description Does any required initialization for this state machine Notes Author J. Edward Carryer, 2/21/05, 12:54PM ****************************************************************************/ //void StartDepositingSM ( ES_Event CurrentEvent ) { // local variable to get debugger to display the value of CurrentEvent //init us into this state // Decide which beacon to drive to // call the entry function (if any) for the ENTRY_STATE //puts("DepositingSM Started"); } /**************************************************************************** Function QueryDepositingSM Parameters None Returns TimerState The current state of the Timer state machine Description returns the current state of the Template state machine Notes Author J. Edward Carryer, 2/21/05, 12:59PM ****************************************************************************/ //DepositingSubState QueryDepositingSM ( void ) { } /**************************************************************************** Function QueryDesiredQuadrant Parameters None Returns TimerState The current state of the Timer state machine Description returns the current state of the Template state machine Notes Author J. Edward Carryer, 2/21/05, 12:59PM ****************************************************************************/ //unsigned char FindLastDesiredQuadrant(void) { } /**************************************************************************** Functions QueryResetPositions Parameters void Returns integer with position/orientation Description allows other state machines read reset positions Notes Author AAS 2/18/12 ****************************************************************************/ //int QueryResetXPosition( void ) { } //int QueryResetYPosition (void) { } //int QueryResetOrientation (void) { } //char QueryDesiredQuadrant (void) { }