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:
#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);
}
}
Grades for individuals will be based on the group grade, but weighted by the assessed contributions of the group members.
Last modified: Thu Apr 16 00:10:36 2009