Go to Post I'm pretty sure there is a federal sequester on the bandwidth coming out of LSR. - PayneTrain [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-03-2011, 12:41
theNerd's Avatar
theNerd theNerd is offline
Registered User
FRC #3329 (Cam Bots)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2110
Location: St. Marys
Posts: 51
theNerd is an unknown quantity at this point
PID Loops

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?
  #2   Spotlight this post!  
Unread 12-03-2011, 13:43
Chris Hibner's Avatar Unsung FIRST Hero
Chris Hibner Chris Hibner is offline
Eschewing Obfuscation Since 1990
AKA: Lars Kamen's Roadie
FRC #0051 (Wings of Fire)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1997
Location: Canton, MI
Posts: 1,488
Chris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond repute
Re: PID Loops

Quote:
Originally Posted by theNerd View Post
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.
__________________
-
An ounce of perception is worth a pound of obscure.
  #3   Spotlight this post!  
Unread 13-03-2011, 03:52
WizenedEE's Avatar
WizenedEE WizenedEE is offline
Registered User
AKA: Adam
FRC #3238 (Cyborg Ferrets)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Anacortes, WA
Posts: 395
WizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to all
Re: PID Loops

Quote:
Originally Posted by Chris Hibner View Post
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.
Please do. I know the basic theory and I've looked at the labview vi, but I'm a little hazy on the details. Is this how it works:

The integral adds up all the errors and then multiplies by a constant (one of the gains) to adjust the speed.

The derivative takes the current speed and somehow uses that to adjust the speed? How does it do that?

Also, looking at the labview vi again, I'm wondering why they use minutes instead of milliseconds. If I rewrite it (to learn about it) to use milliseconds, would I have to the input D by 60,000 for it to work?
  #4   Spotlight this post!  
Unread 13-03-2011, 09:04
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID Loops

Quote:
Originally Posted by WizenedEE View Post
The derivative takes the current speed and somehow uses that to adjust the speed? How does it do that?
The derivative subtracts the previous value of the process variable from the current value of the process variable and divides the result by the elapsed time between the two to get an approximation of the time rate of change of the process variable. This is then multiplied by a gain and added to the contributions from the P and I calculations.


  #5   Spotlight this post!  
Unread 13-03-2011, 09:09
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,753
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: PID Loops

When looking at the LV VI, be a little careful that it doesn't add to the confusion. You know how there are multiple formulas for computing the slope of a line? Well there are multiple ways to write the formula for a PID.

The one most often used in robotics is called the parallel form or ideal form, and the terms are independent and the P, I, and D coefficients are all multiplied gains.

The LV VI implements the academic form or standard form, the one most often used for industrial plant control. The proportion gain affects the I and D results as well, and the I and D coefficients are time based and the I coefficient is a divisor instead of a gain. The time units are long because the processes often change slowly, and convention is to use seconds.

The wikipedia article (near the bottom) covers the conversions and some of the other implementation techniques in the LV one that make it more stable for industry.

By the way, we are considering including both forms and a number of additional control tools in the future. Any feedback or requests?

Greg McKaskle
  #6   Spotlight this post!  
Unread 13-03-2011, 10:40
HarveyAce's Avatar
HarveyAce HarveyAce is offline
Registered User
FRC #3329 (CAMBots)
Team Role: Leadership
 
Join Date: Dec 2010
Rookie Year: 2010
Location: Camden County
Posts: 91
HarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant future
Re: PID Loops

So you could make an arm hold a certain position without a mechanical lock? I've been wondering how to get an arm to drive and hold a position in the vertical without it falling down and without using the window motors. is that what a PID loop does?
__________________
"Though I fly through the Valley of Death I shall fear no evil, for I am at 80,000 feet and climbing."
  #7   Spotlight this post!  
Unread 13-03-2011, 11:08
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID Loops

Quote:
Originally Posted by HarveyAce View Post
So you could make an arm hold a certain position without a mechanical lock? I've been wondering how to get an arm to drive and hold a position in the vertical without it falling down and without using the window motors. is that what a PID loop does?
Yes. But if you don't have the right motor/gear combination and/or you have a large unbalanced torque load, you will burn up the motor.


  #8   Spotlight this post!  
Unread 13-03-2011, 11:16
HarveyAce's Avatar
HarveyAce HarveyAce is offline
Registered User
FRC #3329 (CAMBots)
Team Role: Leadership
 
Join Date: Dec 2010
Rookie Year: 2010
Location: Camden County
Posts: 91
HarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant futureHarveyAce has a brilliant future
Re: PID Loops

If we have approx 30-35 ft.lbs. of torque from the weight of the arm, fp would defiantly move it with ease, but it won't stay in a position. What would be needed with a PID to make it work?
__________________
"Though I fly through the Valley of Death I shall fear no evil, for I am at 80,000 feet and climbing."
  #9   Spotlight this post!  
Unread 13-03-2011, 11:49
Chris27's Avatar
Chris27 Chris27 is offline
Registered User
AKA: Chris Freeman
FRC #1625 (Winnovation)
Team Role: Alumni
 
