12 ms·
Tune Your PID Controller
- tonetheman 5y agoIf only the site explained wtf a PID controller was ...
- sokoloff 5y agoAbove the fold (and in the first five words of text) is a link to describe what a PID controller is.
- McGlockenshire 5y ago> Above the fold The entirety of the "fold" on my screen is an absurdly giant and seemingly irrelevant image, overlaid with the text "Tune your PID", "It has never been easier", and two buttons. As I scroll down, the next thing my eyes catch is some mathematical nonsense, which tells me exactly nothing other than that this is a complex thing that is surely entirely over my head. To people that know what a "PID controller" is, it's probably informative. I came in assuming that there was some sort of controller for OS program PIDs and was unable to grasp the context at all.
- lbotos 5y agohttps://en.wikipedia.org/wiki/PID_controller#:~:text=A%20proportional%E2%80%93integral%E2%80%93derivative%20controller,continuously%20calculates%20an%20error%20value https://en.wikipedia.org/wiki/PID_controller#:~:text=A%20pro... Heavily used for industrial automation, hackers here may know it from espresso machine hacking. (and I'm sure manyyyyy other uses)
- cassianoleal 5y ago3D printers use it to control bed and extruder temperatures.
- trench0 5y agoCan confirm. We use PIDs in espresso machines to control the temperature of the water used in brewing. Some machines have simple thermostats that over/under shoot ideal brewing temperature and a PID will help keep a consistent temperature or even let you override the temperature (if your machine runs too hot or too cold).
- blt 5y agoDo you have any insight on why PID controllers are used for this application? PID assumes a system with a continuous control input, but water boilers usually have an on/off switch. Is the input something like a PWM value? My temperature controlled kettle does a way-more-than-optimal amount of switching when it's near the setpoint. That's consistent with using a PID controller into a PWM input. Maybe there is a market opportunity for a water boiler that uses control techniques better suited to on/off inputs :)
- repiret 5y agoA resistive electric heater can be PWM'ed to provide variable output. If you want to maintain a narrow temperature band, you can do that better by feeding the water temperature into your PID loop and have it control the PWM duty cycle, rather than to a simple on-off thermostat.
- rakah 5y agoYes! I use it to control both the amperage and temperature of a kiln.
- avs733 5y agoHuman beings are actually FASCINATING examples of PID controllers...especially as we learn. I'm soon to become a dad for the first time and so my partner and I have become much more conscious and aware of babies around us and watching them learn things. It's really fun to apply control theory to that... A friend has a young child who is learning to feed themselves. I was chatting with the friend while we drank beer and he helped the child eat dinner. using hands to pick up food (watermelon chunks) and bring it to mouth - very conservative and lossy PID-esque model of action, but you could watch small tuning improvements in real time. Then a spoon was introduced for sweet potatoes and the kid's PID controller clearly could not adapt to the change in mass in the system and we watched huge overshoots and control failures. Then it slowly improved...but isn't yet 'good' then we tried to explain this to our partners (both reside in the 'S' in STEM)...
- sigmaprimus 5y agoUs Billies on the Hill use them in our stills.
- cassianoleal 5y agoThe "Why" section, pretty much at the top of the website, has a link to the Wikipedia article. It has been explained.
- perpetualpatzer 5y agoIn its defense...if you need to tune one, you probably know the acronym. It's a common feedback control scheme for signal processing and engineering control more generally. [0]https://en.m.wikipedia.org/wiki/PID_controller https://en.m.wikipedia.org/wiki/PID_controller
- amelius 5y agoYou are right, but it would be nice to have a step-by-step explanation of how the tuning works. A black box is somewhat unsatisfying. (And of course it doesn't need to explain what a Laplace transform is, as this is aimed at control engineers)
- deleted 5y ago[deleted]
- daenney 5y agoIn the grandparent's defence, I thought it was about a cgroup controller: https://www.kernel.org/doc/Documentation/cgroup-v1/pids.txt https://www.kernel.org/doc/Documentation/cgroup-v1/pids.txt.
- verytrivial 5y agoBPS.space of 'model rocket version of Falcon Heavy' fame has a very good overview/introduction as part of a lecture to other model rocket builders: https://www.youtube.com/watch?v=4cw9K9yuIyU https://www.youtube.com/watch?v=4cw9K9yuIyU It's a dynamic control loop.
- deleted 5y ago[deleted]
- shawnz 5y agoThis is probably not necessary here but I'll try anyway. PID is a control loop algorithm: something which takes a desired value and an actual value from a sensor, and outputs something to some kind of actuator to try and get the actual value to match the desired value. A simple example of a control loop algorithm is the "bang-bang" algorithm used by your thermostat. When it's too cold the furnace turns on, and when it's too hot the furnace turns off. PID was discovered by observing boat helmspeople. It was observed that there are three major factors in their decision of how to turn the boat's wheel (the P, I, and D respectively). First, they set the wheel to approximately where they think it needs to be to achieve the desired angle. That's the P, or proportional part. Then they note the cumulative error over time, i.e. the distance away from the desired angle summed up over each moment that they are still waiting. As the cumulative error rises, they turn the wheel a bit further to compensate. This is the I, or integral term, which accommodates conditions where the controls are particularly dull, causing the proportional control to undershoot. Finally they observe the rate at which they are approaching the desired angle and compensate negatively if they are approaching it more quickly than they expected. This is the D (derivative) term, which accommodates conditions where the controls are particularly sensitive and the proportional control overshoots. PID just adds these three terms together with weights chosen for the specific application. Choosing those weights is the tuning process.
- Redimo 5y agoI made myself the work and created a very basic ClosedFeedbackLoop Example for java, for anyone that might want to try it out. It's old and has terrible documentation, but I also haven't touched it in quite some time. Either way, here it is: https://github.com/RicardoMonteiroSimoes/ClosedLoopControlBlocks https://github.com/RicardoMonteiroSimoes/ClosedLoopControlBl... It contains several blocks,P,I,D,PID,PT1 and PT2, basically the ones that were teached to me
- hawski 5y agoThanks, I missed this explanation years ago when I studied industrial control systems! I truly appreciate it. Though I wonder if that's me that got older and have better understanding of things that I now think I get it, or is it your explanation. Probably both.
- sigmaprimus 5y agoTL;DR over simple answer, it smooths the output by ramping up and down power supplied by predicting what will happen in the future based on history. Eg: The water is about to boil so I am setting the burner to medium from max to keep it at just below a rolling boil.
- dahart 5y agoA PID controller is a suspension system for data. And just like the shocks in your car or mountain bike, the components need to be tuned to make the ride smooth. PID controllers are used in ovens and thermostats and brushless motors and all kinds of things you probably already use.
- pidtuner 5y agoFor anybody interested in a simple introduction of PID control, I recommend watching Brian Douglas' videos https://www.youtube.com/playlist?list=PLUMWjy5jgHK20UW0yM22HYEUTMJfla7Mb https://www.youtube.com/playlist?list=PLUMWjy5jgHK20UW0yM22H...
- ChuckNorris89 5y agoI would have killed for stuff like this back in university. We had written some code in an early version of matlab in the labs that implemented the complex math but few of the students actually understood in depth what was going on and why. Everyone else remained puzzled even after the exams. I went to work in Automotive, implementing various control algos for EVs motor control and later in motorsport and finally managed to understand all the math behind the magic and to mentally visualize the impact and results even before the simulations were run :) Good times
- naoru 5y agoNeeds integration with Betaflight/INAV logs. I'd happily pay for that. Tuning PIDs is tedious and takes away from flying.
- pidtuner 5y agoDeveloper here, open a detailed issue on Github and will give it a look
- deleted 5y ago[deleted]
- ThePhysicist 5y agoI have a Lelit espresso machine with a PID and there are many forum discussions where people share their P, I, D values and argue which ones produce the best resuls. I haven't really fiddled with those yet but maybe I should give the article a try.
- pjkundert 5y agoA decent Python implementation of a PID loop controller is available here: https://github.com/pjkundert/ownercredit https://github.com/pjkundert/ownercredit
- jay3ss 5y agoI never cease to be amazed at the applications of control theory. In an optimal controls class that I took, someone presented a model that they developed to optimize the spread of information in the political space
- qrohlf 5y agoOh man. I wish I had the pages of manual PID tuning notes from when I was doing work with autonomous quadrotors in university to show what this thing replaces. Something like this would have saved me a massive amount of time, thanks for making it and thanks especially for wrapping it up into a nice interface.
- 5440 5y agoBefore I entered management, I spent about 15 years as an engineer building "greenfield" drug manufacturing sites using automation packages such as Allen-Bradley, Emerson DeltaV and Siemens. There is nothing more time consuming than trying to tune the hundreds of PID loops in these facilities not only during site acceptance testing of equipment, but also during validation. These companies try to offer PID packages but they were always really inadequate. I wouldve loved a tool like this. One of my biggest mistakes was tuning a loop during the winter shutdown on a large scale vaccine reactor. It dramatically increased the cells growth rate to a point where we would have had to modify our drug application. Understandably, the regulatory people had me de-tune the loop.
- taneq 5y agoOhh that's the worst. Something's out of whack and you can't fix it because it would mess with some other part of the process.
- londons_explore 5y agoI wish this site expanded a little to model a few things present in most real world systems: * Limits. Nearly all systems have a maximum and minimum input value. That should be modelled so behaviours when the limit is reached can be modelled. For example, a car has a top speed - and any further pressing of the accelerator will not make it go faster, but a PID loop will keep integrating any error, causing the system to not behave as expected. * 'Slack/Hysterisis' * Asymmetric systems - the force applied when pushing a system may not be the same as pulling. I really want a system where data can be thrown in like this, and it fit a model to the data and suggest not only PID values, but other types of controller which would be a better fit.
- pidtuner 5y agoDeveloper here, you are right. I have also considered such systems, but my free time is limited, so for the moment I just implemented the most basic case. Simulating limits will be included in the next release. Hysteresis is something more difficult, so will not handle any time soon. Asymmetric systems can be handled by gain-scheduling the PID (make a model for each region and schedule the gains), this is approachable in the middle term.
- londons_explore 5y agoWhile you're here... It would be nice to have examples of common systems with little diagrams. Eg. "Heater output to get to desired temperature", "Motor PWM to get to specified position", etc. Perhaps each with a little diagram/animation showing the input, the output, and some example data.
- pidtuner 5y agoMaybe the youtube videos help with this? https://www.youtube.com/channel/UCkRD7FztiFOdX50BUsOkcSQ https://www.youtube.com/channel/UCkRD7FztiFOdX50BUsOkcSQ
- DoingIsLearning 5y agoGreat work! Could you go into a bit more detail regarding the webassembly implementation in: pidtuner.github.io/pid/v1.0.6/pid_tuner_wasm.wasm Is it in C, C++, rust? Could you give a brief description of the internal logic?
- pidtuner 5y agoDeveloper here, ask me anything (wondered why the traffic exploded today until I opened HN).
- dokem 5y agoHow come you built this cool thing, read hacker news, but didn't submit?
- dls2016 5y agoCan you comment at all about the tuning algorithm you use? Do you monetize this? Currently work on a process control package (for the next few days, anyway) and am interested in your approach.
- pidtuner 5y agoThe tuning algo is the easiest part, the tool uses this one: https://folk.ntnu.no/skoge/publications/2001/tuningpaper_reno/tuningpaper_06nov01.pdf https://folk.ntnu.no/skoge/publications/2001/tuningpaper_ren... The difficult part is the identification algorithm, that is the challenging part, to accept all sorts of user data for all sorts of processes. There is no monetization, users can be patreons, by a mug, a shirt or simply help by sharing the site. I miantain it on my free time.
- valyagolev 5y agoThis can help setting up a thermostat, which is super annoying to do if you’re not used to it
- juangburgos 5y agoI have used this tool to tune the water level PIDs of several hydroelectric substations. I passed from spending days with manual fine tuning to a couple of hours of a simple experiment and tuning with this tool.
- rhodozelia 5y agoI’ve done level control for about 30 hydro electric power plants but with relatively small headponds or reservoirs, between 20m^6 to 50,000 m^2. You can calculate the gains to achieve critical damping, it was one of the first examples in my university controls textbook. Getting filtering and update rate right is also important.
- juangburgos 5y agoFor me the most complicated part when doing manually was the delay, because the water from the intake gates do not reach the headponds inmediatly. What I like is that the tool considers the delay in the tuning.
- rhodozelia 5y agoSounds like a different civil arrangement than I am used to. Is there a link to one of the plants you can send me so I can see the layout? I mostly work on high head run of river plants, but some are an upper and lower arrangement where the trail race of one plant is the head pond of the next
- juangburgos 5y agoNot sure I can (legal reasons?), but suffice to say thay feed multiple stations with multiple relatively large machines (+10MW). In some cases they have daisy-chained basins, so there are also level inner-loops to be tuned. So the approach has been using the pidtuner for tuning the inner loops first by keeping the outloops in manual. Then tune the loops outwards using the same approach. This has been the winning combination.
- leejoramo 5y agoI have an old commercial electric bakery oven with simple a simple 1 to 10 dial. I have looked into upgrading it to a digital thermostat with a PID, but have never figured out how I would set up the PID. This looks like a great resource.
- mhb 5y agoYou also may want to check out the BrewPi.
- SavantIdiot 5y agoOdd. From my perspective, there is no "perfect" PID tuning, so this function is confusing. I fly drones, and I adjust the PID tunings depending on how I'm flying: acrobatics, racing, filming, instruction, etc. Is there a function to tune the tuner? :) What I mean is: changing P impacts responsiveness to the transmitter controls, D affects wind gusts and sudden changes (fast loops anyone?), I is more for racing, its a bit more complex than that but you get the gist. Why pick one set? EDIT: (a) I didn't actually use the Webapp, after using it, there's more to it than my oversimplification. (b) I'm referring to the rates, not the PIDs. Thanks to the folks below ('pdituner' and 'somehnguy').
- pidtuner 5y agoThat is true, that is why there is a slider in the tool that allows you to trade-off performance for robustness. The bode plot is also an indication on how the closed loop performs in frequency domain, so you would normally choose different tunings according to specific use cases (e.g. some frequency response for tracking and a different one for just regulating)
- SavantIdiot 5y agoYou know, after I posted I noticed there was a "next" button and started using it (I thought it was GitHub only). You pretty much captured a lot of the tradeoffs. Very nicely, might I add: the UI/UX funneling is clever! I'm off to cram a step function into my flight controller... :)
- somehnguy 5y agoAre you sure you don’t adjust the rates depending how you’re flying? The PID tune can be objectively good or bad, and is highly dependent on your specific hardware setup. It controls how stable the drone is, you wouldn’t want to change your PIDs based on flying style as you would just be making it fly worse. For different flying styles you adjust your rates depending on how smooth/snappy you want it to feel and the desired deg/s of rotation.
- 5y ago
- polishdude20 5y agoWoah this is cool! I recently made a little sim for a gimballed rocket that uses a PID loop. It's really helped me tune my real rocket and get some good results: https://codesandbox.io/s/rocket-sim-final-with-position-control-0oq6u https://codesandbox.io/s/rocket-sim-final-with-position-cont...
- culopatin 5y agoMight be useful for my megasquirt corrections if I figure out how to use it. Maybe I’ll get that OEM idle again
- midjji 5y agoBuddy of mine did his master thesis as at a biofuel company a decade ago or so. He was supposed to do some advanced filter modelling, but do so he needed to configure the pid regulators to actually save the sensor values, not to mention turn them on. So he ran the pid configuration software, noticed they hadnt been tuned at all, set the values to something not catastrophically shit by just looking at the signals for a few minutes, then collected his data the next few days and went home to work on the thesis. It took a month before they figured out the random thesis worker no one paid attention too was the reason output was up 80%. He got a really nice bonus and job offer as a result. Then he actually tuned the pids using basic but proper system identification, but the largest gain is always from the most basic stuff, like turning the controllers on.
- pseudosudoer 5y agoI always love stories like this. When you first join a company who's product you admire, I feel like the implicit assumption is that they know what they're doing. Then after some detective work as a curious noobster you realize that everyone is just as clueless as you are!
- deleted 5y ago[deleted]
- weaksauce 5y agoYeah a lot of the plc coders in the field are not too good at the pid tuning stuff actually. some are but it's treated like some dark art instead of a fairly basic thing.
- rckoepke 5y agoVery few loops need any real tuning. For most of them, an incredibly wide range of value works perfectly well. Systems usually have a lot of slack in them. It's hard for most field engineers to get experience tuning loops when there are so few opportunities where the time investment can be justified. This is one of those cases however where field engineers who are around plcs all the time will say "oh I never needed that class" (process control theory) but they never needed it only because they didn't learn it, so they either don't see opportunities to apply it, or aren't assigned the task. I think this happens in computer science a lot as well. You often can go your whole (very successful) career not needing something you didn't learn, because your career would have been different if you had learned it thoroughly.
- theamk 5y agoIt is neither efficient nor optimal and could even be unsafe, but the most fun way to optimize your PID controller is on the actual plant with iterative parameter search. Watch your device whirr and attempt to jump off your table as your algorithm is trying to optimize the P factor! Quickly estimate how good the fit is just by looking at the actuator! (Disclaimer: think hard about safety before doing this, and make sure your device is strong enough or your motor is weak enough to ensure that no parts will be flying into people)
- jbay808 5y agoIn fact, just listening to the system in a quiet room can be a great way to determine whether your gains are too high, much better than simulations are likely to do.
- pidtuner 5y agoTrue to that, but this tool hopes to provide an educated initial guess.
- jay3ss 5y agoWe actually did this with a quadcopter for my undergrad capstone project. It had a tendency to wildly flail about so we had to go to the indoor basketball court/gym when no one else was there. It took a couple of weeks, but we got it working pretty well and developed and entire system for the quadcopter to take off, track/follow, and land on a moving RC car. Fun times!
- jedimastert 5y agoI was actually kinda hoping for a game where you could fiddle with dials and tune a toy simulation
- pidtuner 5y agoThat's literally what you can do with the tool. Did you clicked the "Get Started" button?
- jedimastert 5y agoSorry, I meant for more than one dataset. Also, this tool seems to be geared towards people who already get how PIDs work. It's completely valid assumption to make, I'm just not really in that group.
- spookthesunset 5y agoIt would be cool if there was like "quick tips" for how to get this data out of various PID'y things. For example how do I get data out of Marlin (3d printer controller) to tune my hotends?
- volker48 5y agoThere is a gcode to autotune the PID https://marlinfw.org/docs/gcode/M303.html https://marlinfw.org/docs/gcode/M303.html
- Scramblejams 5y agoPerfect timing! Just last night I picked up a half-done hobby project to write a fan controller for some of my server hardware, starting by reacquainting myself with PID theory. This'll be a great help, thanks!
- MrLeap 5y agoPID controllers are so fun. I experimented with using them to animate tentacles for a game I'm working on. They're great for all sorts of controllers in fiddly physics based systems. (https://twitter.com/LeapJosh/status/1327051175112421377 https://twitter.com/LeapJosh/status/1327051175112421377) Judging by some of the posts in this thread, it amuses me that I might have a leg up in the oil and gas industry.
- jay3ss 5y agoThis is really cool! Do you have any other animations? If you don't mind me asking, how did you use PID controllers to animate the tentacles?
- MrLeap 5y agoMy twitter is full of animations (https://twitter.com/LeapJosh https://twitter.com/LeapJosh) Not many other cool uses of pids specifically. Each tentacle is rigged to a chain of bones, somewhat ironically. The bones are physics objects I apply torques to. Every node has the same error function, which is "where is the tip relative to the goal?" so, theoretically, they should all be getting torques to help the tip get to the goal. Turns out this kind of works! https://twitter.com/LeapJosh/status/1321219814828945411 https://twitter.com/LeapJosh/status/1321219814828945411 Each particle there has a pid controller that adjusts the particles angular velocity so it'll fly towards a goal point in the form of a glowing man. https://twitter.com/LeapJosh/status/1395762486339645443 https://twitter.com/LeapJosh/status/1395762486339645443 here's a more traditional procedural animation I did recently that people seem to like.
- jay3ss 5y agoThis is fantastic and (from my POV) out of the box. I've only ever seen control theory used with cloth animation from some Pixar research papers I've skimmed so this really neat to see another application of controls in animation. Thanks for sharing and keep up the great work
- 5y ago
- dreamcompiler 5y agoThe math behind this is linear control theory (LCT) [0], which is quite interesting. LCT and the Laplace transform techniques at its heart (this is where the "s" terms on the web site come from) are not really that daunting and once you learn them you'll know whether you even need the I and D parts of the PID and what order of each you need. If we had an analogous "Machine Learning Theory", we'd be able to predict from first principles how many neurons we needed, how many hidden layers we needed, and what architecture (i.e. recursive, convolutional, etc.) we needed to solve a given problem. We don't have that now, but I hope we do some day. The good news is we do have such a theory for control problems (at least the linear ones). [0] https://en.m.wikipedia.org/wiki/Control_theory https://en.m.wikipedia.org/wiki/Control_theory
- pidtuner 5y agoYou are right, but the problem of a possible analogous "Machine Learning Theory" is that machine learning problems are highly nonlinear, and control theory has only been "solved" for linear problems. It we could solve nonlinear control that could immediately be applied to machine learning. “Linear systems are important because we can solve them.” — Richard Feynman
- dreamcompiler 5y agoFair point. But of course the reasons for the nonlinearities are different. ML is not inherently nonlinear; ML is only nonlinear because linear neural nets are not very useful. On the other hand linear control theory is quite useful for many real-world problems.
- j1elo 5y agoWhat code implementations of PID controlling do you know, to learn or base upon, to build an actual solution? I've successfully used this blog post series from 2011, which covers the principles behind a PID library for Arduino: http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/ http://brettbeauregard.com/blog/2011/04/improving-the-beginn...