Hey! We are a rookie team and the concept of PID is entirely foreign to us. We want to use it for our autonomous, but would like to fully understand what it is, how to use it, and when to use it. If anyone has an intro for absolute beginners on this concept please do share.
-
Our only knowledge of PID is that it is an algorithm that returns something. (so we know nothing) What exactly does PID return. I know it takes two numbers and using an error and a constant, but what does it return? A heavily detailed answer to this question would be great.
-
When should we use PID? The only time I see it necessary is to keep the robot straight. However, I am sure there are plenty of other times.
-
How do you use PID with encoders? Our robot has encoders on each side of the drive, how can PID be used to keep the robot straight. I have heard about something with master and slave, but do not understand it. If anyone has an example, that’d be great.
-
PID motor in robotc? I know nothing about how or what this is, I just saw it in robotc.
-
How do you incorporate PID into your code? Right now, I have a separate task/thread that is called when the robot needs to be at a certain angle (gyro). Are there better ways?
-
When pronounced, is it P-I-D (as in the letters each spoken individually) or Pid (like it’s own word)?
Even if you answer one of these questions, it will be much appreciated by my team and others who have the same questions.
Thank you
*1. 2. 3. *
This question has been asked and answered a lot (recommend searching vex forum). The first link I think explains PID the best and is used for line following, but the same idea can be used for any thing. I mostly use PID for lifts. Other members can and are willing to answer more questions you have. This I feel is a good start.
4. PID motor in robotc? I know nothing about how or what this is, I just saw it in robotc.
Under motors there is a check box for PID control which to my understanding controls the motors ( power / measured speed) ratio which I would assume you would need IME on each wheel and could help your problem, but this is not normally what people refer to when they say PID in Vex.
5. How do you incorporate PID into your code? Right now, I have a separate task/thread that is called when the robot needs to be at a certain angle (gyro). Are there better ways?
You can create a task or a function.
6. When pronounced, is it P-I-D (as in the letters each spoken individually) or Pid (like it’s own word)?
PID = Proportional Integral Derivative. So P-I-D is correct.
http://www.inpharmix.com/jps/PID_Controller_For_Lego_Mindstorms_Robots.html
https://vexforum.com/t/pid-explanation/20270/1
Don’t dive straight into trying to make a PID control loop. Start with just the “P” or Proportional term since that will make sense and is easily achievable plus for many applications is all you’ll need anyway.
In the context of a lift arm a Proportional control system works like this:
INPUT (Set Point): Where you want the arm to be.
Actual Position: Where the arm is now (position sensor value).
Error: Difference between Set Point and Actual Position.
Gain: How much to scale the Error value.
OUTPUT: How much power to send to the motor. Error * Gain.
If you implement a PID control loop, perhaps using some existing code you find, start with I=0 and D=0 until you get a handle on what they might help with.
In general the I and D terms will allow you to increase P without causing instability thus acheving a snappier response / faster rise time. The I term can also help eliminate final Position errors.
A search of these forums will get you a ton on PID but maybe not some of the basic questions you want answered.
PID is a means of getting me to and holding the value I want - and does so in a wickedly efficient manner. In a robot arm, that is going to move me to a position and hold me there at that target. In driving autonomous, that is generally move this far and stop on a dime. You can also use a PID controller to keep a heading angle by managing the error from the target angle.
The basic measurement of the PID is how far away am I from where I want to be - the current error. PID is a control loop that also takes into account how far will I be next interval, and how far off have I ever been.
The P stands for proportional and is how far away am I from where I want to be.
The I is Integral and that is the sum of how far off I have ever been. (area under the curve). This one needs a cap or else the longer you are away from where you are, the more this blows away the rest of the factors. So capping at 30% - 40% of max power helps.
The D is the derivative and that is essentially how far am I next predicting for time and compensating from that.
You have factors against these P, I, and D factors and you tweak up or down depending on if you are over or under the target value. The tuning of these is the real hard part of PID.
Ideally you want to not have any overshoot past your selected value. You want a clean trajectory in and stop on a dime, and not a gentle glide path. Get me there and hold me there - now and after that.
So there are these tuning mechanisms for getting the right values for PID. You will find them about in your searches. That’s why people say start with tuning P. That gets you a gentle glide path into your target value.
When not to use PID:
- Frequently changing target values. The I term gets messed up so you have better clear or adjust it, and D jumps wildly on your first new calculation. You can do this, but you need to reset/adjust the target and start over for each change.
- Small movements or adjustments. Being close means P is not going to be big. No change means D is not happening, and the capped I value will be miniscule making your robot part not move a heck of a lot with the same constants.
- You don’t have a target value to hit. Driving forward with no encoder target value means there’s no error value to give to a PID loop so there’s nothing to calculate.