If I want to develope a control system for a microcontroller. What is the best/recommended way to control?
- Numerical integration e.g for-loop - Continuous time with digital controller
n = 1000; % Loops x = [0; 0]; for i = 1:n tic; dx = A*x + B*u; u = -L*x + r dt = toc; x = x + dx*dt; t = t + dt; endfor
- Discretion e.g transform a state space model to discrete model.
$$F = e^{Ah}$$ $$G = \int_{0}^{h}e^{At}Bdt $$
$$ x(k+1) = Fx(k) + Gu(k)$$
I don't have any experience with microcontrollers myself, but I will try to compare the two using the knowledge I do have. Both can probably be made to work if the sampling rate would be significantly higher then your bandwidth. But since the sampling rate is usually also used to generate the control input $u$, with zero order hold in between the sample times. Therefore I would say that the discretized state space model would be preferred. For this I would have to assume a (near) constant sample rate. It can also be noted that discretizing the continues time model can also be done with
$$ e^{\begin{bmatrix}A&B\\0&0\end{bmatrix}h} = \begin{bmatrix}F&G\\0&I\end{bmatrix}. $$
For the real continues time model implementation I would assume that you would not calculate the states directly yourself, but use an observer, which calculates the full state space from the outputs of the system. The integrated continues time model should be more flexible in variable sample rates. However it might be good to look into different numerical integration methods, because (forward) Euler's method might perform badly.
When using the discretized model, then you can make use of the theory for discrete Kalman filters. This can give you an estimate of the state before the beginning of a new sample time, so you can calculate a full state feedback control input without a delay.