/**************************************************************************** Module: Hopping_SM.c Description: A hierarchical state machine for the ME218B project. Module Variables: CurrentState ****************************************************************************/ /**************************************************************************** Function RunHopping_SM Takes an event to process Returns an event to return ****************************************************************************/ Depending on CurrentState: If Hopper is waiting... ... and hopper is told to start, move hopper down. If Hopper is moving down... ... and hopper hits bottom limit, switch to move up state. ... and it's time to dump, switch to dump state. ... and hopper time limit expires, switch to move up state. If Hopper is moving up... ... and hopper hits middle limit, switch to hold state. ... and hopper hits upper limit, switch to hold state. ... and it's time to dump, swtich to dumping state. ... and hopper time limit expires, switch to hold state. If Hopper is holding... ... and hopper time limit expires, switch to move down state. ... and it's time to dump, switch to dump state. If Hopper is dumping... ... and hopper hits upper limit, stop hopper. start a pause timer. ... and pause timer expires, switch to move down state. post an event to the main SM to start driving again. If we are making a state transition Execute exit function for current state Execute entry function for new state return ReturnEvent End of function /**************************************************************************** Function StartHopping_SM Takes an event CurrentEvent Returns nothing Does any required initialization for this state machine ***************************************************************************/ If hopper is at lower limit, set Current State to Move Up State Otherwise, set Current State to Move down State Call RunHopping_SM with CurrentEvent End of function /**************************************************************************** Function QueryHopping_SM Takes nothing Returns the current state of the Hopping state machine ****************************************************************************/ Return the value of CurrentState End of function /*************************************************************************** 'During' functions: ***************************************************************************/ DuringWaitState Entry functions: none Exit functions: none During functions: none End of function DuringMoveDownState Entry functions: Set the hopper motor to move DOWN Initialize the hopper timer for Time_HopperDown (in case the limit switch doesn't fire) Exit functions: none During functions: none End of function DuringMoveUpState Entry functions: Set the hopper motor to move UP Initialize the hopper timer for Time_HopperUp (in case the limit switch doesn't fire) Exit functions: none During functions: none End of function DuringHoldState Entry functions: Set the hopper motor to STOP Initialize the hopper timer for Time_HopperHold Exit functions: none During functions: none End of function DuringDumpState Entry functions: Set the hopper motor to move UP Initialize the hopper timer for Time_HopperDump (in case the limit switch doesn't fire) Exit functions: none During functions: none End of function