Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   PID Loops (http://www.chiefdelphi.com/forums/showthread.php?t=93498)

theNerd 12-03-2011 12:41

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?

Chris Hibner 12-03-2011 13:43

Re: PID Loops
 
Quote:

Originally Posted by theNerd (Post 1038198)
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.

WizenedEE 13-03-2011 03:52

Re: PID Loops
 
Quote:

Originally Posted by Chris Hibner (Post 1038216)
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?

Ether 13-03-2011 09:04

Re: PID Loops
 
Quote:

Originally Posted by WizenedEE (Post 1038432)
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.



Greg McKaskle 13-03-2011 09:09

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

HarveyAce 13-03-2011 10:40

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?

Ether 13-03-2011 11:08

Re: PID Loops
 
Quote:

Originally Posted by HarveyAce (Post 1038484)
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.



HarveyAce 13-03-2011 11:16

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?

Chris27 13-03-2011 11:49

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.

Ether 13-03-2011 13:09

Re: PID Loops
 
Quote:

Originally Posted by Chris27 (Post 1038510)
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.



Ether 13-03-2011 13:11

Re: PID Loops
 
Quote:

Originally Posted by HarveyAce (Post 1038494)
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).



theNerd 13-03-2011 13:47

Re: PID Loops
 
Quote:

Originally Posted by Chris27 (Post 1038510)
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?

Ether 13-03-2011 14:03

Re: PID Loops
 
1 Attachment(s)
Quote:

Originally Posted by theNerd (Post 1038562)
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



Chris27 13-03-2011 14:20

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)

Ether 13-03-2011 14:40

Re: PID Loops
 
Quote:

Originally Posted by Chris27 (Post 1038577)
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




All times are GMT -5. The time now is 03:51.

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