Skip to content

Commit 479c1e7

Browse files
authored
Merge pull request #1010 from JuliaControl/pp_example
add pole placement example
2 parents c522a79 + ec028b6 commit 479c1e7

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

docs/src/examples/example.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ L = lqr(Discrete,A,B,Q,R) # lqr(sys,Q,R) can also be used
4242
u(x,t) = -L*x .+ 1.5(t>=2.5) # Form control law (u is a function of t and x), a constant input disturbance is affecting the system from t≧2.5
4343
t = 0:Ts:5 # Time vector
4444
x0 = [1,0] # Initial condition
45-
y, t, x, uout = lsim(sys,u,t,x0=x0)
46-
plot(t,x', lab=["Position" "Velocity"], xlabel="Time [s]")
45+
res = lsim(sys,u,t,x0=x0)
46+
plot(res, lab=["Position" "Velocity"], ploty=false, plotx=true, layout=1, sp=1)
4747
4848
save_docs_plot("lqrplot.svg"); # hide
4949
@@ -64,6 +64,56 @@ See also the following tutorial video on LQR and LQG design
6464
<iframe style="height: 315px; width: 560px" src="https://www.youtube.com/embed/NuAxN1mGCPs" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
6565
```
6666

67+
## Pole Placement Design
68+
69+
The example below demonstrates basic pole placement controller design using the same double integrator system from the LQR example. We design a state-feedback controller with desired closed-loop poles and an observer that is 5 times faster than the closed-loop response.
70+
71+
```@example POLEPLACEMENT
72+
using ControlSystemsBase
73+
using LinearAlgebra
74+
using Plots
75+
76+
# Create system - same as LQR example
77+
Ts = 0.1
78+
A = [1 Ts; 0 1]
79+
B = [0; 1]
80+
C = I(2)
81+
P = ss(A,B,C,0,Ts)
82+
83+
# Design controller using pole placement
84+
# Choose desired closed-loop poles (well-damped, faster than original system)
85+
desired_poles_cont = [-2+0.5im, -2-0.5im] # Continuous-time poles
86+
desired_poles = exp.(Ts .* desired_poles_cont) # Discrete-time poles inside unit circle
87+
88+
# Design state feedback gain using pole placement
89+
L = place(P, desired_poles) |> real
90+
91+
# Design observer with poles 5x faster (closer to origin for discrete time)
92+
observer_poles = exp.(Ts*5 .* desired_poles_cont)
93+
K = place(P, observer_poles, :o) |> real # Note the :o for observer design
94+
95+
# Create observer-controller using the observer_controller function
96+
controller = observer_controller(P, L, K)
97+
98+
# Form closed-loop system and analyze
99+
T_cl = feedback(P * controller)
100+
101+
r(x,t) = [1.5(t>=2.5); 0] # Form control law (r is a function of t and x), change reference to 1.5 at t≧2.5
102+
t = 0:Ts:5 # Time vector
103+
x0 = [1, 0, 0, 0] # Initial condition
104+
res = lsim(T_cl, r, t; x0)
105+
plot(res, lab=["Position" "Velocity"], layout=1, sp=1)
106+
```
107+
108+
Plot Gang of Four to analyze closed-loop properties
109+
```@example POLEPLACEMENT
110+
gangoffourplot(P, controller)
111+
```
112+
113+
114+
The pole placement design allows direct specification of closed-loop pole locations. The [`place`](@ref) function computes the required feedback gains, while [`observer_controller`](@ref) combines the state feedback and observer into a single controller.
115+
116+
67117
## PID design functions
68118
A basic PID controller can be constructed using the constructors [`pid`](@ref), [`pid_2dof`](@ref).
69119
In ControlSystems.jl, we often refer to three different formulations of the PID controller, which are defined as

lib/ControlSystemsBase/src/pid_design.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ end
132132
133133
Calculates and returns a PID controller on 2DOF form with inputs `[r; y]` and outputs `u` where `r` is the reference signal, `y` is the measured output and `u` is the control signal.
134134
135-
Belowm we show two different depections of the contorller, one as a 2-input system (left) and one where the tw internal SISO systems of the controller are shown (right).
135+
Below we show two different depections of the controller, one as a 2-input system (left) and one where the tw internal SISO systems of the controller are shown (right).
136136
```
137137
┌──────┐
138138
r │ │

0 commit comments

Comments
 (0)