Credit Arturo Urquizo
A PID Controller implements the PID control algorithm. The PID control is a useful form of control loop in robotics. It simplifies control of a mechanism by creating a system that you can tell to go to some setpoint and it takes care of automatically moving to that setpoint and maintaining that setpoint as long as the PID loop is tuned.
There are 4 important constants that influence the behavior of the PID Controller, by setting any of these to 0, you can ignore that coefficient and use a simpler controller if it meets your needs. The 4 constants are the proportional, integral, derivative, and forcing constants which are explained below.
The proportional control constant of the PID loop is often referred to as P or kP. It is the simplest parameter to use and in many cases when using PID you really only need the proportional constant. The proportional term is very simple, you know where you are and where you want to be (i.e. the setpoint), so you just take the difference and multiply by kP which acts as a scaling factor.
The integral control constant of the PID loop is often referred to as I or kI. It is useful for overcoming unexpected resistance that would stop a simple loop using only the proportional constant. The integral term represents the area under the curve of the error over time. You know where you are and where you want to be (the setpoint), so you just add this up over time and multiply by kI which acts as another scaling factor.
The derivative control constant of the PID loop is often referred to is D or kD. It is useful for preventing oscillation that otherwise occurs in a control loop. Derivative is the rate of change of the error over time. You know where you are and where you want to be (the setpoint), and you know this from the past time, so you take the setpoint difference, divide by the time difference and as always multiply by a scaling factor. The scaling factor in this case is kD.
The forcing control constant of the PID loop is often referred to as F or kF. It is used as the feed forward term and is very useful for velocity PID. TODO: Fill in
When setup with an elevator and tuned appropriately, the elevator can be told to go to predetermined heights by setting the setpoint to predetermined values. With this, a press of a button can move the elevator to a known height where it can pickup and place pieces.
With a spinning wheel shooter, a PID controller with a forcing term can be used to set the speed of the wheel. When the wheel is spinning at the same speed, it will consistently shoot the same distance. By determining the setpoint for a distance, you can use PID controller to consistently shoot into a basket.
Setting the setpoint in java is easy, just call my_pid_controller.setSetpoint(2);
Setting the setpoint in C++ is easy, just call my_pid_controller.Setsetpoint(2);