# Motor Control Debate how to use PID

K

#### Kipton Moravec

I was reading VanDoren's TUNING FUNDAMENTALS Basics of Proportional-Integral-Derivative Control from Control Engineering Online http://www.controleng.com/archives/1998/ctl0301.98/03a305.htm I am in the middle of a big but friendly argument with a guy in Seattle about how PID works in a motor controller. assuming PID = Kp * err + Kd * (err - err[i-1]) Ki * (sum of err[n]for n = 0 to i) The fundamental difference we have is whether a voltage output (or PWM) is set directly by the PID or if the PID changes the existing voltage output. PWM = PID // His case or PWM = PWM[i-1] + PID // My case My argument is in the case of an aircraft heading the plant (the aircraft) continues flying in the heading with no outside influences. In the case of the motor, to be similar, the motor must continue the same speed until something outside influences it. My proof is when there is no error, the equations should default to: PWM = 0 // His case -- the motor stops? PWM = PWM[i-1] // My case -- it continues with the previous value Is the PID equation is used to adjust the output up or down, or does it produce the output value directly? Kip

P

#### Peter Nachtwey

Your friend is right. The motor doesn't stop when there is no error. The motor will move proportionately to the integral term windup. Your formula will cause the control output to change at a rate proportionate to the integral term. This is not right. Peter Nachtwey

K

#### Ken Brown

Kip, You don't necessarily have zero command at zero error, I noted that your loop equation included an integral term. I would tend to agree with your friend in Seattle . . . if for no other reason that this is what we do using that approach every day and so far we are able to handily demonstrate performance better than anybody that has agreed to go up against us. ; ) (with the possible exception of the guy in Seattle) . . . Ken Brown Applied Motion Systems, Inc. http://www.kinemation.com

R

#### Rolf Gerste

> PWM = PID // His case Right Case > PWM = PWM[i-1] + PID // My case Wrong Case > My argument is in the case of an aircraft heading the plant (the > aircraft) continues flying in the heading with no outside influences. > In the case of the motor, to be similar, the motor must continue the > same speed until something outside influences it. Correct Assumption > My proof is when there is no error, the equations should default to: > > PWM = 0 // His case -- the motor stops? Wrong as in a settled PID the Integral part has accumulated the required control variable to maintain the speed. Lets see what happens dynamically in the PID equation, if you stimulate a step response. To simplify my example lets forget the Differential part as it contributes only as long as you have a dE/dT. The proportional part generates an immidiate change of the CV leaving the proportional error after the process settled. The Integral part starts integrating the remaining error replacing the proportional component as the error gets smaller. After the loop has settled the proportional component is 0 as your error is 0 and the whole CV is accumulated in your integral part. Hope this helps to solve the friendly argument Best Regards Rolf Gerste RG Electrical Engineering & Consulting PO Box 37601, Winnellie NT 0821 Australia Tel: ++61 (0)8 8984 4385 Fax: ++61 (0)8 8984 4001 Mobile: 0417 837 933 Allen Bradley System Integrator Rockwell Strategic Software Provider

D

#### Davis Gentry

You've oversimplified things a bit in your example - your friend is correct. You forgot to take into play such things as friction in the motor, wind resistance, gravity, etc. While the forces may be different in other examples, the results are the same. While the motor is accelerating to steady state speed you will have much higher current while it overcomes inertia etc required to reach speed. While at steady state speed the current output may approach zero if the forces acting on the motor and and load are such that they present little resistance to maintaining that speed. The PID algorithm you showed is also very simplistic - very often controllers have multiple loops, one inside of the other, and modifiers such as friction, velocity, and acceleration feedforward terms in the equation. Davis Gentry Delta Tau Data Systems

K

#### Kipton Moravec

I guess this is where I am completely ignorant. I was under the impression that the integral term was not there to hold the velocity constant, but to fix small errors. The best example I can think of is in a position PID equation, where the error is small and so the P part of the equation does not provide enough power to overcome inertia and "sticktion" to move the object. The errors build up in the I part of the equation until there is enough voltage to overcome the resistance to move, and the motor moves a small amount. Also I can see in the form I wrote, the integral plays the roll of holding the average speed. When I command it to go say from 5 RPM to 10 RPM, the integral makes sure the average speed is 10 RPM from when the command was given. It causes the speed to be higher until the average catches up with the lower speed while it is ramping up. In the case of the integral holding the speed, this is not as obvious that it does it anymore. Finally, usually I see the P being somewhere like 10 times the I. This makes me think that it makes the I windup slowly. Is this good?

K

#### Kipton Moravec

> Your friend is right. The motor doesn't stop when there is no error. The motor will move proportionately to the integral term windup. > > Your formula will cause the control output to change at a rate proportionate to the integral term. This is not right. Oops, somewhere I lost a plus sign befor the Ki. PID = Kp * err + Kd * (err - err[i-1]) + Ki * (sum of err[n]for n = 0 to i)

