# LQR for Inverted pendulumn

I'm studying an optimal control for the inverted pendulum in the following figure the state and the output of the system are defined as $$x=\begin{bmatrix}r & \theta & \dot{r} & \dot{\theta} \end{bmatrix}^T, \quad y=\begin{bmatrix}r & \theta-\alpha & \dot{r} \end{bmatrix}^T$$

so the continuous state space model at the upright equilibrium is \begin{cases} \dot{x}(t)&=Ax(t)+B_u u(t)+B_\alpha \alpha(t)+B_\tau \tau(t)+B_{F_s}F_s\text{sign}(\dot{r}(t)) \\ y(t)&=Cx(t)+D_\alpha\alpha(t) \end{cases} where the disturbance inclination $\alpha$ is suppose constant, $\tau$ is a torque disturbance,$B_{F_s}F_s\text{sign}(\dot{r}(t))$ is a Coulomb's friction term and $u$ is the input force applied at the cart. The numerical values for the transfer matrices are $$A=\begin{bmatrix}0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 2.8040 & -5.2658 & 0 \\ 0 & 18.5885 & -19.6959 & 0 \end{bmatrix}, \quad B_u=\begin{bmatrix}0 \\ 0 \\ 3.7629 \\ 5.5257 \end{bmatrix}, \quad B_\alpha=\begin{bmatrix}0 \\ 0 \\ -12.6447 \\ 18.5885 \end{bmatrix}, \quad B_\tau=\begin{bmatrix}0 \\ 0 \\ 0.5650 \\ 3.7629 \end{bmatrix}, \quad B_{F_s}=\begin{bmatrix}0 \\ 0 \\ -1.1187 \\ -0.5650\end{bmatrix}$$ $$C=\begin{bmatrix} I_3 & 0_{3\times1}\end{bmatrix} ,\qquad D_\alpha=\begin{bmatrix}0 & -1 & 0\end{bmatrix}^T$$ where $I_n$ is the identity matrix $n\times n$ and $0_{m\times n}$ is the null matrix $m\times n$.

For a digital implementation is required a suitable sampling of the previous system, so the discrete relative state-space model is in the form \begin{cases} x_{k+1}&=\Phi x_k+\Gamma_u u_k+\Gamma_\alpha \alpha_k+\Gamma_\tau \tau_k+N_k(\dot{r}_k) \\ y_k&=Cx_k+D_\alpha\alpha_k \end{cases}

Now there is my problem. To counteract the effects of constant rail inclinations a discrete-time integrator is appended to the model $(\Phi,\Gamma_u)$. It is taken in the simple form \begin{equation}\tag{1} w_{k+1}=w_k+r_k\end{equation} so the extended state of the system become $$x^{\text{e}}=\begin{bmatrix}x & w\end{bmatrix}^T$$ and the control state feedback is designed by minimization the cost function $$J(u)=\sum_{k=0}^\infty (x_k^\text{e})^TQx_k^\text{e}+Ru_k^2$$ where the cost's matrices $Q$ must be semi-defined positive and the scalar cost $R$ must be strictly positive.

I can't understand the function of the integrator $(1)$. The rail inclination affect both input and output of the system, so the integral action counteracts only the effect on output. Moreover, the state matrix $A$ is singular, so the system at least has one integral action by itself, and no more integrator has to appended to the system.

Maybe the integrator $(1)$ is considerer for drive the position of the cart to the start of the rail, i.e. $r=0$.

Thanks in advance for any suggestion.