News for hackers. Stuff that matters.
Re:PID Controller for controlling the number of servers in a... by wenc on Sunday July 04, 2021 @10:15PM (#27734139)
Just curious, how did you replace PID with MHE? PID is a control algorithm, while MHE is a state estimation algorithm -- MHE is not a control algorithm and does not perform control.

Did you mean MPC by any chance? (which MHE is often used in tandem with)

If so, MPC is indeed a superior algorithm, but it also requires a dynamic model (LTI, or state space). Such a model may or may not be easy to identify -- it would require the characterization of the dynamics of data center operations.

PID on the other hand, while less optimal, is "model-free" (technically it has a model, i.e. its tunings can be thought to derive from IMC or direct synthesis, even though in practice hand tuning is common) in that it can respond to a wide variety of circumstances without knowing much a priori about the underlying dynamics. PID tunings are also amenable to optimization (products like Loop Pro are used in industry)

Due to their simplicity, PIDs are capable of operating at much higher frequencies than more complex algorithms like MPC. PIDs operate in the order of miliseconds or faster, while MPC operates in the order of seconds to minutes because it has to solve an optimization problem at every iteration, which is too slow for fast loops. In the hierarchy of control, there's supervisory layers on top (RTOs), then MPCs then PIDs. It's usually not either-or, but all together, working at different layers.

Even in industries where MPC is dominant, PID control is still ubiquitous and used alongside it, especially for local regulatory control loops. I don't have enough insight into data center ops to know if PID control is good enough but in my experience PID can be good enough for many applications -- most control loops in the world are essentially still PID. Not because more advanced algorithms don't exist, but because PID has the advantage of being just good enough for most purposes. (cost is also an issue: PIDs are cheap, while licensing costs for industrial MPC software range from 10s to 100k$)

Re:PID Controller for controlling the number of servers in a... by lmilcin on Monday July 05, 2021 @04:11AM (#27735643)
In my case I built a model of espresso machine consisting of various thermal masses with different properties and impedancies between them. (Boiler heater element, water in boiler, scale on the boiler walls, boiler walls, grouphead, water in pipe between boiler and grouphead, water in pipe and pump between reservoir and the boiler, water in reservoir tank).

This model can estimate future temperature of brew water based on current and past temperature measurements in various points in the system as well as on amount of water being pumped through the system.

There are four temperature measurements being made:

- ambient temperature

- water reservoir temperature (the thermometer touches the reservouir), though I am pretty sure this one could be estimated from past operation of the boiler.

- boiler temperature (the thermometer glued to the outside of the boiler at a selected point below water line)

- group head temperature (the thermometer glued to the outside of the group head at selected point). This one could also potentially be estimated from past operation but I tried it and it complicates my model too much.

In particular the model is designed to be able to calculate a single parameter, what is going to be the water temperature if used for brewing coffee, at a point in future, if heating element keeps adding given amount of energy and pump pumps given amount of water.

The way the model is being used depends on what the machine is waiting for. For example, when you want to brew coffee, it delays start of brewing until it can achieve stable temperature.

To achieve this as fast as possible (ie power on from cold to stable temperature) the machine is heating water at maximum power and the model is being executed 50 times a second to estimate what will be maximum temperature attained by brew water if we shut the power now. The idea here is we want to run the heater at max power for as long as possible and shut it off at exact moment so that the heat that spreads will cause the brew water to achieve the exact desired temperature.

Mind that brew water temperature is not measured directly. I can only measure it experimentally with a modified portafilter.

The parameters of the system are being observed and I use other filters to correct the parameters as system changes. For example, the system can detect amount of boiler scale developing rather precisely, mainly due to how it affects impedance between water in the boiler and the temperature sensor.

---

Now, I am pretty sure it is overkill for an espresso machine. I am doing this to teach myself some control theory. But the effects are real and the algorithm works like magic -- the machine starts and achieves optimal temperature in shortest possible time and then keeps it stable with no over or undershoots that could affect the brew.

In todays world the chips that can run this model are being sold for pennies and the only real complication is rather precise, noise free temperature measurement that you need for this plus measurement of amount of water being pumped.

Re:PID Controller for controlling the number of servers in a... by wenc on Monday July 05, 2021 @05:32PM (#27742012)
This sounds like an on-off controller with a predictive model. In this configuration, the predictive model (PM) predicts the temperature p-steps ahead (using 4 measurements) and then feeds the predicted output to the on-off controller, i.e. something like

PM(yₖ, uₖ) → Tₖ₊ₚ

uₖ = {uₘₐₓ if Tₖ₊ₚ < Tₛₑₜ else 0} (on-off control law)

where k = current time, yₖ = 4 temperature measurements, uₖ= manipulated variables (heating), Tₖ₊ₚ = controlled variable, i.e. temperature p-steps ahead (k + p), Tₛₑₜ = setpoint temperature.

If you're doing predictions, I'm not sure the estimator is technically called an MHE since MHEs only estimate the current state, not future states (it cannot because one technically cannot know future measurements), so I call it a predictive model here. (unless you're doing MHE to estimate the current state xₖ and then feeding that into the predictive model to get Tₖ₊ₚ predictions...)

This can indeed provide smoother, more accurate control than PID alone because (1) it uses a model that accounts for more variables than just the controlled variable, (2) it requires less tuning to avoid over/undershoot because it is guided by a model vs simply through setpoint errors; (3) it's a special case. I think it's a very practical control configuration for on-off temperature control, which has tons of applications from oven control to immersion circulator control etc.

I don't think this configuration has a name, but it resembles a simplified version of model predictive control (MPC) except for the lack of an optimizer (the control law is on-off vs an optimal control law computed via an optimizer). It is however a much less general configuration than a PID because in the general case (not on-off) you still need a control law to do trajectory tracking, and that law tends to either be a PID or similar.

Re:PID Controller for controlling the number of servers in a... by lmilcin on Monday July 05, 2021 @07:03PM (#27742651)
> This sounds like an on-off controller with a predictive model.

Well, not exactly. At the startup, yes, but that's because the goal is to get to stable point as soon as possible. Think of this move like suicide burn made by SpaceX boosters coming back to Earth:) The most efficient burn would be done at 100% of thrust with minimum margins. In case of heater obviously the fastest way to get to temperature is to use 100% of heating power immediately and calculate when exactly to turn it off (or to transition to idle power).

But later the controller switches to maintain the temperature by producing power setting for the heater. The controller produces the desired power level as a value between 0 and 1 and this is then mapped (dithered) to turn the heater on/off for half cycles of AC power. The heater is only turned on/off on zero crossing to reduce emitted interference. For this I built a separate controller board equivalent to a solid state relay. I have actually used SCR diode pair + opto isolator + mechanical relay for safety (because SCRs may fail causing dead short).

> If you're doing predictions, I'm not sure the estimator is technically called an MHE since MHEs only estimate the current state, not future states (it cannot because one technically cannot know future measurements).

I guess this is why it is called estimator. Not only it estimates future, but also a parameter that cannot be directly measured.

I test the controller against modified portafilter with a precise temperature sensor in it, but in normal operation, obviously, I don't get this. In some sense this is an open loop controller.

Yes, I am using MHE to estimate current state (including model parameters) and use it to feed predictive model.

The current state of the system is quite complex, and it is possible to describe it in many different ways. I like to think about it as various pulses of energy traveling through the system.

One of my approaches to build predictive model was to measure effect of step pulses on the system (for example with the cold machine I apply 10s of full power, then measure the change over time). Then I tried to divide the operation of the machine into separate pulses (for example 1s of 70% of power) and superimpose predicted effects of those past pulses on future evolution. This is quite easy if you are just heating but quickly gets complicated when you also try to move water through the system. But I found it fun and gained some understanding of the thermal system.

Re:PID Controller for controlling the number of servers in a... by rblatz on Monday July 05, 2021 @01:34PM (#27740093)
This all sounds extremely cool. What is the base espresso machine you are building this on top of? Do you have a blog where you document your process?
Re:PID Controller for controlling the number of servers in a... by lmilcin on Monday July 05, 2021 @08:09PM (#27743041)
So many people ask this. The base machine is Rancilio Silvia, selected because it is relatively cheap, well made, simple, and has no electronics in it. It is a collection of AC switches, thermostats and other AC-powered components.

I don't care about making a blog. I do it for fun. Given choice I would prefer to spend the time doing some more cool projects.

Re:PID Controller for controlling the number of servers in a... by plaguuuuuu on Monday July 05, 2021 @12:32AM (#27734644)
I had no idea this stuff existed. This sounds pretty exciting actually.

Is it really that hard/complex to calculate MPC that it can't be stuck inside a loop that runs at 1hz or less? Talking on decent generic or dedicated hardware. Some tiny SOC is a different story.

Re:PID Controller for controlling the number of servers in a... by wenc on Monday July 05, 2021 @05:40PM (#27742074)
MPC on chip was tried a decade ago [1]. It was based on the idea of parametric programming, where solutions of an optimization problem (a quadratic program, QP) were pre-computed and the control law essentially only involved doing lookups. Lookups were fast and avoided the computational cost of solving an optimization problem on-line.

However, as you can imagine, pre-computing optimal solutions is of exponential complexity so scaling up this technique was difficult at the time. (I'm not sure what the state of the art is).

Computation however has come a long way since, so today it might be possible to actually solve a decent sized quadratic program (QP) on chip at very frequencies in real-time.

[1] https://www.sciencedirect.com/science/article/abs/pii/S00981...

Re:PID Controller for controlling the number of servers in a... by rland on Monday July 05, 2021 @02:00AM (#27735019)
The difficulty with MPC is in the name -- Model predictive control. You need a model.
Re:PID Controller for controlling the number of servers in a... by lmilcin on Monday July 05, 2021 @04:56AM (#27735863)
The model need not be very complex. Think of it as first approximation. It is just, the better model you have, the faster you are going to achieve the result.
Re:PID Controller for controlling the number of servers in a... by pidtuner on Monday July 05, 2021 @03:45AM (#27735522)
https://pidtuner.com can help with that