/**************************************************************************** Module T_Searching.c Description This is a sub state machine (3rd level) called Searching within the NormalOp state machine within the Mining state machine in the Master module for ME 218B project for Team 5. Implements a hierarchical state machine under the Gen2 Events and Services Framework. Notes Private Definitions STATE_ONE STATE_TWO SEARCH_TIME SEE_FREQ_TIME SERVO_TIME COAST_TIME DELAY_TIME FORWARD REVERSE CurrentState Private Functions DuringRotatingS DuringDelayS DuringDrivingS DuringCoastingS DuringClosingGateS ES_Event_t RunSearchingSM(ES_Event_t CurrentEvent) -------------------------- // set MakeTransition to false // set NextState to CurrentState // based on our CurrentState: // if our CurrentState is RotatingS // call the During function of RotatingS - DuringRotatingS // process any events // if a FREQ_DETECTED event occurs // set NextState to DelayS // Start SERVO_TIMER // set MakeTransition to true // if an ES_TIMEOUT event occurs with SEARCH_TIMER parameter // set MakeTransition to true // send CurrentEvent 1 level up to NormalOp // if our CurrentState is DelayS // call the During function of DelayS - DuringDelayS // process any events // if an ES_TIMEOUT event occurs with SERVO_TIMER parameter // set MakeTransition to true // consume this event // if our CurrentState is DrivingS // call the During function of DrivingS - DuringDrivingS // process any events // if an ES_TIMEOUT event occurs with SEE_FREQ_TIMER parameter // set NextState to RotatingS // set MakeTransition to true // if a BEAM_BREAK event occurs // set MakeTransition to true // start SERVO_TIMER // set NextState to CoastingS // if our CurrentState is CoastingS // call the During function of CoastingS - DuringCoastingS // process any events // if an ES_TIMEOUT event occurs with SERVO_TIMER parameter // set MakeTransition to true // set NextState to ClosingGateS // if our CurrentState is ClosingGateS // call the During function of ClosingGateS - DuringClosingGateS // process any events // if an ES_TIMEOUT event occurs with SERVO_TIMER parameter // set MakeTransition to true // if MakeTransition is true // execute exit function for current state // set CurrentState to NextState // execute entry function for next state // return ReturnEvent void StartSearchingSM (ES_Event_t CurrentEvent) ---------------------------- // set CurrentState to RotatingS // call RunSearchingSM with the entry event SearchingState QuerySearchingSM (void) ------------------------------------- // return CurrentState static ES_Event_t DuringRotatingS(ES_Event_t Event) ------------------------ // process ES_ENTRY and ES_ENTRY_HISTORY events // start rotating left // start SEARCH_TIMER static ES_Event_t DuringDelayS(ES_Event_t Event) --------------------------- // process ES_EXIT events // stop rotating static ES_Event_t DuringDrivingS(ES_Event_t Event) ------------------------- // process ES_ENTRY and ES_ENTRY_HISTORY events // drive forward static ES_Event_t DuringCoastingS(ES_Event_t Event) ------------------------- // process ES_EXIT events // stop driving static ES_Event_t DuringClosingGateS(ES_Event_t Event) ---------------------- // process ES_ENTRY events // close servo gate // start SERVO_TIMER bool EventCheckPeriod(void) ------------------------------------------------- // get current period // check if period is within 10% of target period // post FREQ_DETECTED event to Master SM // start SEE_FREQ_TIMER