
Control theory for fun and profit - evanweaver
https://fauna.com/blog/control-theory-for-fun-and-profit
======
rland
For a deeper dive, I can recommend the Astrom and Murray book. It's free:

[http://www.cds.caltech.edu/~murray/amwiki/index.php?title=Se...](http://www.cds.caltech.edu/~murray/amwiki/index.php?title=Second_Edition)

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.

------
dreamcompiler
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.

~~~
sgillen
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.

~~~
closeparen
Then the PHP analogy is right on.

[https://w3techs.com/technologies/overview/programming_langua...](https://w3techs.com/technologies/overview/programming_language)

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

~~~
udkl
possibly as a result of the dominance of wordpress

------
rozgo
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...](https://www.youtube.com/watch?v=8hfKs02QHR4&list=PLpDgOnZpfh6E3uxv4OYbmEugYsaJJLa3L&index=6&t=0s)

I can watch control systems all day.

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

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

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

~~~
fauna-ben
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.

~~~
jcims
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](https://www.youtube.com/user/ControlLectures/videos)

~~~
vladTheInhaler
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...](https://www.youtube.com/playlist?list=PLMrJAkhIeNNR20Mz-
VpzgfQs5zrYi085m)

~~~
jcims
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...](https://www.planetary.org/blogs/emily-
lakdawalla/2012/07060700-how-curiosity-land-part-3.html)

------
kqr
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...](http://web.archive.org/web/20160828042756/https://www.qualitydigest.com/inside/operations-
column/071116-process-monitor-charts.html)

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.

~~~
michaericalribo
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.

~~~
kqr
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.

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

------
solumos
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?

~~~
kortex
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

~~~
dreamcompiler
...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

------
carlosf
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.

~~~
cma
> 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.

~~~
deepspace
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.

~~~
Gibbon1
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.

Blah.

------
ithkuil
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).

------
thelittlenag
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!

------
ezconnect
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.

~~~
thr0w__4w4y
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:

[https://www.youtube.com/playlist?list=PLMrJAkhIeNNR20Mz-
Vpzg...](https://www.youtube.com/playlist?list=PLMrJAkhIeNNR20Mz-
VpzgfQs5zrYi085m)

------
p4bl0
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](https://www.youtube.com/watch?v=rln_kZbYaWc)

------
nullc
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.

------
Scarbutt
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.

~~~
freels
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.

------
in9
are took longer

