Quote:
Originally Posted by DustinB_3
I have searched and read everything I could find on PID loops. I am still very confused. How would I create use a potentiometer with a PID loop. It will be used so that all the driver has to do is hit a button so that our arm will go to a certain height. Any help is appreciated.
|
In reading about PID loops you probably noticed that the math is based on an error value that is the difference between an actual value and a desired value. You're talking about using a potentiometer, so I'm guessing you are trying to set an arm or extension position.
The pot connected to an analog input returns a value that represents the current position of the arm. You probably have some desired position that you are trying to move to. If you subtract those two values, you'll have a number that is positive for correcting in one direction and negative for correcting in the other direction. The magnitude of that value is how far away you are from the desired position.
That's the value you use for the PID code. If you were just using proportional control, then the speed that you drive the arm would be proportional to the error (with some scaling to get it to match your motor, gearing, etc). So the more the error, the faster the motor corrects the position. When the motor is sent a value of 127, it's off. So taking:
motor speed = error * Kp + 127 (where Kp is the proportional gain or scale factor) would drive the motor in the right direction (assuming the sign is right) and at a speed that is proportional to the distance to the desired position.
That's the basics of how to make it work.