# What adaptive controller can be used in embedded system with low RAM?

This is not a question for data science, hardware or programming languages. This is a more practical question about adaptive control for embedded systems, but still a math question.

I have tried to apply matrix algebra for subspace identification onto an embedded system. It did work, but I consumed all RAM memory at once. I tested it on a STM32F401RE micro controller that have 96 kBytes of RAM. In practice, a 100*100 hankel matrix, which are often used in subspace identification methods, it will be 100*100*8 = 80 kBytes, due to 8 is the size of the datatype double. Double takes 8 bytes because double precision is required when it comes to subspace identification. Even if I used float, it will be 100*100*4 = 40 kBytes and I have 96 kBytes in RAM.

So matrix algebra is not a good idea for embedded systems.

Another method that I don't have tried on embedded systems is the recursive least square (RLS) method. The only use for RLS is for stochastic systems e.g fast systems. Systems that "move a lot" under a short amount of time. If RLS is estimated on perfect controlled system, it will estimate a bad mathematical model and further it will cause instability due to the lack of volatility in the dynamical system. The benefit with RLS is it can be applied to an embedded system e.g Real-Time system.

But what if I have a first order or a high damped second order system that looked like this picture below. It represent a slow system such as water level control or temperature control.

Questions:

1. Which estimation method can be used for estimating models for deterministic systems e.g slow systems, and that method can also be applied onto an embedded system?

2. Which controller can be used to tune in the dynamical system and make it follow a reference point? Assume that we know a SISO transfer function of the current dynamical system.

The reason why I think transfer functions will be in better use than state space representations in embedded systems, is due to the limited RAM.

Edit: Do you think this linear least square method will work for estimating the parameters for a discrete ordinary differential equation, which can be transformed easily into a discrete transfer function.

$$\hat \theta = (\Theta^T \Theta + rI)^{-1}\Theta^T y(k)$$

Where $$r$$ is a tuning parameter, which will be in practice set to a very low number. It's because so $$\Theta^T \Theta$$ can always be inverted.

If I got the parameters, the model in other words. What can I use then for find my inputs? Which controller can I use? Assume that I want prediction too.

• Maybe extremum seeking control might also be an option. – Kwin van der Veen May 23 at 0:56
• @KwinvanderVeen How? – Daniel Mårtensson May 23 at 8:14
• Do you want to estimate the parameters online, and then control? Or you want to estimate and control simultaneously? I am asking because in the second case you will not have such a nice step response. Could you please specify the control goal? – Arastas May 23 at 8:32
• @Arastas Yes. First estimate, then control, then estimate again and then control. At the beginning I will have a very clear step response, but over time, that step response will act like a straight line on a LCD graph. My control goal is to have a controller that can learn the systems behavior from measurement data by using least square methods. But I don't know what least square method and I don't know which control method I want to use. – Daniel Mårtensson May 23 at 8:38

Note that there are basically two adaptive approaches: direct and indirect. With the indirect one, you estimate the model parameters, and then you design the control as if the system is known. With the direct one, you do not care about the parameters, and you directly tune the controller to ensure the desired behavior, e.g., reference tracking.

If the goal is only to follow the desired trajectory, then probably you can apply the direct adaptive model-reference control.

If the system repetitively executes the same task, then probably you should think about iterative control.

However, if you also want to estimate the model parameters for further prediction, you should use the indirect adaptation. As far as I see it form the figure, it is not reasonable to estimate a second-order model here, unless you have some parameters known, i.e. the white-box model. Assuming the first-order model, we have two parameters. To estimate these parameters, the system must be sufficiently excited, and in your case, it holds only during the transient, i.e. if the system has arrived to the desired position, you cannot estimate two parameters since the system does not move.

It seems two me that any RLS with some forgetting should perfectly work here. You apply the estimation procedure during the transient, you obtain some (hopefully nice) estimates, and then you compute your controller. Probably, you need to run the estimation procedure only once if you do not expect that the parameters vary.

However, since the problem you describe is rather general, the answer is very general too; it is hard to give some precise advice when the exact engineering problem statement is not known.

• Thanks. Well, I don't think RLS will work for deterministic systems. Only stochastical systems. Assume that we have estimate a system, then we control it and it works fine. But then when the system is follow a tracking point, the estimation of the dynamical system will not be dynamical, it will be statical model. Because the system have it's steady state point. I think that least square will estimate its parameters, even if those parameters will descirbe a static system. In hits case, I select the second-order transfer function as a grey box model. – Daniel Mårtensson May 23 at 9:51
• Sorry, I do not understand your point about the RLS. The RLS-like methods are widely used for identification of deterministic systems. However, as I said, your input should be sufficiently exciting. Thus, when you know that the system is excited (step response), you estimate it. If it is not, you do not. Or you can use some directional forgetting, but it is more advanced. Or use the RLS without forgetting; then you use all the avaliable historical data. It depends on your hypothesis on possible variation of the parameters. – Arastas May 23 at 11:00
• Ok. Estimating when the system have a step response, might work good with RLS. I don't need a forgetting factor. The system need to be automatic tuned by it self. But then the controller will be an auto-tuning controller, not an adaptive controller that estimating all the time. – Daniel Mårtensson May 23 at 11:05