Go to Post Dreams come and go, but once life throws a football you have to think fast. - Pavan Dave [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 12-01-2007, 11:05
DustinB_3 DustinB_3 is offline
Registered User
FRC #0935 (Railerobotics)
Team Role: Leadership
 
Join Date: Nov 2005
Rookie Year: 2001
Location: Newton, Kansas
Posts: 78
DustinB_3 is an unknown quantity at this point
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   Spotlight this post!  
Unread 12-01-2007, 12:29
Kingofl337's Avatar
Kingofl337 Kingofl337 is offline
You didn't see anything....
AKA: Adam
FRC #0501 (Power Knights)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 1998
Location: Manchester, NH
Posts: 861
Kingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond repute
Send a message via Yahoo to Kingofl337
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)
}
__________________
FIRST Team 501 PowerKnights - Mentor
FIRST Team 40 Checkmate - Mentor Alum
FIRST Team 146 Blue Lightning - Alumni

Last edited by Kingofl337 : 12-01-2007 at 12:34.
  #3   Spotlight this post!  
Unread 12-01-2007, 12:31
Robby's Avatar
Robby Robby is offline
Registered User
AKA: Kevin Beranek
FRC #0269 (Cooney Robotics)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2003
Location: Wisconsin
Posts: 47
Robby has a spectacular aura aboutRobby has a spectacular aura about
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   Spotlight this post!  
Unread 12-01-2007, 12:35
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 592
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: Potentiometer PID

Quote:
Originally Posted by DustinB_3 View Post
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.
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
  #5   Spotlight this post!  
Unread 12-01-2007, 12:36
Joe Johnson's Avatar Unsung FIRST Hero
Joe Johnson Joe Johnson is offline
Engineer at Medrobotics
AKA: Dr. Joe
FRC #0088 (TJ2)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Raynham, MA
Posts: 2,648
Joe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond repute
Re: Potentiometer PID

Quote:
Originally Posted by DustinB_3 View Post
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.
You can not create a potentiometer with a PID loop any more than you can create a pressure sensor or yaw rate sensor with a PID loop.

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
__________________
Joseph M. Johnson, Ph.D., P.E.
Mentor
Team #88, TJ2
  #6   Spotlight this post!  
Unread 12-01-2007, 13:11
DustinB_3 DustinB_3 is offline
Registered User
FRC #0935 (Railerobotics)
Team Role: Leadership
 
Join Date: Nov 2005
Rookie Year: 2001
Location: Newton, Kansas
Posts: 78
DustinB_3 is an unknown quantity at this point
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;
  #7   Spotlight this post!  
Unread 12-01-2007, 13:16
Kingofl337's Avatar
Kingofl337 Kingofl337 is offline
You didn't see anything....
AKA: Adam
FRC #0501 (Power Knights)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 1998
Location: Manchester, NH
Posts: 861
Kingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond repute
Send a message via Yahoo to Kingofl337
Re: Potentiometer PID

That should work extreamly well.
__________________
FIRST Team 501 PowerKnights - Mentor
FIRST Team 40 Checkmate - Mentor Alum
FIRST Team 146 Blue Lightning - Alumni
  #8   Spotlight this post!  
Unread 12-01-2007, 14:46
DanDon's Avatar
DanDon DanDon is offline
ohhh MY god
AKA: Dan Hoizner
FRC #0375 (The Robotic Plague)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Staten Island, NY
Posts: 1,432
DanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond repute
Send a message via ICQ to DanDon Send a message via AIM to DanDon Send a message via MSN to DanDon
Re: Potentiometer PID

Quote:
Originally Posted by DustinB_3 View Post
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;
The analog inputs on the RC vary from 0 to 1024.

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.
  #9   Spotlight this post!  
Unread 12-01-2007, 14:51
kaszeta's Avatar
kaszeta kaszeta is offline
Registered User
FRC #0095 (Grasshoppers)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Lebanon, NH
Posts: 334
kaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of light
Re: Potentiometer PID

Quote:
Originally Posted by dhoizner View Post
The analog inputs on the RC vary from 0 to 1024.
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....
  #10   Spotlight this post!  
