PID Control
PID is a method of moving a mechanism to a precise point. It works using a Proportional, integral, and derivatie term. Let's dive deeper into each of these terms and what they do.
The kP term
the P term, or the Proportional term, is the most commonly used term for PID. To explain how it works, let's use an example mechanism that has to move 50 degrees. Using an encoder value on the mechanism, we know that the mechanism's current position is at 0 degrees. We also know the mechanism needs to get to the 50 degree position. This distance is called the error. So, the mechanism has an error of 50 degrees.
The proportional term is a constant, and it works by multiplying itself by the error to get the motor output. The equation is:
MotorOutput = kP * Error
The P term is quite straightforward. as the motor moves the mechanism closer to its 50 degree mark, the error becomes smaller, and the motor output will then slow as the mechanism gets closer to the goalpoint. Here is a graph with what different PID values may do to a mechanism in relations to the setpoint:
Tuning the kP term
As said before, it is important to start with a small kP term. Having one that is too large can lead to extremely high speeds and oscilation that may break a mechanism. Let's go back to our mechanism example. at first, we decide to test it with a kP value of 0.05. After running it, we get a result that looks similar to the undershoot in the graph above. So, we decide to increase the kP value to 0.1, resulting in a graph that looks similar to the overshot. So, after decreasing kP to 0.075, our result is almost to perfection.