Create a function that will implement a proportional-derivative controller:
void pd_control(int16_t error, int16_t rotation_rate, uint8_t forward_thrust) where error is the heading error, rotation_rate is the rate of craft rotation, and forward_thrust is the total forward thrust that should be generated by the left/right fans combined (this latter value will be between 0 ... 127)
This function will:
Note: you are strongly encouraged to use integer math instead of floating point math.
Notes on tuning the PD control parameters:
Note: this part will count for one personal programming credit
Create a function that will implement a steering controller:
int8_t steering_control(uint16_t distance_left, unt16_t distance_right, int16_t rotation_rate, uint8_t forward_thrust) distance_left and distance_right are the distances (in mm) to the nearest obstacle for the left and right sensors, rotation_rate is the rate of craft rotation, and forward_thrust is the total forward thrust that should be generated by the left/right fans combined (this latter value will be between 0 ... 127)
This function will:
Note: this part will count for one personal programming credit
For this part, you will implement a high-level control loop that will cycle once every 50 ms. For each of these control steps, the hovercraft will first steer away from obstacles (while moving forward). If there are no obstacles, then the hovercraft will steer toward the goal heading (also, moving forward).
int main(void) {
int16_t counter = 0;
int16_t heading, heading_goal, heading_error;
int16_t rotation_rate, distance_left, distance_right;
#APPROPRIATE VARIABLE DECLARATIONS HERE#
#APPROPRIATE INITIALIZATIONS HERE#
heading_goal = get_orientation();
middle_thrust_dir(1);
#RAMP UP MIDDLE THRUST TO HOVER#
while(counter < 20*30) { // 30 seconds
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, #PICK SOME SMALL VALUE#);
if(status == -1) {
// No obstacles: steer to desired direction
pd_control(heading_error, rotation_rate, , #PICK THE SAME SMALL VALUE#);
}
// 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;
}
// Shut down hovercraft
duty_left = 0;
duty_right = 0;
#RAMP DOWN MIDDLE THRUST TO ZERO#
while(1){}; // Spin forever
}
Remember that documentation is about helping you and others looking at your code to understand what it is doing. Therefore, it will generally describe the logic of the code (and not-necessarily the low-level details). For this class:
See an example.
Grades for individuals will be based on the group grade, but weighted by the assessed contributions of the group members.
Last modified: Wed Mar 30 23:48:46 2011