Hacker News new | past | comments | ask | show | jobs | submit login
Control theory for fun and profit (fauna.com)
195 points by evanweaver 17 days ago | hide | past | favorite | 47 comments

For a deeper dive, I can recommend the Astrom and Murray book. It's free:


This subject is tightly coupled with system modeling, and can touch many different domains:

    Cruise Control
    Bicycle Dynamics
    Operational Amplifier Circuits
    Computing Systems and Networks
    Atomic Force Microscopy
    Drug Administration
    Population Dynamics
Cheap computers are making it easy to make controllers that can reliably control systems with hundreds or thousands of variables and unknown dynamics.

PID loops are to control theory what PHP is to computer science: It barely scratches the surface but it sort of works some of the time.

If you really explore control theory you'll learn when the P or the I or the D is unnecessary. Or when you need a second derivative (not just the first). And it'll often give you closed-form solutions for the coefficients so you're not just blindly hunting around in parameter space.

Not sure if I agree with the analogy. The figure I often seen thrown out is that PID control in one form or another is used for something like 90%+ of all controllers found in the wild. And they can usually be made to work very well for whatever problem you have.

Huh, TIL, thanks. As a young and non web programmer I had no idea php was still so dominant in the wild.

possibly as a result of the dominance of wordpress

You're right. But they are a lot easier to build correctly the first time if you understand the math beneath them.

There's also a class of controllers that contain a PID loop, but that dynamically optimize the PID parameters.

Control theory for fun can be really fun. Using control systems for solving problems you are familiar with can help develop an intuition, that you can then map to other problem domains. Years ago a peer at LucasArts taught me how to use PIDs for game cameras, and I've used them everywhere since.

Very simple rules can create lifelike emergent behavior. This is an example of 2 simple motors using PID to try to target a red dot, in 3D, with gravity on: https://www.youtube.com/watch?v=8hfKs02QHR4&list=PLpDgOnZpfh...

I can watch control systems all day.

That video reminds me of a puppy or dog when you hold food above it's mouth.

I can recommend "Feedback Control for Computer Systems, Introducing Control Theory to Enterprise Programmers" by Philipp Janert

They say they use a PID controller, but don’t write about the next step: how to choose the parameters for the controller?

There are at least 6 classes of approaches [1] for controller tuning. But they all involve the following: (1) starting with some initial guesses for tuning parameters (2) fine-tuning them in real-life.

If you have a (rough) model of the system e.g. a transfer function, you can invert the model to get some initial parameters, and then fine-tune by hand.

If you don't have a model but are able to run tests [0] to collect data, you can apply any number of heuristic methods to systematically perturb the system to collect data to aid in tuning. Then fine-tune by hand.

Difficult loops e.g. MIMO (multiple input multiple output) loops that are larger than 2x2 where there's interaction between the variables (i.e. you move one variable, others move as well) require more analysis with loop-pairing techniques like RGA (relative gain analysis).[3]

For really difficult loops (or loops that have degraded over time), you can use software like Loop Pro [2]. This only makes sense if you're controlling something valuable and where loop degradation could lead to safety or performance issues. You probably don't need software to tune the PID in your espresso maker.


[0] Some systems are "open-loop unstable", which means they can go haywire if you perturb too much in the wrong direction. Simply blindly perturbing these types of systems is inadvisable. Process understanding/analysis is needed to avoid unstable situations.

[1] https://sites.chemengr.ucsb.edu/~ceweb/faculty/seborg/teachi...

[2] https://controlstation.com/pid-tuning/

[3] For really large MIMO systems, PID is no longer the right control mechanism. Advanced control techniques like MPC are used, where a computer repeatedly solves an numerical optimization problem at some frequency to calculate the next control moves. MPC is usually used to control chemical plants with hundreds/thousands of control variables. PID is used in local loops, whereas MPC sits on top as an optimizing layer.

Fair warning: this is a rabbit hole reaching the Earth's core.

Play around with this a bit to get a feel for it: http://codinglab.blogspot.com/2016/04/online-pdi-trainer.htm...

That's fair! We didn't use any fancy process for loop tuning. I basically played around with it until we were getting decent convergence.

