I have been working with new sensors a lot lately and what I have noticed is that for a lot of them you need to use PID. I know that it is for feedback of some sort, but what does the P, I, and D do and how do you configure them to meet your robots needs. That is what I am having a hard time understanding?
PID (stands for proportional, integral, and derivative) is a control loop where the feedback is used as an adjustment for the next iteration. It takes in a setpoint that the loop will try to adjust for and the sensors that you stated will give you back a current value. You can subtract your current from your setpoint to get your error.
The way that most people understand PID is thinking about it as a function graph where the x-axis is the number of iterations and the y-axis is your error (setpoint - current). Now this function (let’s call it f(x)) is your basic function for your error versus iterations that is constantly growing as your PID loop continues. Your proportional value will be a constant (kP) multiplied by f(b) where b is equal to your last iteration. The integral (if you have not taken calculus) is the area underneath the curve of the function, which can be simply done by adding all the error terms. Then, you can multiply your constant (kI) by the sum of your error to find your integral constant. The derivative term is the slope of the function and is given by your point slope formula: (f(b) - f(a)) / (b - a). The derivative value is given by multiplying this slope and the constant (kD). You add all of these together to get a PID value to send to your motor.
Now, the proportional value is pretty self-explanatory. It decreases as the error becomes smaller or as you approach your setpoint. Thus, it gives a huge boost at the beginning and reduces its effectiveness as the error decreases. A P-only loop will result in oscillation. The integral term provides an extra boost that will get the PID loop to the setpoint required. Since it is the sum of the errors, it can “predict” where the power level will go next and try to compensate. The derivative portion speeds up (or slows down if your constant is negative) the loop because it multiplies a constant by your slope and adds it to the system.
Cruise control in a car is one example of PID. As you approach the setpoint (the speed you want), the car accelerates less and less until it is at the right speed, as opposed to accelerating at maximum until it hits the speed and then lets off the gas suddenly. Then it keeps that speed, even if there’s a hill. The further below the set speed you are, the greater the acceleration - to a point: There is a maximum acceleration value that the car won’t exceed (maybe about 40% of the car’s maximum performance).
P is the gradual lessening of acceleration as the “error” (the difference between the set speed and the actual speed)
I is what keeps the speed constant, even when the error is very small
D is what limits the maximum acceleration to a safe and reasonable value.
In robotics, often P is all you need. Maybe I, rarely D.
Here on CD, look for a paper called “PID without a PhD”, as well as the several dozen posts on the topic.
If your control algorithm does input/process/output, then the feedback is used as an adjustment for the present iteration.
the sensors that you stated will give you back a current value. You can subtract your current from your setpoint to get your error.
the OP may think you are talking about amps here.
The way that most people understand PID is thinking about it as a function graph where the x-axis is the number of iterations and the y-axis is your error (setpoint - current). Now this function (let’s call it f(x)) is your basic function for your error versus iterations that is constantly growing as your PID loop continues.
The error should be decreasing, not growing, if the controller is working properly.
You add all of these together to get a PID value to send to your motor.
True for the WPILib Java implementation, but other languages (like LabVIEW) use a different form of PID. The 2013 WPILib PID also has a feedforward term.
Now, the proportional value is pretty self-explanatory. It decreases as the error becomes smaller or as you approach your setpoint. Thus, it gives a huge boost at the beginning and reduces its effectiveness as the error decreases. A P-only loop will result in oscillation.
Not true as an unqualified general statement. It depends on what you are controlling, and how high you crank up the gain.
The integral term … can “predict” where the power level will go next and try to compensate.
I think you are confusing the integral term with the derivative term.
How I was taught PID was that the integral takes the current accumulation of the error, which could be translated into the state of the system. Thus, if you tune the I term properly, it could be properly used to correct the loop. I even heard the word “predict” when I was learning PID. Now I realize that my mentor probably meant that it was for correction rather than prediction.
The error should be decreasing, not growing, if the controller is working properly.
My bad, I meant that the number of iterations is growing, not the error. My fault.
It’s funny because recursion.