|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Potentiometer PID
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.
|
|
#2
|
||||
|
||||
|
Re: Potentiometer PID
Well the POT in an analog port will return 0 - 1024.
The code should explain the rest. You probaly want to add a statement to make sure the number going into the victor is between 0 and 255. Code:
{
if ( Button1 == 1 )
{
Target = 200 ;
}
else if ( Button2 == 1 )
{
Target = 400 ;
}
else if ( Button3 == 1 )
{
Target = 600 ;
}
Arm_Out = GetAnalogInput ( 1 ) ; //GetAnalogInput(Port) Checks the Port and Return 0-1024
Error = (Current - Target) // Computes Error Based on How Far you are from the goal
Drive = ((Gain * Error)+127) // Based on the gain it outputs a number and then add 127 so the Victor Understands
SetPWM ( 1 , Drive ) ; // SetPWM(Port,Speed)
}
Last edited by Kingofl337 : 12-01-2007 at 12:34. |
|
#3
|
||||
|
||||
|
Re: Potentiometer PID
What about this paper? http://www.chiefdelphi.com/media/papers/1823?
It explains the theory and then shows an example using a camera to track the green light, but that example is very similar to using a potentiometer to hold a mechanism in place. You are simply finding the difference between the desired and the actual values and multiplying the difference by a gain, the summation of the difference by a gain, and the change in the difference by a gain. |
|
#4
|
|||
|
|||
|
Re: Potentiometer PID
Thanks for the whitepaper
I think I understand fairly well, would this work: int Target; int Error; int Gain = 0.5; int Drive; int Arm_Out; if ( p1_sw_trig == 1 ) { Target = 600 ; } else if ( p2_sw_trig == 1 ) { Target = 1000 ; } else if ( p3_sw_trig == 1 ) { Target = 1600 ; } Arm_Out = Get_ADC_Result(2); //GetAnalogInput(Port) Checks the Port and Return 0-1024 Error = (Arm_Out - Target); // Computes Error Based on How Far you are from the goal Drive = ((Gain * Error)+127); // Based on the gain it outputs a number and then add 127 so the Victor Understands pwm01 = Drive; |
|
#5
|
||||
|
||||
|
Re: Potentiometer PID
That should work extreamly well.
![]() |
|
#6
|
|||||
|
|||||
|
Re: Potentiometer PID
Quote:
A target of 1600 would cause the arm motor to continue to run indefinately. [EDIT] This depends on what line you have defined in Kevin's code. [/EDIT] Last edited by DanDon : 12-01-2007 at 16:02. |
|
#7
|
||||
|
||||
|
Re: Potentiometer PID
Depends on whether you're using the standard routines, or Kevin Watson's ADC package which integrates the readings for possible higher precision. The use of Get_ADC_Result() suggests that that code uses Kevin's version.
Team 95's ADC values ranges from 0 to 4095 last year.... |
|
#8
|
|||||
|
|||||
|
Re: Potentiometer PID
Quote:
So that will control the arm, but it is not PID control. |
|
#9
|
||||
|
||||
|
Re: Potentiometer PID
Quote:
|
|
#10
|
||||||
|
||||||
|
Re: Potentiometer PID
Quote:
Let's also not forget extra the care and feeding a PID loop needs that a P loop does not (for example if you don't turn off the integrator when your robot disabled it is very likely to do some violent action as soon as it is enabled*). Bottom line for me: if you can get acceptable performance using a P loop, use a P loop. If not, add an I and finally if needed add a D. Oh yeah, one more thing, if you are using a feedback loop on a clearly non-linear system (like a robot arm), you can really help yourself by adding in a term that corrects for KNOWN non-linear disturbances. For example, gravity. It is quite easy to know what effect that gravity has on your arm given that you know the position of the arm joints. You can simply calculate the moment due to gravity as mg*L*cos(theta). Once you have this term it is pretty easy calculate an added term that you output to your motors that will add the right about a torque to the motor to just cancel the gravity torque. In this way, your feedback loop only has to deal with unknown disturbances (like more fiction or a tube being on your arm, etc.) On a similar note, you will have much better control of your arm if you can use counterbalance (e.g. lots of latex tubing) to cancel gravity without your feedback loop having to do anything. In general, anything you do to make your arm easier to control for your drivers in "open loop" mode will help your feedback loop (PID or otherwise). Finally, a higher gear ratio is another huge help to making feedback loops more controllable -- this helps for many reasons, too many to go into here, but as a rule of thumb I try to design arms to have a gear ratio such that my worst case expected load on the motor is about 1/5 to 1/4 of the stall torque of the motor (worst case does not include another robot hanging my arm but my worst case geometry with my heaviest payload) Good luck. Joe J. *if you have a PID control you are living on the edge if you don't have routines in your C code called "JustEnabled" and "justDisabled" You should have those routines anyway but you REALLY need them with PID control. JJ Last edited by Joe Johnson : 12-01-2007 at 15:52. |
|
#11
|
|||
|
|||
|
Re: Potentiometer PID
Thanks for all of the replies. I actually used the example in the PID Control Theory Whitepaper. I used KP with a value of 1/10 and it works great. Thanks for all of your replies
|
|
#12
|
|||
|
|||
|
Re: Potentiometer PID
I can't agree more. We just call our controllers when the robot is enabled. Dead simple and works great.
|
|
#13
|
||||
|
||||
|
Re: Potentiometer PID
Quote:
(Gain * Error)+127 is really (0 * Error) + 127 |
|
#14
|
|||
|
|||
|
Re: Potentiometer PID
Quote:
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. |
|
#15
|
||||||
|
||||||
|
Re: Potentiometer PID
Quote:
A PID loop is short hand for a particular type of closed loop control system that uses information about actual position and the desired position to determine the input to system (in this case a motor that drives your arm). The idea of PID control is that you calculate an error (Desired Position - Actual Position) then you calculate two additional values, the rate of change of the error (the derivative of the error) and the added sum of all the errors over time (the integral of the error). In PID control, you multiply each of these three numbers by 3 constants and, hey presto, out pops the input to the motor. There is some magic (i.e. math) involved in making sure your system in stable and optimal (in some sense to be defined) but that is the basic idea. The hardest part is implementing it in C code and picking your constants. The whole business depends on you system having a method of measuring position. That is where your potentiometer comes in. You have to somehow design your arm such that it rotates the pot as it moves. It is better if you can make the pot move linearly with respect to the arm movement but even some non-linearity can be worked around (at a minimum you can always linearize the pot values in C code). There is a good Chiefdelphi.com thread on this subject called PID without Ph.D. Check it out. Good luck. Joe J. that |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Potentiometer help | Unholy | Programming | 4 | 07-02-2006 17:48 |
| Potentiometer Help! | thoughtful | Programming | 4 | 18-02-2005 08:21 |
| coding a potentiometer | incognito_NICK | Programming | 5 | 14-02-2005 15:56 |
| Potentiometer | Joshua May | Technical Discussion | 8 | 22-05-2004 19:51 |
| Potentiometer Theory | Ulibrium | Technical Discussion | 6 | 25-01-2002 21:16 |