F

#### Friedrich Haase

Moin Kip, >PWM = PWM[i-1] + PID // My case This is an additional integral action in series / behind the PID. Regards Friedrich Haase

W

#### wlmostia

It would appear that you guys are arguing about two common implementations of the PID equation, the velocity form(incremental) and the positional form(complete calculation). Both work. The reason the positional one does not go to zero on zero error is because of the accumulated integral term. Bill Mostia =========================================== William(Bill) L. Mostia, Jr. PE Independent I &E Consultant WLM Engineering Co. P.O. Box 1129 Kemah, TX 77565 [email protected] 281-334-3169

P

#### Peter Nachtwey

> I guess this is where I am completely ignorant. I was under the impression that the integral term was not there to hold the velocity constant, but to fix small errors. You are right. Velocity Feed forwards are for doing 99% of the work while moving. > > The best example I can think of is in a position PID equation, where the error is small and so the P part of the equation does not provide enough power to overcome inertia and "sticktion" to move the object. The errors build up in the I part of the equation until there is enough voltage to overcome the resistance to move, and the motor moves a small amount. > > Also I can see in the form I wrote, the integral plays the roll of holding the average speed. When I command it to go say from 5 RPM to 10 RPM, the integral makes sure the average speed is 10 RPM from when the command was given. It causes the speed to be higher until the average catches up with the lower speed while it is ramping up. In the case of the integral holding the speed, this is not as obvious that it does it anymore. > Integral drive does not work very well on point to point moves. The integral term does not have time to wind up. Use feed forwards. PIDs do not work unless there is error. To get a system to track closely most of the work must be done using feed forwards or some sort of output estimator. Most motion controllers have both a velocity and acceleration feed forward which give a second order approximation of the drive requirements of the system therefore reducing the amount of controling the PID must do. This reduces error while moving significantly.

K

#### Kipton Moravec

This is what drives me crazy about control theory. I just had three people (or more) in a row tell me I was wrong, and now someone says we are both right. I did not think control theory was an opinion. I thought it was mathematics. While I believe there are different ways to impliment it, there must be a way that is better than another. I have not seen a good discussion on the way to best impliment a motor control for a small robot. The discussion on the Seattle Robotics forum is how to make a robot with two wheels that are driving work. The robot turns by making one wheel go faster than the other. Ideally we have to keep track of position as well as velocity. I have looked and have not seen a giid discription of this other than a couple of pages in "Mobile Robots" by Jones, Flynn and Seiger. and they use an Form like my equation above, but the PID part is only proportional. They have an additional integral term to keep the two motors spinning together. My friend in Seattle tells me that they (the authors) are completely wrong, and that PID is not done that way. In almost all of our cases, we have a DC motor driving the wheels, an optical encoder providing ticks for portions of a rotation of the wheel, and Pulse Width Modulation (PWM) for controlling the speed of the motor. We desire to be able to know our position, and be able to run a course autonomously as fast as possible. So how do you do this best? What is the best form? Everyone says use PID. Great. Now I find out there is positional and velocity PID. So PID is not PID. I sometimes think Control Engineers (like RF Engineers) intentionally make things confusing by using "Black Magic" to make things work. I look at Schaums outline for Feedback and Control and it does not help answer the question. It tells me how to do Laplace transforms, and Bode Plots, but not how to do PID or how to choose it. Most of the articles on PID show the equation I used above, or a slight variation of it (moving the constants around) but not how to control a motor. Sorry to sound frustrated, but there are not any understandable references. Then I get three people saying I am wrong, so I contact the guy in Seattle, and basically say, I guess you are right and I am wrong. Then I am told we are both right. Aargg! Why is this so hard? It makes me think there is "Black Magic" in it.

B

What about, 1-) PWM = Kp * err + Kd * (err - err[i-1]) Ki * (sum of err[n]for n = 0 to i) 2-) PWM[i-1]=Kp * err[i-1] + Kd * (err[i-1] - err[i-2]) Ki * (sum of err[n-1]for n = 0 to i-1) THEN, subtract 2 from 1, you get: PWM=PWM[i-1]+Ki*err+Kp*(err-err[i-1])+Kd* (err-2err[i-1]+err[i-2]) what about the equation above? I want to use that equation in a Microcontroller unit in the velocity control of a mobile robot. Is it okay?Are there any better,suitable ones? Thanks for any comments.

B

#### Brian Kukulski

I believe that a "normal" PID keeps its output and adds or subtracts a bit each scan to adjust to a changing PV. ie New CV = Old CV +/- adjustment for each scan. I have also used an "incremental" PID algorithm where the output was simply the +/- adjustment term. Isn't this what the Master PID loop does in a Cascase type arrangement where the secondary loop setpoint gets modified by the primary loop CV.

B

#### Brett Haas

... may approach no-load current. Brett Haas

K

#### Kipton Moravec

