Project 5: Finite State Machines

Project Goals

At the end of this project, you should be able to:

Project Outline

The goal for the hovercraft is to navigate to a specific "corner" of a room or hallway. Define theta1 to be the initial orientation of the craft (nominally oriented with the hallway). Define theta2 to point in a direction orthogonal to theta1. If the switch is in a low logic state, then theta2 should be clockwise from theta1. Otherwise, theta2 should be counter-clockwise from theta1.

Here are the steps:

  1. Ramp up the middle fan to a level that enables the craft to leave the ground.
  2. Navigate along theta1 while avoiding oblique obstacles (obstacles such that the two distance sensors give very different values).
  3. Should an obstacle appear directly in front of the craft (as indicated by the two distance sensors having similar values), then the craft should first brake and then turn toward theta2. If the new direction is also blocked by an obstacle, then the craft should power down and stop.
  4. Navigate along theta2 while avoiding oblique obstacles.
  5. Should an obstacle appear directly in front of the craft, then the craft should first brake and then turn toward theta1. If the new direction is also blocked by an obstacle, then the craft should power down and stop.
  6. Continue with step 2


Project Components

All components are required to receive full credit for the project.

Part 1: Finite State Machine Design

Design a complete FSM in diagram form:

Part 2: Finite State Machine Implementation

Note: this part will count for one personal programming credit

Modify your main function such that it is structured as follows (you will of course need to add other code). Here is an outline for the code:

int main(void) {
       int16_t counter = 0;
       int16_t heading, heading_goal, heading_error;
       int16_t theta1, theta2;
       int16_t rotation_rate, distance_left, distance_right;
       uint8_t state = STATE_START;

       #APPROPRIATE VARIABLE DECLARATIONS HERE#
       #APPROPRIATE INITIALIZATIONS HERE#

       theta1 = get_orientation();
       theta2 = ####

       middle_thrust_dir(1);

       while(1) {
           heading = get_orientation();
           heading_error = compute_error(heading_goal, heading);
           rotation_rate = get_rotation_rate();
           distance_left = get_left_sensor();
           distance_right = get_right_sensor();

           // Display
           if(#SWITCH OPEN#) {
                display_orient(heading);
           }else{
                display_orient(heading_error);
           }

           // Steer away from obstacles
           status = steering_control(distance_left, distance_right, rotation_rate, #PICK SOME SMALL VALUE#);

           if(status == -1) {
                // No obstacles: steer to desired direction
                pd_control(heading_error, rotation_rate, #PICK THE SAME SMALL VALUE#);
           }


           // Note that "status" will be useful for detecting some FSM events
        
           // Finite state machine
           switch(state) {
               case STATE_START:
                   :
                  break;
               case STATE_NAVIGATE_1:
                   :
                  break;
                :
                :
               default:
                  // this should never happen
                  #Shut down craft#
                  while(1){};
           }


           // Increment time
           ++counter;

           // Wait for the flag to be set (once every 50 ms)
           while(flag == 0) {};

           // Clear the flag for next time.
           flag = 0;
       }
}



References


What to Hand In

All components of the project are due by Thursday, April 29th at 5:00pm.


Grading

Group grade distribution:

Grades for individuals will be based on the group grade, but weighted by the assessed contributions of the group members.


fagg [[at]] cs.ou.edu

Last modified: Sun Apr 18 23:38:35 2010