Hacker News new | past | comments | ask | show | jobs | submit login
Phenomenological Introduction to PID Controllers (vanhunteradams.com)
92 points by vha3 on Jan 10, 2022 | hide | past | favorite | 14 comments



I haven't done PID for a looong time but the best method for tuning PID loops is to look at the frequency response, somewhat along these lines: https://eng.libretexts.org/Bookshelves/Industrial_and_System...

This is much much better than the rules of thumb of increasing the proportional gain until the system becomes unstable etc. etc. You can tell what your gain and phase margins actually are which is difficult otherwise so you can push the correct parameters to the limit while maintaining margin.

There are also other approaches that rely on modelling the system and calculating the parameters based on the model... That can work but tends to be iffy for real world systems in my experience...


The old ship steering analogy:

P: is steering hard because you are off course.

I: is steering into the wind to counteract wind drift and into the current to counteract opposing currents as you move toward course.

D: is reducing steering input as you close on the intended course


For those who may not know, automatically steering ships was the problem PID controllers were invented to solve. So one might even say it’s more than an analogy!


Its control laws were even derived after observing an actual helmsman.

See https://en.wikipedia.org/wiki/PID_controller#Origins


Please also see "PID without a PHD" (I am not affiliated with these people):

https://wescottdesign.com/articles/pid/pidWithoutAPhd.pdf


I would be interested to hear people here smarter than me explain why PID is better than some simple explicit control logic made by a person.

They work well, but you have to tune it properly and don't have much flexibility to add in prior knowledge of non linearities etc which as a human we know about and know the complexities of.

I've found similar things with Kalman filters. Everyone is always keen to go PID, Kalman etc by default, but I've found getting them to behave correctly in complex systems can take ages and maybe never quite get there. Throw them out and do a few really simple explicit logic control steps like you would if you as a human were controlling it and bingo everything works great, the code is understandable by even non programmers as it's explicit and easy to deal with.

Don't get me wrong, I use all of the above, but I do find that PID and Kalman etc end up in places where a few if statements end up being just as good.

(Seriously not trying to flamebait here... Just never seen this discussed before)


> but I do find that PID and Kalman etc end up in places where a few if statements end up being just as good.

PID implementation isn't that much more complicated than a few if statements. In fact that's often were many solutions to control problem starts. Once one notes that the degree of control achieved is unsatisfactory one starts toying with that ad-hoc if statement based bang-bang control implementation, for example, overshoot problems, problems of not reaching the set point. So you add some inertia, you add some damping, you accumulate the cumulative error to counter it and behold you have reinvented a PID controller.

Math just formalizes and gives structure to this iterative rediscovery of PID control.

Yes obtaining the optimally tuned parameters isnt straightforward for an actuall messy system, but even with suboptimal parameters PID controller performance is often quite satisfactory.


It's just a well understood model that can handle certain physical phenomena reasonably well.

Let's say you're doing motion control. You have a linear motor, an encoder, and a load, and you want to control its position and velocity. The command signal is current. How do you approach that with a "simple explicit control logic" that will outpeform some flavour of PID (which most commercial motion controllers use).


They are very simple to model and thus well understood. You can easily calculate their error and stability for all possible input, even if you can't model the system very well. How do you proof your steps won't create unwanted oscillations for some kinds of input?

You can also implement them using very simple circuits or even completely mechanical, but that's probably not too important these days.

If you can model the system optimal control is even better. Much more robust than PIDs and can also be done linear using LQ.


For many applications, you're correct. Logic works just fine. However, we should also be careful about this because for many machines the programming interface to control it has a low level controller that may in fact have a PID to provide stability.

A PID control provides a method for a real-time, feedback controller. The real-time portion can be important for quickly and often smoothly guiding the system from one point to another. The feedback portion can be important because it provides a mechanism to adjust to a changing system based on something that we can tangibly measure. Though, at this point, programming logic could still do both of these things.

That said, a PID controller can provide theoretical guarantees that would be difficult to analyze using an arbitrary piece of code. At its core, we generally use a PID controller to control a system governed by a differential equation. For example, we could say that our system is well modeled by the system, `diff(y) = f(y) + u` where `y` represents the state, `f` the dynamics, and `u` the control. This `u` could be a piece of programming logic. It could be a PID controller. If we choose a PID controller, then we now have a new differential equation `diff(y) = f(y) + kp y + kd diff(y) + ki int(y)`. This differential equation is now all in `y`. At this point, we have theorems like Lyapunov stability that can tell us whether or not the system will converge to a particular point for all starting solutions within some region. This is a very useful and powerful guarantee. Without it, it may be possible for system to enter a feedback loop that damages the machine. Can we get the same for some logic? Sure. In fact, we can still use theorems like Lyapunov stability, but it's not always straightforward as to how what these equations look like and whether they're in a form that's easy to analyze. If the logic has time dependence, it can get hard. If there's some strange nonlinearities or discontinuties, like if statements, it can get hard. If the result can't be written as a first-order system, it can get hard. If there's a time delay and the result becomes a delay differential equation, it can get hard. Again, it doesn't mean it won't work and it doesn't mean that there may not be a stability guarantee, but ensuring that can be really important.

Now, candidly, most people don't ever model their system and check the differential equation. That said, if the underlying system is linear and time independent (or close to it), we can still use a PID and get stability guarantees without even knowing the particulars of the system. It may perform poorly, so we still need to tune the PID parameters, but there's still stability. If we take a linear system and add some logic to it and the logic is nonlinear, then it becomes a difficult question again to understand how the system will behave.

As one other side benefit, PIDs can also be designed from analog components, which can give a very, very fast response that can be much smoother than a microcontroller on an update loop. This is not always important, but nice when it helps.



Control systems (analog) was one of the courses I did poorly in university. And of course, my first job after school was working on (digital) control systems! It turns out digital is a lot easier than analog (to me, at least).

A couple things I discovered:

- When changing setpoints for your controller it helps to slowly ramp them to prevent disturbing the system. Calculate a (end-start)/steps and apply the delta every loop cycle.

- For integral wind-up, I found it more convenient to re-calculate the integral term when hitting a control limit.


When you get into the Z domain don't forget to do your long division of the polynomials.


Very well-worded and understandable. Thanks for this.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: