15 ms·
PID Without a PhD (2016) [pdf]
- andyjpb 7y agoThis is great. It's called "PID Without a PhD" but it still assumes at least an undergrad level training. I wish it had been around when I was studying EE-2-Control. That was not one of my favourite courses but is one of the bits of theory that I have reached for the most since and this guide has been a very useful reminder of much of it.
- babygoat 7y agoBut “PID with an undergrad” doesn’t rhyme :)
- TimWescott 7y agoHad I considered that title I would have discarded it for that reason.
- harry8 7y agoControl theory text. 'PID Control The "PID" in "PID Control" stands for "Proportional, Integral, Derivative". These three terms describe the basic elements of a PID controller.'
- moron4hire 7y agoClassic case of a really simple concept being obfuscated by jargon. If you've done any sort of game development and implemented smooth movement and animations, you've probably accidentally implemented a PID controller.
- dahart 7y agoI bumped into PID controllers doing game dev. Trying to write an AI actor to drive a car that was subject to physics is what revealed the problem. But, I had been writing smooth movement and animation for years and never needed a PID controller before, or implemented one accidentally. In fact using animation smoothing is what got me into trouble with the AI driving. In retrospect, I would call basic animation smoothing a “P” controller, you do something in proportion to your goal. To make it smoother, you just turn down the proportion. I tried making the AI driver use a P-controller to steer in order to stay on the optimal racing line. When you introduce a delay in the system between input and reaction - which is what happens when your car is subject to physics, and when steering changes are rate limited - this is when animation smoothing (P-controller) causes a really surprising behavior. The lower you turn down the P value, the more unstable the system becomes. I was confused at first... why would reducing the input cause the system to go from oscillating to divergent? But when someone suggested reading up on PID controllers, it all made sense, and I was a bit stunned that I hadn’t even heard about them during my undergrad CS years.
- glouwbug 7y agoMy prof spent 8 whole months teaching us systems modeling and PID mathematics only to tell us there's no reasonable way to set your PID values... You gotta guess and check!
- adamweld 7y agoPerturb and observe, my friend. An excellent model for life.
- basicplus2 7y agoA. Set I and D to zero B. Adjust P for 1/4 wave damping , Adjust D to improve response , Adjust I to correct Offset Repeat B. Repeat B. Repeat B. Repeat B. Repeat B. Repeat B. . . . .
- CamperBob2 7y agoI usually end up saying "Screw it" and adjust the value under control to remove half the error at each timestep. Surprising how often that's good enough. Many processes like temperature controls want to settle, you just have to help them out a bit. Applying a full PID algorithm to every control problem is a bit like using TCP/IP to solve every networking problem. It will work, but you'll often do better with a domain-focused solution.
- tlb 7y agoTemperature control problems are only first-order (heat->temperature), so they're much easier to control than a second order system like force->velocity->position.
- CamperBob2 7y agoYep, totally. Motion control would be a different case altogether. Zeno's Paradox was supposed to be a puzzle, not a solution.
- salty_biscuits 7y ago
- wycx 7y agoI have also found this useful: http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/ http://brettbeauregard.com/blog/2011/04/improving-the-beginn...
- CamperBob2 7y agoThis appears to be a really nice series of articles, but wow, what an annoying format. Just give me a .PDF or single .html page, don't make me click 'Next' thirty times. :( He's not even doing that to show ads. He's just doing it because, hey, it's not like he wants to read it.
- HeyLaughingBoy 7y agoI've been using his arduino PID library to stabilize a camera platform and the library works pretty well.
- RhysU 7y agohttps://github.com/RhysU/helm/blob/master/README.md https://github.com/RhysU/helm/blob/master/README.md is an implementation of such a thing.
- ragona 7y agoOne of my coworkers (colmmacc@ on twitter) has been giving talks [1][2] for years on how PID loops and control systems theory apply to software, and that I’m totally convinced that it’s an undermined vein of excellent thought. I’m working on applying this to a piece of software I’m building and I’m very excited. 1: https://www.infoq.com/presentations/pid-loops/ https://www.infoq.com/presentations/pid-loops/ 2: https://m.youtube.com/watch?v=O8xLxNje30M https://m.youtube.com/watch?v=O8xLxNje30M
- ssivark 7y agoI know little about web services orchestration, but I feel that a lot of algorithms from control theory / signal processing / optimization / continuous math / etc will apply to software contexts if one “squints right”. And such solutions will often end up being more robust and better behaved (and arguably more intuitive) — an ounce of math often saves a thousand lines of clumsy code. As Peter Naur argued, writing software is primarily about building a functional theory of the domain.
- bloaf 7y agoI personally feel process control is a significantly under-appreciated discipline. I've been at an academic lecture where a process control engineer used the example of air conditioning to explain that when your system is controlled, you have to be extremely careful about correlation and causation. If you're not, you can very easily conclude that because the room is hot whenever the AC is running hard, that the AC running hard makes the room hot. He then showed that biologists were making this mistake with respect to certain biomarkers and cancer. Process control is interesting even in philosophy. For example, there is a process control theorem which proves that the maximally efficient regulator must have an accurate model of the process being regulated. Therefore, anyone who argues that evolution gives us no reason to expect our brains give us an accurate picture of the world must be ignorant of process control. After all, our brains are regulators of our environment for our survival; therefore the maximally efficient way for our brain to regulate our environment is for our brain to have an accurate model of our environment.
- monadic2 7y agoFor those without reference, PID refers to Personal Inflammatory Disease, according to a quick google.
- gregschlom 7y agoI mean, why not just read the article? It's on the first page of the article (third page of the pdf, after the cover page and the author's note): The "PID" in "PID Control" stands for "Proportional, Integral, Derivative".
- monadic2 7y agoSure, I was commenting on the HN title being inappropriate out of context.
- deleted 7y ago[deleted]
- annoyingnoob 7y agoI read this in a magazine years ago, super helpful. I learned the most when I sat down and worked though it by hand. In practice, I've never needed D, PI has been enough to do the job.
- ssivark 7y agoIn the typical pedagogy, D is only necessary if you feel the PI isn’t responding fast enough (for rapid control). D, being very sensitive to high frequencies, helps with that.
- themeiguoren 7y agoAnd the reason you’d leave it out is because a PI controller is guaranteed to be stable with positive gains. Throw the D term in there and you have to start checking pole positions to make sure your system doesn’t blow up.
- analog31 7y agoI've seen quite a few control loops where, when you dig down to the inner loop, D is set to zero.
- leon_sbt 7y agoThis is a well explained and concise guide on theory and implementation behind it. But like many things, there's no replacement for getting your hands on a real life system and gaining real life intuition. The best way to learn this? Get/make a test bench with safe-ish motor and encoder system. Play with values and measure at the performance in the system. Increasing the P value gains, makes the system "stiffer" but at the expense of stability. Put your hand on the flywheel and "fight it" safely. You can feel the I (Integral) value winding up against your steady state errors. It's quite magical. As you start to chase the highest performance for your system, you start to think about alternative control strategies. Eventually you will dream up the concept of feedforward control loop. Try to automate the the picking of PID values, then you start to learn about Ziegler–Nichols tuning method. Gain Scheduling. Non Linear Control theory. It never stops. (If you do any of this, please make sure the motor/flywheel won't kill you if it goes unstable, and please wire a E-stop that's easy to access when it's unstable)
- pietroglyph 7y agoThis is how I teach middle school and high school students basic controls. They implement and tune a proportional controller, then the derivative part, and then I give them a feedforward model for the plant (usually a brushed DC motor.) The PD controller and feedforward is very easy to write and is quite approachable once you see how simple it is, and it can be very exciting to see a motor “do as you command” before your eyes. I avoid integral control because it’s less effective and much harder to deal with than good feedforward. Most of the mechanisms we use (in the FIRST Robotics context) have a feedforward model and good system-identification tools so this works out well.
- computerex 7y agoReal life systems don't have to be physical. You can do a lot by playing around with digital PID controllers, graphing the sensor value over time and seeing how the graph changes as a response to changes in the gains. The benefit of this approach is that anyone with some programming skills can do it right away without any hardware.
- baylessj 7y agoThis guide is good at going in depth without being too heavy on the jargon. I've found that it's still a bit much for younger students learning about the concept and related math for the first time. George Gillard's intro to PID [1] has been a staple of VEX robotics instruction because it fills this niche -- it's an excellent resource for teaching high school students and younger. 1. http://georgegillard.com/documents/2-introduction-to-pid-controllers http://georgegillard.com/documents/2-introduction-to-pid-con...
- flyinglizard 7y agoI designed control systems for brushless servo motors and more recently did the power control for very power hungry ASICs of a very well known company. Tuning is important but when you come to design a control system, you need to look at the overall system - and this is something textbooks don't really tell you. Control systems are all about reacting quickly enough and accurately enough. Delay and poor incoming/outgoing signal quality are the enemies of the control system: 1. The delay from sensor to controller (e.g. SPI bus incurred delay between your gyro sensor and your processor) 2. The bandwidth of each component. If your gyro sensor is only 10hz bandwidth, it'd be difficult to control anything reasonably fast. Note that bandwidth is often given in frequency to 3dB attenuation (half the amplitude) - that's not enough, you need to understand the phase distortion: in other words, as you approach the bandwidth limit, does your signal get distorted in time? because that's very bad for a control system. 3. The resolution of your actuator - if you end up using an on-off actuator, it'd be impossible to do any precision control. Do you want to position a motor accurately? Make sure you use more than 8-bit PWM. 4. Static/dynamic response: things are usually not nicely linear. Things at standstill take a different amount of effort to move than once they are in motion. My experience has shown time and time again that if you get the system fundamentals correct, implementing and tuning the control loop is reasonably trivial. The secret is having a system that's an order of magnitude faster (higher bandwidth) than what you're trying to control. You really need to think about control systems in the frequency domain: "what I'm controlling requires the bandwidth of X, I need to sample with with n * X, my processor is this fast, my output signal is that accurate, this is the end to end delay". Someone once said "any non-linear system becomes linear when you sample it quickly enough". I don't know who said it or whether it's even remotely true for all parts of life - for control systems though, it's definitely a rule to go by.
- tuckerpo 7y agoThis is a very very common control scheme in the embedded world. I'm surprised this is so new to so many.
- jfim 7y agoThere are a lot of things that aren't part of the usual computer science curriculum, control theory being one of them. Many topics would be interesting to have some minimal exposure to, such as signal processing, operations research, etc.
- TimWescott 7y agoI wrote that article in 2000, and the really scary thing for me is that I'm now seeing code that obviously either came right out of it, or is only a few copy-pasta steps away from it that's just taken as "the way things are done". For the record -- it's one way to do it, but the code in there was primarily written to be as easy to understand as possible, not to be the World's Best Controller Implementation.
- mehrdadn 7y agoOh wow, so the article was written in 2000 and not 2016? And that's funny/scary. Hopefully those cases still end up being an improvement over not using PID at all?
- bloaf 7y agoEven disciplines which typically do cover process control in undergrad often treat process control with a bit of a "there be dragons" mentality. Not for nothing are PhDs mentioned in the title; if some industry employs process control engineers, their group certainly has a concentration of PhDs well above average.
- louwrentius 7y agoFor what it's worth: I use PID to control the fan speed of my DIY NAS. It uses the temperature of the hottest drive to determine if it needs to spin up the fans or not. Works very very well. The end result is an extremely quiet NAS even with 24 drives. https://github.com/louwrentius/storagefancontrol https://github.com/louwrentius/storagefancontrol
- carlob 7y agoI assembled a controller for my smoker from a cheap PID from aliexpress, a relay and a fan. It works like a charm and it's an order of magnitude cheaper than buying a complete solution.
- dang 7y agoDiscussed at the time: https://news.ycombinator.com/item?id=16257156 https://news.ycombinator.com/item?id=16257156
- carapace 7y agoI can recommend also "Feedback Control for Computer Systems, Introducing Control Theory to Enterprise Programmers" by Philipp Janert http://shop.oreilly.com/product/0636920028970.do http://shop.oreilly.com/product/0636920028970.do
- TimWescott 7y agoFYI, if you're a visual learner, check out my YouTube channel: https://www.youtube.com/channel/UC923b-omXUs0dnWOTDD7FhA https://www.youtube.com/channel/UC923b-omXUs0dnWOTDD7FhA, but be warned there's not as much there as I'd like. I do have all the material from "PID Without a PhD" in there -- just watch the three videos with "PID" in the title. I also recommend Brian Douglas's channel: https://www.youtube.com/user/ControlLectures https://www.youtube.com/user/ControlLectures if for no other reason than because I haven't posted a new video for three years -- but then, he's been posting on some Matlab channel, so you'll want to start with his and then move to that one.
- michaelt 7y agoThose look great! What would you recommend if the feedback is noisy enough that a derivative term would be mostly noise, but using a simple FIR filter to remove the noise introduces a delay which makes the system less responsive?
- TimWescott 7y agoFIR filters are the last thing you want in closed loop -- for the amount of filtering they do, they have way excessive phase delay. I'd use a derivative term with bandlimiting, and I'd accept that if I couldn't get the response I needed using feedback in that case then I'd either investigate using feedforward, or I'd work on changing the sensors on the plant so that they're less noisy.
- data_ders 7y agoI'm currently in Georgia Techs OMSCS program and taking Sebastian Thrun's AI for Robotics class on Udacity (free to access). I thought the Lesson on PID controller was really solid. Here's the first lecture. https://www.youtube.com/watch?v=-8w0prceask&feature=emb_logo https://www.youtube.com/watch?v=-8w0prceask&feature=emb_logo
- daveguy 7y agoThis is one of my favorite PID blog posts. Improving the beginners pid: http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/ http://brettbeauregard.com/blog/2011/04/improving-the-beginn...
- themeiguoren 7y agoAs a controls engineer, I’ve pointed people towards that series of posts more than once. Great explanations.
- JadeNB 7y agoI know it must be a foolish question, but Wiki gives too many candidates and the linked PDF seems to assume you know. What is PID?
- markjdb 7y agoIf anyone is interested in their application to system software, the FreeBSD kernel uses a PID loop to regulate memory reclamation: https://svnweb.freebsd.org/base/head/sys/kern/subr_pidctrl.c?view=markup https://svnweb.freebsd.org/base/head/sys/kern/subr_pidctrl.c... https://svnweb.freebsd.org/base/head/sys/vm/vm_pageout.c?view=markup#l2064 https://svnweb.freebsd.org/base/head/sys/vm/vm_pageout.c?vie... It does a pretty good job of maintaining system responsiveness and latency when there's sustained memory pressure, at least much better than the simpler hysteresis loops that are commonly used for this sort of thing.
- metaphor 7y agoI'll be the first to admit that I hastily presumed you were conflating the control theory PID acronym with "process ID", then I looked at the code and had a genuine WT-actual-glorious-F moment.
- Animats 7y agoIt's an OK explanation of a PID controller. They're easy to code; tuning is the hard part. There are lots of approaches to tuning. This author offers a simple one. I note that he cites "James Clerk Maxwell: “On Governors”. Proceedings of the Royal Society, #100,1868".[1] Yes, 1868. Yes, that Maxwell, of Maxwell's Equations. That paper is worth reading. Right there, linear control theory was born. And that's about where the state of the art was until 1950 or so. Modern control theory is closely tied to machine learning. Except that the control theory people want solutions that don't suddenly do funny stuff for some inputs. The math is way beyond me. Even control theory PhDs have trouble now. [1] https://www.maths.ed.ac.uk/~v1ranick/papers/maxwell1.pdf https://www.maths.ed.ac.uk/~v1ranick/papers/maxwell1.pdf
- senderista 7y agoSpecifically, reinforcement learning is closely related to optimal control theory.
- jbay808 7y agoI think there are some important steps between Maxwell and 1950 that are worthy of mention. Black's paper on negative feedback amplifiers, for one; the invention of the PID controller itself, for another...
- Animats 7y agoMaxwell had P and I, but not D. Derivatives are hard to do mechanically, tend to be noisy, need filtering, and thus have lag. An aircraft vertical speed indicator is one of the few widely used mechanical differentiators. Enough gain to allow throwing it away with negative feedback to get linearity was a ways off in 1868.
- LolWolf 7y agoModern control theory (not counting RL, which is rarely, if ever, used on live controllers) is essentially two camps: PID with tuning and MPC (model predictive control). There is some optimal control theory not in either of these camps, but it’s not the norm. The latter is often studied under the umbrella of optimization theory (convex optimization mostly), but most aspects of it are well understood for most systems we care about (with some notable exceptions, of course). I wouldn’t quite say that “even control theory PhDs have trouble now” as there is plenty of work done on the field and many cases are quite useful (but they certainly have many topics to choose from for their theses!) :)
- totorovirus 7y agoIt is quite surprising that this article not related to CS made up to top news in hacker news. There must be a lot of non-CS engineers here.
- creatornator 7y agoPID is very related to CS, especially in the domain of digital signal processing. And yup, I would agree that there are a lot of non-CS engineers here, we are pretty common :)
- totorovirus 7y agoI learned this in control systems in electrical engineering course. Maybe graduate courses do have PID for CS majors, but haven't seen them yet
- jbn 7y agoany large-ish system is going to have admission control and stability issues, better design those than leave them to chance...
- rbrtdrmpc- 7y agoCS engineer here, i had at least 3 exams about control theory (quite the standard here in Italy).
- jbn 7y agoThat's odd. To me control theory is really an EE topic (granted EE and CS are often part of the same department). I did EECS (and did some control theory as part of the mandatory subjects of study) and it feels like CS/SE people usually have no idea that control theory even exists..
- no-s 7y agoI bumped this because it's an underappreciated topic in CS. I never really had any formal education but PID and MPC have been in my bag of systems hacks for decades now. I wish I had more lives to expend in enjoyment of the pursuit of control theory. Frankly computing is starting to really get interesting again, I feel like it's 1979 redux.
- pidtuner 7y agoIt is very easy to tune PID now a days with free tools like https://pidtuner.com https://pidtuner.com
- redis_mlc 7y agoLinux used to have a bunch of control theory-type heuristics implemented in the scheduler by Con Kolivas. It was removed quite a while ago. https://en.wikipedia.org/wiki/Con_Kolivas https://en.wikipedia.org/wiki/Con_Kolivas
- aguki 7y agoIn some cases especially hardware, it is essential that PID tuning is done safely. I've implemented this reinforcement learning algorithm in C++ for safely tuning a PID controller on a hardware system with successful results i.e. has been successfully deployed at customer sites for in-situ tuning. https://github.com/befelix/SafeOpt https://github.com/befelix/SafeOpt http://papers.nips.cc/paper/6692-safe-model-based-reinforcement-learning-with-stability-guarantees http://papers.nips.cc/paper/6692-safe-model-based-reinforcem...
- JCharante 7y agoAh I remember reading this in high school. It's a recommended read/resource for kids learning to control their FIRST Robotics Competition (FRC) robots in autonomous situations or non-drivetrain mechanisms.
- srean 7y agoHN folks don't miss out on the older discussion here on HN https://news.ycombinator.com/item?id=16257156 https://news.ycombinator.com/item?id=16257156
- RMPR 7y ago> Bandwidth Limit Exceeded > The server is temporarily unable to service your request due to the site owner reaching his/her bandwidth limit. Please try again later.
- TimWescott 7y agoHeh. My website has crashed due to excessive bandwidth -- I'm working on it.