Quote:
Originally Posted by theNerd
Besides the name proportional, integral, and derivative (if that's how you spell it) what exactly is this special algorithm used for? I understand its used for fine tuning but when would I ever use it and also how do I use it. I followed the National Instruments tutorial however I still don't understand how it exactly works. Could anybody shed some light on the dirt on how and when PID loops are used?
|
A PID loop is used to make something go to and hold a value (position, speed, etc) automatically. For example, think of your cruise control on your car. You set a desired speed. A PID can be used to make your car go to and hold that speed automatically.
There are many ways to use this for your robot. Let's say you have an arm that you want to control. You can put a sensor on that arm that measures the angle of the arm (for example, a potentiometer or an encoder). Using a PID loop, you can tell your arm what angle to go to, and the PID will command the motor automatically to get to that angle. If you can measure the heading of your robot (using a gyro or two encoders) you can use a PID loop to automatically drive along a desired heading in autonomous. There are unlimited uses: if you can think of something you want the robot to do automatically, a PID loop can help you do it.
How does it work? It's actually fairly simple.
Let's say you're driving your car and you want to accelerate to 40 MPH and hold that speed. How much do you push the pedal while you accelerate? (think about that for a minute before going on). I'm willing to bet that when you are far away from 40 MPH you push the pedal a lot, and as you get closer to 40 MPH you gradually back off. In other words, the farther you are from your desired speed, the more you push the pedal.
Let's add some mathematics to this driving technique:
You can determine how far you are away from your desired speed with a simple subtraction:
How Far From Desired Speed = DesredSpeed - ActualSpeed
The jargon is to call the above subtraction the "error". In other words, the "error" is how far away you are from what you desire. Mathematically:
Error = Desired - Actual
For the cruise control: Error = DesiredSpeed - ActualSpeed.
Example: you want to be going 40 MPH (above example) and you are going 30 MPH. Then:
Error = 40 MPH - 30 MPH
Error = 10 MPH
As we said before, when you drive you push the pedal more when you're farther away from 40 MPH and back off as you get closer. We can restate this by saying that as the "Error" is larger, you push the pedal more. When the Error is smaller, you back off on the pedal. Mathematically, this is:
Pedal = K * Error
Where K is some constant to convert between the Error and how much you push the pedal.
The above equation (Pedal = K * Error) is exactly what is being done by the P part of the PID. P means proportional, and the above equation pushes the pedal in
proportion to how much error you have.
The I and the D part are a little more complicated. If this all makes sense so far, let me know and we can continue on with the I and the D part.