Project 5: Finite State Machines
- All components of the project are due by Thursday, April 29th
at 5:00pm.
- Discussion within groups is fine.
- Discussion across groups may not be about the specifics of the
solution (general programming/circuit issues are fine to
discuss).
Project Goals
At the end of this project, you should be able to:
- design a Finite State Machine (FSM) that performs a specified
high-level task,
- implement the FSM in code,
- connect FSM events to sensor events, and
- connect FSM actions to control actions.
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:
- Ramp up the middle fan to a level that enables the craft to
leave the ground.
- Navigate along theta1 while avoiding oblique obstacles
(obstacles such that the two distance sensors give very
different values).
- 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.
- Navigate along theta2 while avoiding oblique
obstacles.
- 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.
- 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:
- List the actions. How the actions relate to control
signals? For example, an action such as brake
requires the reversal of the middle fan and a large middle fan
duty cycle for a brief period of time.
- List the events. How do the events relate to internal or
external information? For example, an event such as
obstacle requires that the values of the two distance
sensors are similar and within some range.
- Draw the FSM diagram with states, events and actions listed. Include this FSM
diagram as part of your report.
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:
- 40%: Project implementation
- 30%: Demonstration/presentation of working project (to either
of the TA or the instructor)
- 30%: Code documentation and group report
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