# How to generate reference trajectory for hidden states?

I would like to implement control law on a model that has states that are estimated from measurements.

$$u = -K\,x + G\,r$$

However, I'm confused about how to generate reference signal $r$. Not to mention finding the matrix $G$. Which would be inverse of measurement matrix $C$, but I don't have all states on the output and $C$ is not square.

I can easily generate trajectory for two of the states, however the two remaining states are only there to make the model behave more precisely and they are not easily understood because the model is result of model fit. I have done experiments with running a separate observer that observes the two generated reference states and estimates the other two. However this does not seem right.

If the control law is used for control then how is the reference trajectory usually generated and mapped to the full state vector $x$ so that it can be used with the control law? I don't want all states to go to zero after all, I want them to track a trajectory defined by two out of four states in $x$.

The signal $r$ is a desired value for the output of your system $y$. A common reference might be a series of steps, for example the first $T_1$ time units it is desired that the output is zero, then the next $T_2$ time units it is desired that the output is some other constant, ect. However in general the reference signal can be any real signal in time. But when feedback is combined with feed-forward the reference is often chosen to be sufficiently smooth, such that some of its time derivatives are continuous and known. But in general the reference signal is free to be chosen by you, the operator.

Usually the matrix $G$ is defined such that in steady state, which is assumed to be stable ($A-B\,K$ is Hurwitz), the output of the state space model $y$ converges to $r$. Is also important to note that this does assume that $r$ is constant. This statement can be formulated in an equation as follows

$$\begin{bmatrix} \dot{x} \\ y \end{bmatrix} = \begin{bmatrix} A & B \\ C & D \end{bmatrix} \begin{bmatrix} x_r \\ u_r \end{bmatrix} = \begin{bmatrix} 0 \\ r \end{bmatrix}$$

where $x_r$ and $u_r$ are the state vector and input in steady state respectively, such the corresponding $y$ is equal to $r$. In order to solve for what the state vector $x_r$ and input $u_r$ should be in steady state, given as constant reference $r$, one can use

$$\begin{bmatrix} x_r \\ u_r \end{bmatrix} = \begin{bmatrix} A & B \\ C & D \end{bmatrix}^{-1} \begin{bmatrix} 0 \\ I \end{bmatrix} r$$

this only work if the matrix consisting of $A$, $B$, $C$ and $D$ is invertible.

In order to assure that the $u=u_r$ when $x=x_r$ the control law can be adjusted to

$$u = -K\,(x - x_r) + u_r$$

which after substitution of the solution for $x_r$ and $u_r$ gives

\begin{align} u&= -K\,x + \begin{bmatrix} K & I \end{bmatrix} \begin{bmatrix} x_r \\ u_r \end{bmatrix} \\ &= -K\,x + \underbrace{ \begin{bmatrix} K & I \end{bmatrix} \begin{bmatrix} A & B \\ C & D \end{bmatrix}^{-1} \begin{bmatrix} 0 \\ I \end{bmatrix}}_G r. \end{align}

But if your model is not exactly equal to that of the plant you are trying to control then you are very likely to have a steady state error. In such a case you could maybe use adaptive control or extend the state with an integral, such as LQI.

• I almost got it working however the $[x_r; u_r]$ vector that is generated seems to produce controlled output that is several times the desired trajectory when used in conjunction with the control law. Is this solution equally applicable for discrete time case when Ax + Bu = x(t+1)? – Martin May 12 '18 at 9:02
• Right, I just noticed you assumed x dot being zero in the matrix that you multiply by r. I guess for discrete case that would be previous computed state $x_r$? – Martin May 12 '18 at 9:28
• Also, it is a bit unclear to be how this will work for a mimo system where the the ABCD matrix may not be square? In my case vector $y_r$ would ideally be made of two reference signals which the system must follow as a trajectory. Then I can not easily invert that matrix because it has more rows than columns. – Martin May 12 '18 at 10:20
• @Martin For discrete systems you would assume that $x_r(t+1)=x_r(t)$, so $$\begin{bmatrix} A-I & B \\ C & D \end{bmatrix} \begin{bmatrix} x_r \\ u_r \end{bmatrix} = \begin{bmatrix} 0 \\ r \end{bmatrix}$$ – Kwin van der Veen May 14 '18 at 6:03
• @Martin And in the MIMO case when the big matrix as a function of $A$, $B$, $C$ and $D$ matrices (with minus identity for $A$ in the discrete case) is wider then high then you could use the right inverse, which minimizes the 2-norm of $\begin{bmatrix}x_r^\top & u_r^\top\end{bmatrix}^\top$. And in the case that it is higher then wide, or in general if the rank of the big matrix is less then the number of elements of the vector $\begin{bmatrix}0 & r^\top\end{bmatrix}^\top$, then that vector has to lie inside the span of the big matrix. – Kwin van der Veen May 14 '18 at 6:22