Brian Douglas is the one delivering that MatLab video linked at the bottom of the article. He's got a ton of deep control theory lectures on his own channel, too - https://www.youtube.com/user/ControlLectures/videos

Steve Brunton also has a wealth of incredibly well-produced content on controls. Here is his control bootcamp series: https://www.youtube.com/playlist?list=PLMrJAkhIeNNR20Mz-Vpzg...

Wow that looks like a great series, thanks for the heads up. I'm just starting to dip my toes into basic PID control and am astounded by how deep (and predictive) the math can get in this domain.

Edit: Also, I learned a lesson about closed-loop systems with the launch (well, EDL) of the Curiosity rover on MARS. It's mentioned in this article [1] but the trigger to start lowering the rover on the crane wasn't some process monitoring distance from the ground...it actually had no direct notion of that. It just watched the throttle setting on the retro-rockets and started unwinding the winch when the throttles reached a reduced steady state setting...something expected once the descent stage had reached its hover altitude.

[1] (search for throttle) - https://www.planetary.org/blogs/emily-lakdawalla/2012/070607...

That looks like a good series to watch, thank you.

Totally unrelated, but the first time I saw that technique with writing on the glass and then flipping the video L-R was about 4 years ago when F5 did a good video introduction on elliptic curve cryptography [0]

They (F5) even wrote up the technical details of their Lightboard [1]

[0] https://youtu.be/dCvB-mhkT0w

[1] https://devcentral.f5.com/s/articles/lightboard-lessons-behi...

I have seen these videos and highly recommend them especially for people like me who want to get a sense of the traditional control theory literature, have seen similar concepts elsewhere and are trying to map the motivations and notations.

I like me the most popular answer which is: Have a little fun.

I had the same idea (ie PID loop to control system behaviour) some time ago to control traffic to external system so that it is just at the limit of throughput of that external system. The external system is really badly implemented and we had to put much effort into maximizing throughput.

In the end we are replacing HTTP requests with Kafka topics which let's the other system process as fast as possible without destabilizing. On our end we continuously monitor latency and have flow control based on consumer behaviour.

I mean if you can buffer and defer, always do that. Synchronous only when you have to?

Guess and “suck it and see” as old professor of mine in control theory would tell the class.

That would not be the way to tune the control loops on a nuclear reactor.

You can use https://pidtuner.com to obtain the gains based on an easy experiment

In relation to this, I've relatively recently discovered statistical process control (SPC) and the common process behaviour charts (also known as control charts). Donald Wheeler has shown that by taking the detection limits of these charts and turning them into compensation thresholds, they can turn into very powerful process controllers, too! (And maybe even better than the standard PID controller -- without the hunt for parameters.)

Took me a while to find the article, but here it is: http://web.archive.org/web/20160828042756/https://www.qualit...

The general idea is that PID controllers make unnecessary adjustments in response to regular, small, expected fluctuations in the input. These adjustments frequently increase variation beyond what a more tempered approach would have.

In my experience in manufacturing, SPC control charts are used to assess / analyze / monitor control, ie, quantify the degree to which a process is in control...but not often to actually manage / maintain that control. As another commenter alluded to, the vast majority of control systems are managed by PID loops, and SPC is a complement to those systems, not a replacement per se.

That is indeed how things are traditionally done. I (along with Wheeler) am suggesting that division does not necessarily have to exist, and the control charts themselves can serve as useful feedback mechanisms. In many cases they may even be more effective than a PID controller, with zero tuning required.

As Wheeler notes in his article, PID controllers are based on the assumption that calibration/adjustments are free. As any practitioner of SPC knows, adjustments are never actually free in the face of natural variation in the process.

I'm always curious about delving deeper into the history of control theory. Specifically, the work pertaining to Cybernetics in the late 40s/50s. Has anyone gone down that rabbit hole and found anything interesting?

In no particular order, here's some cybernetics-adjacent discoveries/inventions:

- PID theory, especially pole analysis

- linear quadratic regulator

- digital filter design

- the Hebbian rule of neurons

- distributed consensus: paxos, RAFT protocol, blockchain protocol

- STAR voting

- pretty much everything deep learning, in particular descent algos like Adaboost

- Conflict-free replicated data type (those are neat!)

