# Apollo Lunar Module


```python
import numpy as np
import sympy as sy
sy.init_printing()
```


```python
s = sy.symbols('s', real=False)
J, g = sy.symbols('J, g', real=True, positive=True)

```


```python
A = sy.Matrix([[0,0,0],[1,0,0],[0,g,0]])
B = sy.Matrix([[1/J],[0],[0]])
C = sy.Matrix([[0,0,1]])
A, A*A
```

## Controllability


```python
Ctr = sy.Matrix([[B.T], [B.T*A.T], [B.T*A.T*A.T]]).T
Ctr
```


```python
l0, l1, l2, l3 = sy.symbols('l_0, l_1, l_2, l_3') 
L = sy.Matrix([[l1, l2, l3]])
L
```


```python
M = s*sy.eye(3) - (A-B*L)
M
```


```python
char_pol = sy.poly(sy.det(M), s)
```

## Desired closed-loop poles


```python
tauc = sy.symbols('tau_c')
wc = 1/tauc
p1 = -wc
p2 = wc/np.sqrt(2)*complex(-1,1)
p3 = wc/np.sqrt(2)*complex(-1, -1)
p3
```


```python
char_pol_des = sy.poly((s-p1)*(s-p2)*(s-p3), s)
```


```python
char_pol_des
```


```python
eqns = [c_ - cd_ for c_, cd_ in zip(char_pol.coeffs(), char_pol_des.coeffs())]
eqns
```


```python
sol = sy.solve(eqns, [l1, l2, l3])
```


```python
sol
```


```python
2*np.sqrt(2)
```

## The forward gain $l_0$

From transfer function
$$ G_c(s) = l_0 \frac{\frac{g}{J}}{s^3 + \frac{1+\sqrt{2}}{\tau_c}s^2 + \frac{1+\sqrt{2}}{\tau_c^2}s + \frac{1}{\tau_c^3}}$$
and 
$$ G_c(0) = 1 $$


```python
l0 = J/g/tauc**3
l0
```

From steady-state solution
$$ 0 = (A-BL)x + l_0Br $$
$$ x = -l_0(A-BL)^{-1}Br $$


```python
dcgainx = -(A-B*L).inv()*B
dcgainx = dcgainx.subs([(l3, sol[l3])])
dcgainx
```


```python
dcgainy = C*dcgainx
l0 = 1/dcgainy[0]
l0
```

## Observer design



```python
k1,k2,k3 = sy.symbols('k_1, k_2, k_3')
K = sy.Matrix([k1,k2,k3])
K
```


```python
o_char_pol = sy.poly(sy.det(s*sy.eye(3) - (A - K*C) ), s)
o_char_pol
```

### Desired observer poles
Separation of n, hence the poles are at n times the distance from the origin of the closed-loop poles


```python
sep = sy.symbols('n', real=True, positive=True)
wc_o = sep*wc
p1_o = -wc_o
p2_o = wc_o/np.sqrt(2)*complex(-1,1)
p3_o = wc_o/np.sqrt(2)*complex(-1, -1)
p3_o
```


```python
o_char_pol_des = sy.poly((s-p1_o)*(s-p2_o)*(s-p3_o), s)
o_char_pol_des
```


```python
eqns = [c_ - cd_ for c_, cd_ in zip(o_char_pol.coeffs(), o_char_pol_des.coeffs())]
eqns
```


```python
sol_o = sy.solve(eqns, [k1, k2, k3])
sol_o
```


```python
C
```


```python
A
```


```python
B
```


```python

```

b71ccc06997ad10900ef71931e3a5bfee18a57cd
ipynb
Jupyter Notebook
modern-control/notebooks/Apollo-lunar-module-feedback-design.ipynb
kjartan-at-tec/mr2025
88c28aa76e84890c25d252167e5bbcd25318463e
MIT
modern-control/notebooks/Apollo-lunar-module-feedback-design.ipynb
kjartan-at-tec/mr2025
88c28aa76e84890c25d252167e5bbcd25318463e
MIT
modern-control/notebooks/Apollo-lunar-module-feedback-design.ipynb
kjartan-at-tec/mr2025
88c28aa76e84890c25d252167e5bbcd25318463e
MIT
Qwen/Qwen-72B
1. YES
2. YES