Project 3: Orientation Control
All components of the project are due by Thursday, April 16th
at 5:00pm (or close of the lab, whichever is later).
Project Goals
At the end of this project, you should be able to:
- implement an Application Programming Interface (API) for
commanding a robot, and
- implement and tune a proportional-derivative controller that connects
sensing to actuation.
Project Overview
For this project, you will be creating a control program to maintain
the orientation of helicopter at a specified compass heading (i.e.,
you will be doing yaw control).
In brief, your craft must:
- Bring the throttle to a level sufficient for hovering. This is
easy to do in "open-loop" (without sensing) because the
cables dangling from the bottom of the craft add weight as the
craft rises.
- Hover for one minute.
- During the hover, the craft must maintain the same heading that
it had at lift-off.
- After the minute of hovering, the throttle must be reduced
slowly so as to bring the craft to a soft landing.
Project Components
All components are required to receive full credit for the project.
Part 1: Application Programming Interface
Implement the following functions:
- void set_throttle(uint8_t) will send the necessary
command to set the current throttle level (due to the dangling
wire, this signal is a combination of acceleration and
position command).
- void set_yaw(uint8_t) will send the necessary
command to set the current yaw level (this is essentially an
acceleration command).
- int16_t clip(int16_t) will implement a "deadband"
around zero and saturate errors at +/-45 degrees. More details
in class...
Part 2: Proportional-Derivative Controller
Create a proportional-derivative controller that will bring the
craft's heading to a specified goal orientation. In essence, you will
implement the following:
yaw_command = yaw_center +
Kp * clip(heading_error) - Kv * heading_derivative
where Kp and Kv are gain parameters that you
must select (start small!), and yaw_center is the yaw
command that corresponds to "no yaw acceleration" (128).
Notes:
- If you are using different data types (e.g., int and float), you
must take care to cast one in terms of the other before mixing them (see
the AVR programming book on type casting). However, note that
you can perform all of the necessary computations using integer math only
(which is much more computationally efficient than using floats).
- Start by setting Kv = 0 and choosing a Kp. Although this will lead to
oscillations around your goal (if you have the sign of Kp
correct), you can use this mode to get Kp into a "ballpark" in
which your controller will drive the yaw in the right direction
from far away from the goal.
- Once Kp is yielding reasonable behavior, then begin to adjust Kv
to dampen the oscillations.
- If the robot responds too slowly in correcting the heading, then
Kv may be too high or Kp may be too low.
- If the robot overshoots the desired heading (so that it
oscillates around this heading), then Kv may be too low or Kp too
high.
- Be sure to work carefully through your choice of sign for Kp and Kv.
Your main loop template (start from here!):
#define STATE_THROTTLE_UP 0
#define STATE_HOVER 1
#define STATE_THROTTLE_DOWN 2
#define STATE_DONE 3
void main_loop(void) {
int16_t counter = 0;
uint8_t state = STATE_THROTTLE_UP;
uint8_t throttle = 20;
#APPROPRIATE VARIABLE DECLARATIONS HERE#
heading_current = #HOW SHOULD THIS BE INITIALIZED?#
heading_goal = #HOW SHOULD THIS BE INITIALIZED?#
while(1) {
heading_last = heading_current;
heading_current = get_heading();
heading_error = compute_error(heading_goal, heading_current);
heading_derivative = compute_derivative(heading_last, heading_current);
// Display
if(#COMMAND INPUT LINE#) {
display_orient(heading_current);
}else{
display_orient(heading_error);
}
display_derivative(heading_derivative);
// PD controller
yaw_command = yaw_center +
Kp * clip(heading_error) - Kv * heading_derivative;
set_yaw(yaw_command);
// Finite State Machine for height control
switch(state) {
case STATE_THROTTLE_UP:
if((counter % 10) == 0) {
// True once every second
// Increase throttle
throttle += 5;
set_throttle(throttle);
// Are we at max throttle?
if(throttle >= 150) {
// Yes: change to the hover state
state = STATE_HOVER;
counter = 0;
}
}
break;
case STATE_HOVER:
if(counter >= 600) {
// We have hovered for 1 minute
state = STATE_THROTTLE_DOWN;
counter = 0;
};
break;
case STATE_THROTTLE_DOWN:
if((counter % 10) == 0) {
// True once every second
// Decrease throttle
throttle -= 5;
set_throttle(throttle);
// Are we throttled down?
if(throttle <= 20) {
// Yes: change to the done state
set_throttle(0);
state = STATE_DONE;
counter = 0;
}
}
break;
case STATE_DONE:
// Do something to indicate that you are done
break;
};
// Increment time
++counter;
// Give us approximately 100 ms steps
delay_ms(100);
}
}
References and Hints
What to Hand In
All components of the project are due by Thursday, April 16th at
5:00pm (or close of lab, whichever is later).
- Demonstration/Presentation: All group members must be
present.
- Demonstrate your final product.
- Present your design and implementation (5 minutes).
The group is
responsible for assembling a short presentation
consisting of 3-4 slides (on computer or in printed
form). Describe the design including:
- Your general approach to solving the problem,
- any key software algorithms (how the general problems are solved in code), and
- the software organization (describe how the software problem is split into different separable sub-problems, and how the different components interact).
- DO NOT include low-level code
- Hand in the power point file to the project 3 digital
dropbox.
- Code: Turn in your documented code to the
project 3 digital dropbox on D2L (hand in the ".c" file). Only hand in
one copy of the code per group.
- Personal report: One submission per person to the
project 3 digital dropbox. State the relative contribution of
you and your group members (in terms of percentage of effort)
(text format only!). This distribution will be used to compute
the individual grades.
Grading
Group grade distribution:
- 40%: Project implementation
- 30%: Demonstration/presentation of working project (to either
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: Thu Apr 16 00:10:36 2009