- Lorenz attractors

- type theory

- category theory

...and Lorenz attractors leads to Chaos Theory which illustrates the central problem with nonlinear systems which brings up nonlinear control theory, state space control theory, etc etc

During my control studies, when talking about history, professors always use the centrifugal governor as a control application that triggered modern formal studies about control (basically discovering how useful it can be)


I have mixed feelings about control theory (education). On one hand, the maths are fun, on the other hand:

0 - For simple things PIDs work well, but then you don't need an entire course on Control Theory to learn how PIDs work.

1 - Most books focus too much on maths an very little on applications. You'll see the same toy examples repeated over and over in literature.

2 - For more complex things related to CT that's even worse. I've read some Multi-variable Control Theory books that were 100% maths, 0% on how to apply the goddamn thing you're learning.

3 - Complex CT techniques are often fragile (because you're modeling systems with high order polynomials), so most people just skip to using Machine Learning.

4 - You often need to make too many assumptions about a system to apply CT techniques.

I've actually used CT for a few things related to electronics circuits in my life, but overall I think most courses I took in university (Analog CT and Digital CT, Multivariate and Adaptive CT) were complete overkill and way too much theory without practical insights.

> 0 - For simple things PIDs work well, but then you don't need an entire course on Control Theory to learn how PIDs work.

Kalman filters seem pretty useful, especially with phones and stuff having an array of different sensors that can be combined, and probably require a class more than something more simple like a PID controller.

I used to be a control systems engineer in a previous life, working with ultra high precision position control systems, where PID just does not cut it.

Best approach I found was high-sample-rate LQE / LQR control - the LQE part is a Kalman filter, which is a piece of cake now, but was very hard to achieve with available hardware 25 years ago.

The biggest enemy of simplicity was nonlinearities, and much of the 'art' of precision digital control system designs was in knowing how to linearize them through software tricks and/or adapt the algorithm to provide piecewise linear control.

I worked on but didn't design the control algorithm for a zone controller where each of the five zones interacted with each other because they were part of a six foot tall quartz tube. There was compensation for the heating elements being nonlinear. And because the thermal mass was basically nothing radiation losses dominated it's behavior. Some of the control variables were squared then scaled. And zero overshoot was allowed for the hottest zone. And because it was a batch process it had to heat up quick.

I had to re-tune one after they replaced the quartz chamber.


As a control engineer and main developer of https://pidtuner.com, I never expected control theory to be widely used outside the industrial world (specially for solving certain CS problems)

At work we have a problem in a different domain that I had planned to use an approach like this on. The extra resources that folks have linked to or provided are quite helpful. Thank you!

There was a youtube video series that explains the PID control system very well. It was a professor standing in front of a whiteboard, half body shot and the videos are 10 to 15mins long and about 20 of them. It's now gone I wished bookmarks are forever. It's probably been deleted or made private. He explained the concept very well and the length of the video is just enough so you can absorb what was discussed and take a pause before playing the next video.

Not sure if it’s what you are/were referring to, but somebody else a little lower in this thread mentioned Steve Brunton’s control boot camp series on YouTube:


I recently discussed about fuzzy logic with a colleague, and it seems to me it could be applied here for such controllers. The advantage with fuzzy logic controllers is that you do not have to know the system that well in advance. I just looked for a short video intro and found this if anyone is interested: https://www.youtube.com/watch?v=rln_kZbYaWc

I for one am hoping to see a Zachtronics-like game where you get presented a chemical factory and then program all the relevant control logic.

Maybe part of the game could be determining where to add instrumentation of various kinds or making changes to the process. Extra fun is when the process behaviour depends on feedstock properties that aren't directly observable or environmental conditions.

Another trick for reducing tail latency with minimal utilization increase is to fire the second call earlier but send a cancellation signal when the first response arrives (e.g. a udp packet is usually good enough).

This works when the cost of managing the request queue is low relative to the coat of serving the requests themselves (usually true whenever there is some IO involved).

What's the catch with this database? skimming the website, it seems to promise too much. Impressive if all those features work well together as advertised.

There’s no catch. No database is going to work for every use case, but we’ve built FaunaDB to be general purpose, and suitable for many of them.

are took longer

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