# State feedback design for the Apollo moon lander
which has similar dynamics as a quadcopter


```python
import numpy as np
import sympy as sy
import matplotlib.pyplot as plt
import control as cm
sy.init_printing()
%matplotlib notebook
```


```python
k1, k2, h = sy.symbols('k1, k2, h', real=True, positive=True)
s = sy.symbols('s', real=True)
z = sy.symbols('z', real=False)
```


```python
A = sy.Matrix([[0,0,0], [1,0,0], [0,k2,0]])
A*A
```


```python
A*A*A
```


```python
Phi = sy.eye(3) + A*h+ A*A*h**2/2
Phis = sy.eye(3) + A*s+ A*A*s**2/2
Phi
```


```python
Phim = sy.exp(A*h)
Phim
```


```python
B = sy.Matrix([[k1],[0],[0]])
```


```python
Phis*B
```


```python
B
```


```python
Gammas = sy.integrate(Phis*B, s)
Gamma = Gammas.subs({s:h})
Gamma
```

## Discrete-time state space model
\begin{align}
x(k+1) &= \Phi(h) x(k) + \Gamma(h)u(k) = \begin{bmatrix}1 & 0 & 0\\h & 1 & 0\\\frac{h^2k_2}{2} & hk_2 & 1 \end{bmatrix} x(k) + k_1h\begin{bmatrix}1\\\frac{h}{2}\\\frac{k_2h^2}{6} \end{bmatrix} u(k)\\
y &= C x(k) = \begin{bmatrix} 0 & 0 & 1\end{bmatrix} x(k)
\end{align}

In the rest of the development, we will work in normalized time, that is $h=1$ and the sampling period is the unit of time. This gives the model
\begin{align}
x(k+1) &= \Phi(h) x(k) + \Gamma(h)u(k) = \begin{bmatrix}1 & 0 & 0\\1 & 1 & 0\\\frac{k_2}{2} & k_2 & 1 \end{bmatrix} x(k) + k_1\begin{bmatrix}1\\\frac{1}{2}\\\frac{k_2}{6} \end{bmatrix} u(k)\\
y &= C x(k) = \begin{bmatrix} 0 & 0 & 1\end{bmatrix} x(k)
\end{align}

## Check observability and controlability


```python
Wc = sy.Matrix(sy.BlockMatrix([[Gamma, Phi*Gamma, Phi*Phi*Gamma]]))
Wc
```


```python
sy.det(Wc)
```


```python
C = sy.Matrix([[0,0,1]])
Wo = sy.Matrix(sy.BlockMatrix([[C], [C*Phi], [C*Phi*Phi]]))
Wo
```


```python
sy.det(Wo)
```

## Feedback design
Desired poles (3) in z=0.7, z=0.7+0.1i, z = 0.7-0.1i 





```python
pd = np.array([])
Phi_n = np.array(Phi.subs({h:1.0, k1:1.0, k2:1.0})).asarray(float)
Gamma_n = np.array(Gamma.subs({h:1.0, k1:1.0, k2:1.0}))
l1,l2,l3 = sy.symbols('l1,l2,l3')
L = sy.Matrix([[l1, l2, l3]])
Phi_min_GL = Phi_n - Gamma_n*L
Phi_min_GL
```


```python
np.asarray([1,1,1], dtype=float)
```




    array([1., 1., 1.])




```python

```

56065384b16088306ecd484cf2b9d7c5a88060fb
ipynb
Jupyter Notebook
state-space/notebooks/Apollo-moon-lander.ipynb
kjartan-at-tec/mr2007-computerized-control
16e35f5007f53870eaf344eea1165507505ab4aa
MIT
2020-11-07T05:20:37.000Z
2020-12-22T09:46:13.000Z
state-space/notebooks/Apollo-moon-lander.ipynb
kjartan-at-tec/mr2007-computerized-control
16e35f5007f53870eaf344eea1165507505ab4aa
MIT
2020-06-12T20:44:41.000Z
2020-06-12T20:49:00.000Z
state-space/notebooks/Apollo-moon-lander.ipynb
kjartan-at-tec/mr2007-computerized-control
16e35f5007f53870eaf344eea1165507505ab4aa
MIT
2021-03-14T03:55:27.000Z
2021-03-14T03:55:27.000Z
Qwen/Qwen-72B
1. YES
2. YES