FRC79 / CK_16

Code base for CK_16 (C++)
0 stars 0 forks source link

Investigate Velocity PID controllers #8

Closed schreiaj closed 11 years ago

schreiaj commented 11 years ago

There's a bunch of discussion over V_PID controllers on CD. Search it up and figure out what we need to change to make it work.

schreiaj commented 11 years ago

Minimally add description of what and why to the wiki page PID Controller

schreiaj commented 11 years ago

So, from the wiki I noticed you were looking at http://www.chiefdelphi.com/forums/showpost.php?p=690837&postcount=13 I've snipped the relevant sections here. Please disregard any references to 26ms, it was the rate at which the old IFI controllers executed code in their slow loop, basically it's no longer relevant. Replace any use of it with delta time and you're fine.

output = Kp*e_pos + Ki*e_pos_sum + Kd*e_pos_delta;

This is the standard definition of a PID controller. PID is Position, Integral, Derivative. Basically put it's 'how far am I from where I want to be, how far have I been away from it, and how fast am I approaching it" Kp, Ki, and Kd are all constants that we can tweak (these are the knobs we have to control how the algorithm works). e_pos is simply the target we are trying to reach minus our current value. target-current_value. e_pos_sum is simply a running total of our error. We reset this every time we change targets. e_pos_delta is just the change in the errors, we have to store our previous error and then we subtract the two. Below is a rough version of a complete PID controller that will work for position.

int target;
int prev_error;
int sum_error;
double k_p, k_i, k_d;
int error; 
int output; 

error = target-encoder.get();
sum_error += error;
output = k_p*error + k_i*sum_error+k_d*(error-prev_error);
prev_error = error;

The constants are all set depending on the properties of the system we are controlling and are usually determined experimentally (at least in FRC).

This should at least give you an understanding of about how a position PID controller works.

schreiaj commented 11 years ago

Some additional resources courtesy of Ether... I need to add an issue in here assigned to me "Meet Ether and thank him for being awesome"

http://www.chiefdelphi.com/forums/showpost.php?p=1114338&postcount=4 http://www.chiefdelphi.com/forums/showthread.php?t=101285?p=1115090&postcount=5