> Integral drive does not work very well on point to point moves. The integral term does not have time to wind up. Use feed forwards. PIDs do not work unless there is error. To get a system to track closely most of the work must be done using feed forwards or some sort of output estimator. Most motion controllers have both a velocity and acceleration feed forward which give a second order approximation of the drive requirements of the system therefore reducing the amount of controling the PID must do. This reduces error while moving significantly. > O.K. So what does that equation look like? I thought the D part contributed to feed forward. I have a robot with two wheels driving and encoder feedback. One wheel turns faster than the other to change dorection. It needs to go from point A to point B (X and Y) on a flat surface. The wheels need to ramp up and down to speed so they don't slip, and I loose track of where I am. What should the control loop equation look like?

A

#### Anthony Kerstens

I would like to quickly interject that you're not completely ignorant. The way I understand PID and the way I use it is this. P (proportional) is the primary control mechanism. I (integral) is a correction factor to compensate offset error resulting from P. It cannot be known until P is properly tuned and the offset error found. D (derivative) is a correction factor to compensate for a changing error. If the error is constant, then D has no effect. D should not be used unless the error is changing, but is often is problematic if the measurement is noisy. It is difficult to get your head around PID looking at equations. Find a good book that describes it using mechanical depictions. Then you will understand. In fact, I do not use equations. I use charts and always start with P only (I=0, D=0). If there is then enough proportional error to be a concern, then and only then start adding I to compensate. After you have I settled, and you need to compensate for non-noisy changing error, start adding D. Anthony Kerstens P.Eng.

K

#### Ken Irving

On Tue, Mar 27, 2001 at 03:30:31PM -0500, Kipton Moravec wrote: > > I guess this is where I am completely ignorant. I was under the > impression that the integral term was not there to hold the velocity > constant, but to fix small errors. Perhaps another way to approach the question is to forget about integral (and derivative), and just look at P-only control. In "his" case, > >> PWM = PID // His case the output would indeed be zero when the error is zero; but it is common to add a fixed bias value to the output such that the zero-error output does yield a control output, With P-only control in "your" case, > >> PWM = PWM[i-1] + PID // My case no such bias is required because the PID's output is being _integrated_ in the PWM output value. So you _are_ implementing integral control, although the integral gain is obfuscated, hidden in the proportional gain and in the control scan rate. Adding integral back into "his" case, you achieve exactly what you have in "your" case, except now you've got a non-hidden integral gain that can be adjusted and is understandable in process terms (e.g., time). > The best example I can think of is in a position PID equation, where the > error is small and so the P part of the equation does not provide enough > power to overcome inertia and "sticktion" to move the object. The errors > build up in the I part of the equation until there is enough voltage to > overcome the resistance to move, and the motor moves a small amount. While this may be a useful effect in some cases, PID is a linear control means, while stiction is decidedly non-linear and cannot be completely solved by PID alone. The example is a different problem, and not a trivial one. > Finally, usually I see the P being somewhere like 10 times the I. This > makes me think that it makes the I windup slowly. Is this good? My biggest gripe with PID implementations is that the gains are often presented as numbers, with little attention to what those numbers mean. P gain deals with output per input, while I gain is in terms of time, or time along with the P terms (depending on the algorithm). One way to look at the P term is to ask: what output effect do you want with a given error? And for the I term, how fast do you want the controller to self-adjust as it tries to drive toward zero error? Ken -- Ken Irving <[email protected]> Trident Software

W

#### Willy Smith

Hi, There is a book by Jacob Tal, called "Motion Control by Microprocessors", published by Galil Motion Control. I don't know if it's still available, but it's a great technical description of the different facets of what has to happen to control a motor with a microprocessor. Try their site: www.galilmc.com There is also a chip made by National Semiconductor that implements PID in both position and velocity mode. As I recall, the datasheet explains how the equations work for the different modes. You can download the datasheet from: http://www.national.com/pf/LM/LM628.html#Datasheet The difference between position and velocity control, very simply, is what the setpoint is. In a MC system with encoder feedback, the target is either counts (position) or counts per second (velocity). The equations are the same. Have fun! It's not magic, but it does take some hands-on experience to understand how the system performance is affected by the different terms. Willy Smith Numatics, Inc. Costa Rica

H

#### Heavner, Lou [FRS/AUS]

Don't confuse lead (vs lag) action with feed forward (vs feedback) control.

B

#### Bruce Durdle

Kipton, The incremental and positional versions of the PID equation are two different ways of attaining the same end. You have to remember that the PID controller sis not develop as a result of a mathematical construction being turned into nuts and bolts - it was the other way round. The PID controller evolved as hardware because it worked. Then the mathematicians got hold of it and converted the behaviour into equation form. Because the original was continuous and followed (more or less) an equation involving pure integrals and differentials, an approximation had to be made to get it into digital form - two different approaches to the approximation result in two different discrete world equations. When converted back into "pure" analogue form, they should give much the same answer. Bruce.