Join Date: Mar 2005
Rookie Year: 2004
Location: Mountain View
Posts: 196
Chris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant future
Re: PID Loops

read this starting at page 23

http://www.cs.cmu.edu/afs/cs/academi...y_friction.pdf


Basically, PID is a function that takes an input a target (set point) you want to achieve and your current error to this target and outputs the motor speed to get there.

P refers to a term that is proportional to the error. It is used to achieve the desired rise time to get to the set point. However having a high P will cause
the system to oscillate around the set point.

D refers to a term that is proportional to he derivative of the error. It is used to dampen the system to reduced the oscillations. If you overly dampen the system, you may rob it of the power it needs to actually reach the set point. This is called steady state error.

I refers to a term that is proportional to the integral of the error. It is used to address steady state error. Basically, as long as error persists, the system will try harder and harder to reduce the error. This may become dangerous because of wind up. E.g. say that you disable power to a motor
for a moment. The I term will cause the speed output to rise as the error is
not going away (the motor is disabled). When the motor is finally re enabled, it will go flying.

Sometimes you can get away with just using P especially if there is a lot of
friction in the system which would make it hard to shoot past the set point.

Hope that helps.
  #10   Spotlight this post!  
Unread 13-03-2011, 13:09
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID Loops

Quote:
Originally Posted by Chris27 View Post
D refers to a term that is proportional to he derivative of the error.
In the LabVIEW PID vi, D is the derivative of the process variable... not the error.


  #11   Spotlight this post!  
Unread 13-03-2011, 13:11
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID Loops

Quote:
Originally Posted by HarveyAce View Post
If we have approx 30-35 ft.lbs. of torque from the weight of the arm, fp would defiantly move it with ease, but it won't stay in a position. What would be needed with a PID to make it work?
What is your total gear ratio from motor to arm (gearbox plus external gears or sprockets or pulleys etc).


  #12   Spotlight this post!  
Unread 13-03-2011, 13:47
theNerd's Avatar
theNerd theNerd is offline
Registered User
FRC #3329 (Cam Bots)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2110
Location: St. Marys
Posts: 51
theNerd is an unknown quantity at this point
Re: PID Loops

Quote:
Originally Posted by Chris27 View Post
read this starting at page 23

D refers to a term that is proportional to he derivative of the error.

I refers to a term that is proportional to the integral of the error
I still don't understand to much about the details on how to find the derivative of the error (or the integral). I understand that the derivative of an equation is e.g.: instantaneous velocity, for instance F(x)' 4x^4 = 16x^3 (not pretending anything however I don't know the in depths of the derivatives all i know from second hand learning is the power rule). However my knowledge on integrals is null. How do you find the integral and derivative?
  #13   Spotlight this post!  
Unread 13-03-2011, 14:03
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID Loops

Quote:
Originally Posted by theNerd View Post
I still don't understand to much about the details on how to find the derivative of the error (or the integral). I understand that the derivative of an equation is e.g.: instantaneous velocity, for instance F(x)' 4x^4 = 16x^3 (not pretending anything however I don't know the in depths of the derivatives all i know from second hand learning is the power rule). However my knowledge on integrals is null. How do you find the integral and derivative?
If you are using PID functions that came with the language you are using, you don't have to. It is done within the provided library function.

All you need supply are:
the setpoint (the target value),

the process variable (the measured - with a sensor - value of what you are trying to control),

the 3 "gains" P, I, D

and any other optional inputs to the function such as output range

See attached screenshot of LabVIEW's PID


Attached Thumbnails
Click image for larger version

Name:	LabVIEW PID (help).png
Views:	55
Size:	18.3 KB
ID:	10401  

Last edited by Ether : 13-03-2011 at 14:06.
  #14   Spotlight this post!  
Unread 13-03-2011, 14:20
Chris27's Avatar
Chris27 Chris27 is offline
Registered User
AKA: Chris Freeman
FRC #1625 (Winnovation)
Team Role: Alumni
 
Join Date: Mar 2005
Rookie Year: 2004
Location: Mountain View
Posts: 196
Chris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant futureChris27 has a brilliant future
Re: PID Loops

Computing the derivative is easy as it is just change over time. Computing the integral is a bit more involved. You can use Fourth order Runge-Kutta to estimate the integral

http://mathworld.wolfram.com/Runge-KuttaMethod.html
http://doswa.com/blog/2009/01/02/fou...l-integration/

If you are using a PID function of some library, you probably don't need to worry about computing derivatives and integrals and will probably just need to pass it the desired set point and the current location/sensor reading (like in Labview)
  #15   Spotlight this post!  
Unread 13-03-2011, 14:40
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID Loops

Quote:
Originally Posted by Chris27 View Post
Computing the integral is a bit more involved. You can use Fourth order Runge-Kutta to estimate the integral
"Euler's Method is the most common integration method for control systems . Control methods such as PID do not need exact integration to work well. This is because the purpose of the integral is usually to force the average error to zero to ensure that the controlled signal matches the command signal over long periods of time. Only rarely is there a need to control the integral of a signal. In those cases you may need a more accurate integration method."


Control System Design Guide
Second Edition
George Ellis
Page 82


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


All times are GMT -5. The time now is 23:40.

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