Unread 12-01-2007, 15:00
Unsung FIRST Hero
Greg Marra Greg Marra is offline
[automate(a) for a in tasks_to_do]
FRC #5507 (Robotic Eagles)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2005
Location: San Francisco, CA
Posts: 2,031
Greg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond repute
Re: Potentiometer PID

Quote:
Originally Posted by DustinB_3 View Post
Thanks for the whitepaper
I think I understand fairly well, would this work:

*snip*

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;
Correct me if I am wrong, but that is NOT a PID loop. All that is going on there is a proportional control based on distance of the arm from the target. That code does not account for the integral of error or the rate of change of error, making it a P loop, not a PID loop.

So that will control the arm, but it is not PID control.
  #11   Spotlight this post!  
Unread 12-01-2007, 15:05
Robby's Avatar
Robby Robby is offline
Registered User
AKA: Kevin Beranek
FRC #0269 (Cooney Robotics)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2003
Location: Wisconsin
Posts: 47
Robby has a spectacular aura aboutRobby has a spectacular aura about
Re: Potentiometer PID

Quote:
Originally Posted by Greg Marra View Post
Correct me if I am wrong, but that is NOT a PID loop. All that is going on there is a proportional control based on distance of the arm from the target. That code does not account for the integral of error or the rate of change of error, making it a P loop, not a PID loop.

So that will control the arm, but it is not PID control.
Correct. Although the way PID loops are generally created is by adjusting the P portion until it almost works and then adding the I portion until it is almost there and then adding the D portion to make it work better. A lot of the time, depending of what you are doing and how much precision you need, you'll find that the P control may be all that you need.
  #12   Spotlight this post!  
Unread 12-01-2007, 15:44
Joe Johnson's Avatar Unsung FIRST Hero
Joe Johnson Joe Johnson is offline
Engineer at Medrobotics
AKA: Dr. Joe
FRC #0088 (TJ2)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Raynham, MA
Posts: 2,648
Joe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond repute
Re: Potentiometer PID

Quote:
Originally Posted by Robby View Post
Correct. Although the way PID loops are generally created is by adjusting the P portion until it almost works and then adding the I portion until it is almost there and then adding the D portion to make it work better. A lot of the time, depending of what you are doing and how much precision you need, you'll find that the P control may be all that you need.
AND you may find the I and D are fraught with peril when implemented in a relatively low resolution discrete CPU. There is integral windup to deal with. Taking derivatives will amplifying noise - perhaps causing bad behavior. If that wasn't bad enough then there is the whole sampling delay causing instability issue.

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
__________________
Joseph M. Johnson, Ph.D., P.E.
Mentor
Team #88, TJ2

Last edited by Joe Johnson : 12-01-2007 at 15:52.
  #13   Spotlight this post!  
Unread 12-01-2007, 20:04
DustinB_3 DustinB_3 is offline
Registered User
FRC #0935 (Railerobotics)
Team Role: Leadership
 
Join Date: Nov 2005
Rookie Year: 2001
Location: Newton, Kansas
Posts: 78
DustinB_3 is an unknown quantity at this point
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
  #14   Spotlight this post!  
Unread 15-01-2007, 16:09
maniac_2040's Avatar
maniac_2040 maniac_2040 is offline
Registered User
AKA: Matt
FRC #3302 (Turbo Trojans)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Clawson, Michigan
Posts: 34
maniac_2040 is infamous around these partsmaniac_2040 is infamous around these partsmaniac_2040 is infamous around these partsmaniac_2040 is infamous around these parts
Send a message via MSN to maniac_2040
Re: Potentiometer PID

Quote:
Originally Posted by DustinB_3 View Post
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;
Well this particular code will not work because there is one small error. "Gain" is an integer. When you assign the value 0.5 to it(a double) it will chop off the decimal places and just assign 0 to it. This means the Drive pwm will always be 127:

(Gain * Error)+127
is really
(0 * Error) + 127
  #15   Spotlight this post!  
Unread 20-01-2007, 18:10
fezkazi fezkazi is offline
Registered User
FRC #2158
 
Join Date: Jan 2007
Location: Austin
Posts: 4
fezkazi is an unknown quantity at this point
Re: Potentiometer PID

hi there! which potentiometer are u guys using? who is the manufacturer and where did you buy it?

thanks! best of luck...
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 20:55.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi