# PID without a PhD

## Transcript

2 multiplies it by a constant. Finally, The equations of motion for the potentiometer measures the this system are fairly simple. The position of the output shaft. force on the stage is proportional F i g u r e 3 s h o w s t h e s t e p to the drive command alone, so response of the motor and gear the acceleration of the system is exactly proportional to the drive. combination. I’m using a time The step response of this system constant value of t0 = 0.2s. The by itself is a parabola, as shown step response of a system is just the behaviour of the output in in . As we will see later Figure 5 this makes the control problem response to an input that goes more challenging because of from zero to some constant value at time t = 0. Since we’re dealing the sluggishness with which the stage starts moving, and its with fairly generic examples here I’ve shown the step response as a enthusiasm to keep moving once fraction of full scale, so it goes to it gets going. 1. Figure 3 shows the step input Temperature control and the motor response. The Figure 3 The third example plant I’ll use is response of the motor starts out a heater. shows a dia - Figure 6 slowly due to the time constant, gram of an example system. The but once that is out of the way vessel is heated by an electric the motor position ramps at a constant velocity. heater, and the temperature of its - contents is sensed by a tempera ture-sensing device. Precision actuator - Thermal systems tend to have It is sometimes necessary to con - trol the position of something very complex responses. I’m go - very precisely. A precise position ing to ignore quite a bit of detail and give a very approximate ing system can be built using a Figure 4 model. Unless your performance freely moving mechanical stage, requirements are severe, an ac - a speaker coil (a coil and magnet curate model isn’t necessary. - arrangement), and a non-con tact position transducer. s h o w s t h e s t e p F i g u r e 7 r e s p o n s e o f t h e s y s t e m t o a You might expect to see this change in Vd. I’ve used time sort of mechanism stabilising an constants of t1 = 0.1s and t2 = element of an optical system, or locating some other piece of 0.3s. The response tends to settle Figure 4 out to a constant temperature equipment or sensor. for a given drive, but it can take shows such a system. Software a great deal of time doing it. commands the current in the coil. Also, without lots of insulation, This current sets up a magnetic thermal systems tend to be very field that exerts a force on the sensitive to outside effects. This magnet. The magnet is attached to the stage, which moves with effect is not shown in the figure, but we’ll be investigating it later an acceleration proportional to the coil current. Finally, the stage in the article. position is monitored by a non- Figure 5 contact position transducer. Controllers The elements of a PID controller With this arrangement, the - presented here either take their force on the magnet is indepen - dent of the stage motion. Fortu input from the measured plant nately this isolates the stage from output or from the error signal, external effects. Unfortunately which is the difference between - the plant output and the system the resulting system is very “slip pery,” and can be a challenge to command. I’m going to write the control. In addition, the electrical control code using floating point requirements to build a good cur - to keep implementation details rent-output amplifier and non- out of the discussion. It’s up to - contact transducer interface can you to adapt this if you are go ing to implement your controller be challenging. You can expect with integer or other fixed-point that if you are doing a project like this you are a member of a fairly arithmetic. I’m going to assume a func - talented team (or you’re working Figure 6 on a short-lived project). tion call as shown below. As  eetindia.co m | October 2000 | EE Times-India

3 the discussion evolves, you’ll up the response to a point. Be - yond that point (kp = 5, kp = 10) see how the data structure and the internals of the function the motor starts out faster, but it overshoots the target. In the end shape up. the system doesn’t settle out any quicker than it would have with double UpdatePID(SPid * pid, double error, double lower gain, but there is more position) overshoot. If we kept increasing { the gain we would eventually . reach a point where the system . just oscillated around the target and never settled out-the system . } would be unstable. T h e m o t o r a n d g e a r s t a r t to overshoot with high gains The reason I pass the error to the PID update routine instead because of the delay in the mo - tor response. If you look back at of passing the command is that Figure 7 sometimes you want to play tricks Figure 2, you can see that the m o t o r p o s i t i o n d o e s n ’ t s t a r t with the error. Leaving out the er - ramping up immediately. This ror calculation in the main code delay, plus high feedback gain, is makes the application of the PID what causes the overshoot seen more universal. This function will Figure 9 get used like this: shows the in Figure 8. - response of the precision actua tor with proportional feedback . only. Proportional control alone . - obviously doesn’t help this sys position = ReadPlantADC(); tem. There is so much delay in drive = UpdatePID(&plantPID, the plant that no matter how plantCommand - position, low the gain is, the system will position); oscillate. As the gain is increased, DrivePlantDAC(drive); . the frequency of the output will . increase but the system just won’t settle. shows what hap Proportional Figure 10 - pens when you use pure pro Proportional control is the easiest - p o r t i o n a l f e e d b a c k w i t h t h e feedback control to implement, Figure 8 - temperature controller. I’m show and simple proportional control is probably the most common kind ing the system response with a of control loop. A proportional disturbance due to a change in ambient temperature at t = 2s. controller is just the error signal multiplied by a constant and fed Even without the disturbance you out to the drive. The proportional can see that proportional control - doesn’t get the temperature to term gets calculated with the fol the desired setting. Increasing lowing code: the gain helps, but even with double pTerm; kp = 10 the output is still below target, and you are starting to see . a strong overshoot that continues . to travel back and forth (this is . called ringing). pTerm = pid->pGain * error; . As the previous examples show, a proportional controller . alone can be useful for some . return pTerm; things, but it doesn’t always help. Plants that have too much delay, Figure 9 Figure 8 shows what hap - like the precision actuator, can’t pens when you add proportional be stabilised with proportional control. Some plants, like the Integral feedback to the motor and gear may need to be driven faster than temperature controller, cannot be system. For small gains (kp = 1) is possible with proportional con - Integral control is used to add long- trol alone. To solve these control brought to the desired set point. term precision to a control loop. It is the motor goes to the correct tar - - almost always used in conjunction get, but it does so quite slowly. In Plants like the motor and gear problems you need to add integral with proportional control. creasing the gain (kp = 2) speeds or differential control or both. combination may work, but they  eetindia.co m | October 2000 | EE Times-India

4 The code to implement an late, after the plant has gotten up integrator is shown below. The speed. To stabilise the two previ - integrator state, iState is the sum ous systems, you need a little bit of all the preceding inputs. The of their present value, which you parameters iMin and iMax are the get from a proportional term. - minimum and maximum allow shows the motor Figure 13 able integrator state values. and gear with proportional and integral (PI) control. Compare this with Figures 8 and 11. The double iTerm; . position takes longer to settle out than the system with pure . proportional control, but it will . // calculate the integral state not settle to the wrong spot. Figure 14 // with appropriate limiting shows what hap - pid->iState += error; pens when you use PI control on the heater system. The heater if (pid->iState > pid->iMax) pid->iState = still settles out to the exact target Figure 10 temperature, as with pure inte - pid->iMax; else if (pid->iState gral control (see Figure 12), but < with PI control, it settles out two to three times faster. This figure pid-> iMin) shows operation pretty close to the limit of the speed attainable pid->iState = pid->iMin; using PI control with this plant. iTerm = pid->iGain * iState; Before we leave the discussion // calculate the integral term of integrators, there are two more . . things I need to point out. First, since you are adding up the er . - ror over time, the sampling time Integral control by itself usu that you are running becomes - important. Second, you need to ally decreases stability, or de - pay attention to the range of your stroys it altogether. Figure 11 integrator to avoid windup. shows the motor and gear with The rate that the integrator pure integral control (pGain = state changes is equal to the 0). The system doesn’t settle. average error multiplied by the Like the precision actuator with Figure 11 integrator gain multiplied by the proportional control, the motor - sampling rate. Because the inte and gear system with integral control alone will oscillate with grator tends to smooth things out bigger and bigger swings until over the long term you can get something hits a limit. (Hopefully away with a somewhat uneven - the limit isn’t breakable.) sampling rate, but it needs to av shows the tem Figure 12 erage out to a constant value. At - worst, your sampling rate should perature control system with pure integral control. This system vary by no more than ý20% over any 10-sample interval. You can takes a lot longer to settle out - than the same plant with propor even get away with missing a few tional control (see Figure 10), but samples as long as your average sample rate stays within bounds. notice that when it does settle Nonetheless, for a PI controller out, it settles out to the target I prefer to have a system where value-even with the disturbance each sample falls within ý1% to added in. If your problem at hand doesn’t require fast settling, this ý5% of the correct sample time, and a long-term average rate that might be a workable system. is right on the button. Figure 12 shows why we use Figure 12 an integral term. The integrator If you have a controller that all the time spent in saturation grator unwinds and the process state “remembers” all that has needs to push the plant hard, can cause the integrator state your controller output will spend reverses. This situation can get so gone on before, which is what allows the controller to cancel significant amounts of time out to grow (wind up) to very large bad that the system never settles - out any long term errors in the values. When the plant reaches out, but just slowly oscillates side the bounds of what your output. This same memory also drive can actually accept. This the target, the integrator value is around the target position. condition is called saturation. still very large, so the plant drives Figure 15 illustrates the effect contributes to instability-the con - troller is always responding too of integrator windup. I used the beyond the target while the inte If you use a PI controller, then -  eetindia.co m | October 2000 | EE Times-India

5 motor/controller of Figure 13, and the command value changes. limited the motor drive to ý0.2. The differential term itself is the last value of the position Not only is controller output much minus the current value of the greater than the drive available to the motor, but the motor shows position. This gives you a rough estimate of the velocity (delta - severe overshoot. The motor ac position/sample time), which tually reaches its target at around five seconds, but it doesn’t reverse predicts where the position will direction until eight seconds, and be in a while. doesn’t settle out until 15 seconds have gone by. double dTerm; . The easiest and most direct way to deal with integrator wind - . . up is to limit the integrator state, as I showed in my previous code dTerm = pid->dGain * (posi - example. tion - pid->dState); shows what Figure 16 pid->dState = position; h a p p e n s w h e n y o u t a k e t h e system in Figure 15 and limit . the integrator term to the avail - . Figure 13 . able drive output. The controller output is still large (because of the proportional term), but the With differential control you integrator doesn’t wind up very can stabilise the precision actua - far and the system starts settling tor system. shows the Figure 17 out at five seconds, and finishes - response of the precision ac at around six seconds. tuator system with proportional and derivative (PD) control. This Note that with the code ex - system settles in less than 1/2 of ample above you must scale iMin and iMax whenever you change a second, compared to multiple seconds for the other systems. the integrator gain. Usually you Figure 18 shows the heating - can just set the integrator mini system with PID control. You can mum and maximum so that the integrator output matches the - see the performance improve drive minimum and maximum. If ment to be had by using full PID control with this plant. you know your disturbances will be small and you want quicker Differential control is very settling, you can limit the integra powerful, but it is also the most - tor further. problematic of the control types Figure 14 - presented here. The three prob Differential - lems that you are most likely go I didn’t even show the precision ing to experience are sampling irregularities, noise, and high actuator in the previous section. frequency oscillations. When This is because the precision ac - I presented the code for a dif - tuator cannot be stabilised with ferential element I mentioned PI control. In general, if you can’t stabilise a plant with proportional that the output is proportional to the position change divided control, you can’t stabilise it with - PI control. We know that propor - by the sample time. If the posi tional control deals with the pres - tion is changing at a constant rate but your sample time varies ent behaviour of the plant, and from sample to sample, you will that integral control deals with get noise on your differential the past behaviour of the plant. If - term. Since the differential gain we had some element that pre dicts the plant behaviour then is usually high, this noise will be this might be used to stabilise amplified a great deal. When you use differential the plant. A differentiator will do control you need to pay close the trick. Figure 15 The code below shows the attention to even sampling. I’d say that you want the sampling - sampling interval, design your differential term of a PID con sure the actual ADC conversion happens at the right time. It may troller. I prefer to use the actual interval to be consistent to within software to sample with very high - priority. You don’t have to actu be best to put all your sampling 1% of the total at all times-the plant position rather than the ally execute the controller with closer the better. If you can’t set in an ISR or very high-priority task, error because this makes for then execute the control code in s m o o t h e r t r a n s i t i o n s w h e n such rigid precision-just make the hardware up to enforce the  eetindia.co m | October 2000 | EE Times-India

### COMM 750 Network S Directory 508

SM Provider Directory – Blue Network S UPDATED SEPTEMBER 2016

### WEF GGGR 2017

Insight Report The Global Gender Gap Report 2 017

### PhysicianDirectoryByAtoZ

Physician Directory By A to Z Abbate , Antonio , MD Abdallah , Adel , MD Pediatrics Cardiology Neonatology General Internal Medicine Ambulatory Care Center VCU Medical Center Critical Care Hospital 12...

### PhysicianDirectoryByAtoZ

Physician Directory By A to Z Abbate , Antonio , MD Abdallah , Adel , MD Pediatrics Cardiology Neonatology General Internal Medicine Ambulatory Care Center VCU Medical Center Critical Care Hospital 12...

### U7112 UCARE CONNECT + MEDICARE PROVIDERDIR MAY 2019 DATA.sv

UCare Connect + Medicare Provider and Pharmacy Directory Introduction This Provider and Pharmacy Directory includes information about the provider and pharmacy types in UCare Connect + Medicare and li...

### u7112 connectplus directories 2019

UCare Connect + Medicare Provider and Pharmacy Directory Introduction This Provider and Pharmacy Directory includes information about the provider and pharmacy types in UCare Connect + Medicare and li...

### USAHA Grey Book

F A NIMAL D ISEASES OREIGN REVISED 2008 EVENTH E DITION S Committee on Foreign and Emerging Diseases of the United States Animal Health Association USAHA PO Box 8805 St. Joseph, MO 64508 Phone: 816-67...

### 2018 MOIL Provider Directory 2 13 18 FA WEB

The ME Graduate Handbook All about the Graduate Program in Mechanical Engineering in The McCormick School of Engineering and Applied Science at Northwestern University

### Water System Design Manual

Water System Design Manual December 2009 DOH 331-123 (REV. 12/09)

### Scholarly Pursuits CURRENT

PURSUITS: SCHOLARLY GUIDE TO PROFESSIONAL A DEVELOPMENT DURING THE GRADUATE YEARS Twelfth Edition by Cynthia Verba A publication of the Graduate School of Arts and Sciences Harvard University

### PID Without a PhD

PID Without a PhD Tim Wescott, Wescott Design Services I both consult and teach in the area of digital control. Through both of these ef- forts, I have found that while there certainly are control pro...

### 2018 Physical Activity Guidelines Advisory Committee Scientific Report

2018 Physical Activity Guidelines Advisory Committee Scientific Report To the Secretary of Health and Human Services

### ADNI Acknowledgement List 11 27 17

ACKNOWLEDGEMENT LIST FOR ADNI PUBLICATIONS The Data and Publications Committee, in keeping with the publication policies adopted by the ADNI Steering three parts: I. ADNI Committee, here provide lists...

### The PhD Experience: A Review of the Factors Influencing Doctoral Students’ Completion, Achievement, and Well Being

8 Vo l u m e 1 3, 201 D H P HE T E XPERIENCE : A R EVIEW O F T HE F ACTORS OCTORAL NFLUENCING I TUD ENTS ’ C OMPLETION , D S A CHIEVEMENT , AND W ELL -B EING Anna Sverdlik* [email protected]