Tune Your PID Controller
pidtuner.com
pidtuner.com
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.
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
* 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.
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.
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.
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?
The most complex part is the identification algorithm, which uses this algorithm: https://math.stackexchange.com/questions/1428566/fit-sum-of-...
I wonder if it could be portable to a microcontroller Are the blas routines expensive or large matrices?
(Another way is stopping integration when control output is at its physical limit, usually in addition to a numeric limit.)
As with all other PID parameters, this is something you'd have to figure out more-or-less empirically.
Testing with hardware would be checking that controller outputs stop increasing while the actuator is blocked away from its target value, usually running with much reduced speed/current etc limits. Ideally, of course, run unit tests and SIL, before trying it on actual hardware.
What saturates is the actuator. You could choose a single minimum/maximum value for the integrator, but it could be better ye to have a value that depends dynamically on how much room there is left in the actuator output.
For example, if the actuator is saturated, the integral term should not be increasing. That could happen at different values of the integral, so there is not a single min/max.
http://brettbeauregard.com/blog/2011/04/improving-the-beginn...
The I in PID is the only adaptive part. You can think of it as an estimator of an additive term that arises from e.g. friction or forces due to gravity.
But what about estimating e.g. a multiplicative term? It seems we should be able to do much better than PID, but without needing to commit all the way to a model-based method or reinforcement learning.
I wish there were some materials for how to move just beyond PID, but textbook treatments of LQR or MPC cannot even handle the I in PID.
The integral problem of LQR and MPC is indeed not the first topic discussed on textbooks, but there has been a solution for that for year, called "disturbance model". You you can have an "adaptive MPC" following some design procedures. Check out this reference:
https://folk.ntnu.no/skoge/prost/proceedings/ifac2014/media/...
I've run into a conceptual problem when using this approach with [infinite-horizon] LQR to try to recover what looks like a PID controller, which IIRC is due to the control u not necessarily converging to 0. This is expected, to counteract a constant disturbance, but it means that the sum doesn't converge.
I only skimmed the reference, but I did not find a discussion of this issue.
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.
Sometimes wisely and sometimes less so :)
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.
Getting filtering and update rate right is also important.
I'd happily pay for that. Tuning PIDs is tedious and takes away from flying.
(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.
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 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 here's a more traditional procedural animation I did recently that people seem to like.
Thanks for sharing and keep up the great work
PIDs have been a remarkably versatile hammer for lots of things that aren't nails.
> PIDs have been a remarkably versatile hammer for lots of things that aren't nails.
Love it
https://codesandbox.io/s/rocket-sim-final-with-position-cont...
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).
“Linear systems are important because we can solve them.” — Richard Feynman
On the other hand linear control theory is quite useful for many real-world problems.
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').
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)
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.
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-beginn...
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.
Heavily used for industrial automation, hackers here may know it from espresso machine hacking. (and I'm sure manyyyyy other uses)
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 :)
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)...
It has been explained.
It's a common feedback control scheme for signal processing and engineering control more generally.
(And of course it doesn't need to explain what a Laplace transform is, as this is aimed at control engineers)
It's a dynamic control loop.
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.
https://github.com/RicardoMonteiroSimoes/ClosedLoopControlBl...
It contains several blocks,P,I,D,PID,PT1 and PT2, basically the ones that were teached to me
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.
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.