# Example of pole placement with discrete PI controller
We have stable first-order plant model
$$ H(z) = \frac{b}{z-a} $$
and discrete-time PI controller
$$ F(z) = K_c \left( 1 + \frac{h/T_i}{z-1} \right) = K_c \frac{z-1+h/T_i}{z-1}. $$
We want to find controller parameters $K_c$ and $T_i$ such that the closed-loop system has two poles in $z = \alpha$.
### Characteristic equation
\begin{align}
  1 + H(z)F_{PI}(z) &= 0\\
  (z-1)(z-a) + K_c b (z - 1 + h/T_i) &= 0
\end{align}
### Characteristic polynomial
$$\underbrace{(z-1)(z-a) + K_c b (z - 1 + h/T_i)}_{\text{parameterized}} = \underbrace{(z-\alpha)^2}_{\text{desired}} $$
$$ z^2 - (1+a -K_cb)z + K_cb(h/T_i - 1)+a = z^2 -2\alpha z + \alpha^2 $$
\begin{align}
  1 + a - K_c b &= 2\alpha \quad \Rightarrow \quad K_c = \frac{1+a-2\alpha}{b}\\
  K_cb(h/T_i - 1) + a &= \alpha^2 \quad \Rightarrow \quad \frac{1}{T_i} = \frac{1}{h}\left(1 + \frac{\alpha^2-a}{K_c b}\right) = \frac{1}{h} \left( \frac{(\alpha-1)^2}{1 + a - 2\alpha}\right) 
\end{align}



```python
import numpy as np
import matplotlib.pyplot as plt
import sympy as sy
import control.matlab as cm
```

## Symbolic solution


```python
sy.init_printing()
aa, alphaa, hh, bb, KK, TT = sy.symbols('a, alpha, h, b, Kc, Ti', 
                                        real=True, positive=True)
zz = sy.symbols('z', real=False)
```


```python
A = zz-aa
B = bb
R = zz-1
S = KK*(zz-1+hh/TT)
LHS = sy.Poly(A*R + B*S, zz)
LHS
```


```python
RHS = sy.Poly((zz-alphaa)**2, zz)
Dioph = LHS-RHS
coeffs = Dioph.coeffs()
coeffs
```


```python
sol = sy.solve(coeffs, [KK, TT])
sol
```

## Numerical solution


```python
# Plant
a = 0.9
b = 1
h = 0.1
H = cm.tf([b], [1, -a], h)

# Desired closed-loop pole
alpha = 0.8

# Controller parameters
Kc = (1+a-2*alpha)/b
Ti = h*(1+a-2*alpha)/(alpha-1)**2
F = Kc*cm.tf([1, -1+h/Ti], [1, -1], h)
F
```




    
    0.3 z - 0.26
    ------------
        z - 1
    
    dt = 0.1




```python
# Check calculations
Hc = cm.feedback(F*H, 1)
cm.pole(Hc)
```




    array([0.8+1.65261872e-08j, 0.8-1.65261872e-08j])




```python
br, res = cm.rlocus(F*H)
plt.plot(np.real(br1), np.imag(br1))
plt.xlim((0,1.2))
plt.ylim((-1.2,1.2));
```


```python
y, t = cm.step(Hc)
tt = h*np.arange(len(y))
plt.stem(tt[:30], y[:30]);
```


```python

```

82876554a143607ef7a430944ff8505a933dd07f
ipynb
Jupyter Notebook
approximating-cont-controller/notebooks/Pole-placement-PI-controller-example.ipynb
kjartan-at-tec/mr2007-computerized-control
16e35f5007f53870eaf344eea1165507505ab4aa
MIT
2020-11-07T05:20:37.000Z
2020-12-22T09:46:13.000Z
approximating-cont-controller/notebooks/Pole-placement-PI-controller-example.ipynb
kjartan-at-tec/mr2007-computerized-control
16e35f5007f53870eaf344eea1165507505ab4aa
MIT
2020-06-12T20:44:41.000Z
2020-06-12T20:49:00.000Z
approximating-cont-controller/notebooks/Pole-placement-PI-controller-example.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