Professional Documents
Culture Documents
ω( s) K
Gm( s) = = Transfer function for a DC Motor
V( s) 2
( J⋅ s + b ) ⋅ ( L⋅ s + R) + K
Ki + Kp + Kd⋅ s ⋅ K
s Closed loop transfer function
( J⋅ s + b ) ⋅ ( L⋅ s + R) + K2 Gc( s) ⋅ Gm( s)
T( s) = T( s) =
1 + + Kp + Kd⋅ s ⋅
Ki K 1 + Gc( s) ⋅ Gm( s)
s ( J⋅ s + b ) ⋅ ( L⋅ s + R) + K2
T( s) =
(Ki + Kp⋅s + Kd⋅s2)⋅K
J⋅ s ⋅ L + ( J⋅ R + b ⋅ L + K⋅ Kd) ⋅ s + ( K + K⋅ Kp + b ⋅ R) ⋅ s + K⋅ Ki
3 2 2
Desired characteristic
( s + λ )3 equation. In this case a
critically damped response is
desired with 3 poles at -λ.
Find the difference between the system characteristic equation and the desired
characteristic equation and the solve for the gains.
2
J⋅ R + b ⋅ L + K⋅ Kd 2 K + K⋅ Kp + b ⋅ R K⋅ Ki
− (s + λ )
3 3
DiffCE := s + ⋅s + ⋅s +
J⋅ L J⋅ L J⋅ L
coeffs , s
DiffCE
Ki → λ 3⋅ J⋅ L
(−K2) − b⋅R + 3⋅λ 2⋅J⋅L ( −J) ⋅ R − b ⋅ L + 3 ⋅ λ ⋅ J⋅ L
solve , Kp K K K
Kd
DC Motor Parameters
See http://www.engin.umich.edu/group/ctm/examples/motor/motor.html
R := 1 R=1 Ohm
Find the DC gain. It is about 0.1 radians per second per volt. Therefore the
motor has a maximum speed of 1 radian per second which is very slow.
Obviously this is not a realistic example.
K
lim float , 2 → .10
s → 0 ( J⋅ s + b ) ⋅ ( L⋅ s + R) + K2
Calculate the PID gains. Place the three closed loop poles at -λ radians to get a critically
damped response. Making λ bigger moves the closed loop poles farther to the left and
makes the response faster.
λ := 2 ⋅ π ⋅ 3 λ = 18.849556
3 L
Ki := λ ⋅ J⋅ Ki = 3348.677881
K
Kp :=
(−K2) − b⋅R + 3⋅λ 2⋅J⋅L Kp = 522.948638
K
( −J) ⋅ R − b ⋅ L + 3 ⋅ λ ⋅ J⋅ L
Kd := Kd = 22.274334
K
σ := 0.1
K := K⋅ rnorm( 1 , 1 , σ ) 0 K = 0.01
J := J⋅ rnorm( 1 , 1 , σ ) 0 J = 0.01
b := b ⋅ rnorm( 1 , 1 , σ ) 0 b = 0.1
R := R ⋅ rnorm( 1 , 1 , σ ) 0 R=1
L := L⋅ rnorm( 1 , 1 , σ ) 0 L = 0.5
Τ := .001
Τ 0
0
1 −1
Kzi := ( Ki Kp Kd ) ⋅
0
Convert the PID gains to
1 2 1 coefficients for the PID
Τ −Τ
Τ difference equation.
r := 0 if n < 10
n
0.5 + 0.0 − 0.5 − 0.0 ⋅ cosπ ⋅ n − 10 if 10 ≤ n < 1010 r(n) is the target or
2 2 0.1⋅ N
reference velocity.
0.5 if n ≥ 1010 ∧ n < 0.3⋅ N
0.5 − 0.8 − −0.8 − 0.5 ⋅ cosπ ⋅ n − 0.3⋅ N if 0.3⋅ N ≤ n < 0.4⋅ N
2 0.1⋅ N
2
−0.8 if n ≥ 0.4⋅ N ∧ n < 0.7⋅ N
−0.8 − 0.25 − −0.25 − −0.8 ⋅ cosπ ⋅ n − 0.7⋅ N if 0.7⋅ N ≤ n < 0.8⋅ N
0.1⋅ N
2 2
−0.25 otherwise
xn+1
u := PID r , x , u , err Call the PID routine
n+1 ( n n n n) for each time period.
errn+1
0.4
0.2 5
0.2 0
0.4
0.6 5
0.8
1 10
0 2 4 6 8 10
Time
Target Velocity
Actual Velocity
Motor Current
Control Output
The actual velocity tracks the target velocity almost perfectly execet where the control output
saturates at about 3.3 seconds. A less radical velocity change or reducing the bandwidth by
reducing λ wouls avoid the output saturation.
T( s) := Ki + Kp + Kd⋅ s ⋅ K
s ( J⋅ s + b ) ⋅ ( L⋅ s + R) + K2
Mn
:= r ← Tj ⋅ ( 2 ⋅ π ) ⋅ Hz
φn n
arg( r)
a←
deg
a ← a − 360 if n > 0 ∧ a − φ n− 1 > 100
20⋅ log( r )
a
100
50
Magnitude db
Phase deg
120
0
140
50 160
1 .10
3
0.01 0.1 1 10 100
Frequency Hz
Magnitude
Phase
T( s) :=
(Ki + Kp⋅s + Kd⋅s2)⋅K
3 2 2 2 2
J⋅ s ⋅ L + J⋅ s ⋅ R + b ⋅ L⋅ s + s⋅ b ⋅ R + s⋅ K + K⋅ Ki + K⋅ Kp⋅ s + K⋅ Kd⋅ s
Mn
:= r ← Tj ⋅ ( 2 ⋅ π ) ⋅ Hz
φn n
arg( r)
a←
deg
a ← a − 360 if n > 0 ∧ a − φ n− 1 > 100
20⋅ log( r )
a
0
20
10
Magnitude db
40
Phase deg
20
60
30
80
40
50 100
1 .10
3
0.01 0.1 1 10 100
Frequency Hz
Magnitude
Phase
T( s) :=
(Ki + Kp⋅s + Kd⋅s2)⋅K
J⋅ s ⋅ L + ( J⋅ R + b ⋅ L + K⋅ Kd) ⋅ s + ( K + K⋅ Kp + b ⋅ R) ⋅ s + K⋅ Ki
3 2 2
K⋅ Ki
2
3 2 2
( )
J⋅ s ⋅ L + ( J⋅ R + b ⋅ L + K⋅ Kd) ⋅ s + K + K⋅ Kp + b ⋅ R ⋅ s + K⋅ Ki
coeffs , s
explicit
→
K + K⋅ Kp + b ⋅ R
J⋅ R + b ⋅ L + K⋅ Kd
J⋅ L
K⋅ Ki
2 −18.849556 Right where we
poles := polyroots K + K⋅ Kp + b ⋅ R
poles = −18.849556 wanted them to be!
J⋅ R + b⋅ L + K⋅ Kd
−18.849555
J⋅ L
K⋅ Ki
coeffs , s
(Ki + Kp⋅s + Kd⋅s )⋅K 2
explicit
→ K⋅ Kp
K⋅ Kd
K⋅ Ki
zeros := polyroots K⋅ Kp
−11.738817 − 3.540924i
zeros =
−11.738817 + 3.540924i
K⋅ Kd
Poles and Zeros
20
Imaginary Axis
20 0 20
20
Real Axis
Poles
Zeros
Ki + Kp ⋅ s + Kd ⋅ s2 ⋅ λ 3
To =
o o o
DiffCE := s + 3 ⋅ s ⋅ λ + 3 ⋅ s ⋅ λ + λ ⋅ Kdo + λ
3 2
5 4 3 2
3 3 3
( )3 ( )(
⋅ s + λ ⋅ Kpo ⋅ s + λ ⋅ Kio − s + µ ⋅ s + α ⋅ s + β
)
coeffs , s 2 2
3 ⋅ µ 3⋅ λ − 3 ⋅ µ ⋅ λ + 2 ⋅ µ 3 ⋅ µ 2⋅ ( −8 ) ⋅ µ ⋅ λ
2
+ 5⋅ µ + 3⋅ λ
2 ( 3 2
− λ + 18⋅ µ ⋅ λ − 10
Kio 3 3 3
λ λ λ
DiffCE Kpo →
solve , Kd
o 3 λ 2 − 3⋅ µ⋅ λ + 2⋅ µ2 2 ( −8 ) ⋅ µ ⋅ λ
2
+ 5⋅ µ + 3⋅ λ
2 ( 3 2
− λ + 18⋅ µ ⋅ λ − 10
α 3 ⋅ µ ⋅ 3
3⋅ µ ⋅
3 3
λ λ λ
β
2
3 λ − 3⋅ µ⋅ λ + 2⋅ µ
2 The symbolic equations for the
3⋅ µ ⋅ outer loop gains as a function of
λ
3 the inner loop poles and the outer
loop poles. If the relationship
2
2 5 ⋅ µ − 8 ⋅ µ ⋅ λ + 3⋅ λ
2 between the outer loop poles, µ,
3⋅ µ ⋅ and the inner loop poles, λ, is not
Kio λ
3
right the outer loop gains will be
negative or the unplaced poles, α
3 2 3 2
Kpo 10⋅ µ − 18⋅ µ ⋅ λ − λ + 9 ⋅ µ ⋅ λ and β, will be in the right hand
Kd = 3 plane.
o λ
α 1
β 3 3 1 2
2
2
2 ⋅ λ − 2 ⋅ µ − 2 ⋅ ( −3) ⋅ λ + 18⋅ µ ⋅ λ − 15⋅ µ
1
3 2
⋅ λ − ⋅ µ + ⋅ ( −3 ) ⋅ λ + 18⋅ µ ⋅ λ − 15⋅ µ
3 1 2 2
2 2 2
Graphs the outer loop gains and α and β as a function of the ratio of the
outer loop pole location to the inner loop pole locations. This is
backwards from a root locus plot.
µ := 0 , 0.01λ .. 1λ
20
Ki,Kp,Kd,alpha & beta as a function of mu
20
40
60
80
0 0.2 0.4 0.6 0.8
mu / lambda
Ki
Kp
Kd
alpha
beta
µ is only valid where Ki, Kp, Kd, α and β are positive and this is only a small fractional range of λ.
Kd is negative if µ/λ is too low and α and β are negative if µ/λ is greater than 1.
Ki, Kp and Kd are maximum at 0.355λ:
µ := µ
0 0
0 0
1 1 0
3 λ 2 − 3⋅ µ⋅ λ + 2⋅ µ2
3 1 2 3 1 2
d
3⋅ µ ⋅ solve , µ → + ⋅6 ⋅λ + ⋅ 6 = 0
dµ 0.844949
λ
3
5 10 5 10
1 1
0.355051
3 1 2 3 1 2
5 − 10 ⋅ 6 ⋅ λ 5 − 10 ⋅ 6
1
3 1 2
10⋅ µ 3 − 18⋅ µ 2⋅ λ − λ 3 + 9 ⋅ µ ⋅ λ 2 + ⋅ 6 ⋅ λ
5 10
3⋅ solve , µ →
d
dµ 3 1
λ 3 1 2
− ⋅ 6 ⋅ λ
5 10
The maximum outer loop gains will all happen at the same ratio of µ to λ.
1
3 1 2
µ := − ⋅ 6 ⋅ λ or about 0.355*λ
5 10
1
3 1 2
µ := − ⋅6 ⋅λ µ = 6.692554
5 10
2
3 λ − 3⋅ µ⋅ λ + 2⋅ µ
2
3⋅ µ ⋅
3
λ
2 2
2 5 ⋅ µ − 8 ⋅ µ ⋅ λ + 3⋅ λ
3⋅ µ ⋅
1
Kio λ
3
3 1 2 Kio
substitute , µ = − ⋅6 ⋅λ
3 2 3 2 5 10
Kpo 10⋅ µ − 18⋅ µ ⋅ λ − λ + 9 ⋅ µ ⋅ λ Kpo
Kd = 3 expand
→ Kd =
o λ simplfy o
α 1 α
collect , λ
β 2 β
3 3 1 2 2
2 ⋅ λ − 2 ⋅ µ − 2 ⋅ ( −3) ⋅ λ + 18⋅ µ ⋅ λ − 15⋅ µ
1
3 2
⋅ λ − ⋅ µ + ⋅ ( −3 ) ⋅ λ + 18⋅ µ ⋅ λ − 15⋅ µ
3 1 2 2
2 2 2
The formulas for outer loop gains and unplaced poles in terms of λ alone
1
3
1
2
1
3 1 2 −4 3 2 3 1 2 2
3⋅ − ⋅6 ⋅ + ⋅ 6 + 2⋅ − ⋅6 ⋅λ
5 10 5 10 5 10
1 1
2 2
1
3 1 2 3 1 2 9 4 2
3⋅ − ⋅ 6 ⋅ 5 ⋅ − ⋅6 − + ⋅6 ⋅λ
5 10 5 10 5 5
Kio 3 2
1 1 1
3 1 2 3 1 2
Kpo 10⋅ − ⋅ 6 − 18⋅ − ⋅6 +
22
−
9 2
⋅6
Kd = 5 10 5 10 5 10
o
α 1
2
β 1 2
1 1
3 3 2 1 3 1 2 2 3 1 2 2
+ ⋅ 6 ⋅ λ − ⋅ ( −3 ) ⋅ λ + 18⋅ − ⋅ 6 ⋅ λ − 15⋅ − ⋅ 6 ⋅ λ
2
5 20 2 5 10 5 10
1
2
1 1 1
2
3 3
+ ⋅ 6 2 ⋅ λ + 1 ⋅ ( −3 ) ⋅ λ 2 + 18⋅ 3 − 1 ⋅ 6 2 ⋅ λ 2 − 15⋅ 3 − 1 ⋅ 6 2 ⋅ λ 2
5 20 2 5 10 5 10
2
3 λ − 3⋅ µ⋅ λ + 2⋅ µ
2
3⋅ µ ⋅
λ
3
2
2 5 ⋅ µ − 8 ⋅ µ ⋅ λ + 3⋅ λ
2
3⋅ µ ⋅
o
Ki λ
3
3 2 3 2
Kpo 10⋅ µ − 18⋅ µ ⋅ λ − λ + 9 ⋅ µ ⋅ λ
:= 3
Kdo λ
α 1
β 3 3 1 2
2
2
2 ⋅ λ − 2 ⋅ µ − 2 ⋅ ( −3) ⋅ λ + 18⋅ µ ⋅ λ − 15⋅ µ
1
3 3 1 2 2
2
⋅ λ − ⋅ µ + ⋅ ( −3 ) ⋅ λ + 18⋅ µ ⋅ λ − 15⋅ µ
2 2 2
Kio 8.92003
Kpo 5.630862
= 0.373939
Kdo
α 6.692554
29.778451
β
α is the same as µ so there are four outer loop poles at µ and one at β. The pole at β is always
farther to the left so it doesn't affect the response much.
0 1 0
0
0 −b K 0 1 0 0
Ac = 0 −10 1
B c := Bc = 0
0
Ac := J J
1
R 0 −0.02 −2 2
K
0 −L − L
L
I := identity( 3 )
Cascade Control
The Cascaded loop controller and system simulator.
An outer loop closed loop generates a reference velocity. The inner loop tries to
follow the velocity generated by the outer loop.
Note the outer and inner loop is really using I-PD control where only the integrator
term is in the forward path. This makes the inner loop less susceptible to the
noise in the set point from the outer loop.
The second line computes the control output using the error between velocity
generated from the outer loop and the feed back or estimated velocity. The control
output is limited to -10 to +10 volts
10
N := n := 0 .. N Simulate 10
Τ seconds
r := x if n < 0.01⋅ N Calculate the target positions
n 0
and velocities. In this case
0.2 the target velocities are 0
if 0.01⋅ N ≤ n ∧ n < 0.2⋅ N since that target positions are
0
changing only in step jumps.
0.1 if 0.2⋅ N ≤ n ∧ n < 0.4⋅ N
0
0.05 if 0.4⋅ N ≤ n ∧ n < 0.65⋅ N
0
0.35 otherwise
0
0
Cascade( r) := x ← 0
0
0
v ←0
0
vi ← 0
u ←0
0
ui ← 0
for n ∈ 0 .. N − 1
x ← A⋅ x + B⋅ u
n+ 1 n n
Kdo
vpd ← −Kpo ⋅ x
n+ 1
0
(
+ ) ( ) − (xn)0
Τ n+ 1 0
⋅ x
Kdi
u pd ← −Kpi ⋅ x
( n+1)1 + ( ) − (xn)1
Τ n+ 1 1
⋅ x
x
u
v
x
u := Cascade( r) Compute the system response
and control output
v
0.35 0.5
0.3 0.4
Target and Actual Position
0.25 0.3
0.15 0.1
0.1 0
0.05 0.1
0 0.2
0 2 4 6 8 10
Time
Target Position
Actual Position
Inner Target Velocity
0.5
0.4 5
Innter Target and Actual Velocity
0.3
0.1
0 5
0.1
0.2 10
0 2 4 6 8 10
Time
Inner Target Velocity
Actual Velocity
Control Output
Motor Current
0.6
0.4
0.4
0.2
Target and Actual Position
0.2
0.2
0.2
0.4
0.4
0.6
0.6 0.8
0 2 4 6 8 10
Time
Target Position
Actual Position
Output Velocity
0.6
0.4 5
Inner Target and Actual Velocity
0.2
0.2
0.4 5
0.6
0.8 10
0 2 4 6 8 10
Time
Inner Target Velocity
Actual Velocity
Control Output
Motor Current
Calculate Bandwidths
ωi
= 1.529474 Inner loop bandwidth in Hz
2⋅ π
Mn
:= r ← Tj ⋅ ( 2 ⋅ π ) ⋅ hz
φn n
arg( r)
a← Closed loop magnitude and phase
deg as a function of frequency
a ← a − 360 if n > 0 ∧ a − φ n− 1 > 100
20⋅ log( r )
a
50
100
Phase deg
Gain db
100
200
150
200 300
1 .10
3
0.01 0.1 1 10 100
Frequency Hz
Gain
Phase
Mn
:= r ← Tj ⋅ ( 2 ⋅ π ) ⋅ hz
φn n
arg( r)
a← Closed loop magnitude and phase
deg as a function of frequency
a ← a − 360 if n > 0 ∧ a − φ n− 1 > 100
20⋅ log( r )
a
100
100
200
Phase deg
Gain db
300
200
400
300 500
1 .10
3
0.01 0.1 1 10 100
Frequency Hz
Gain
Phase
Ti ( s) :=
(Ki + Kp⋅s + Kd⋅s2)⋅K simplify
(
→ Ki + Kp⋅ s + Kd
3 2 2 2 2 explicit
J⋅ s ⋅ L + J⋅ s ⋅ R + b ⋅ L⋅ s + s⋅ b ⋅ R + s⋅ K + K⋅ Ki + K⋅ Kp⋅ s + K⋅ Kd⋅ s
Ki + Kp ⋅ s + Kd ⋅ s2 ⋅ K
Kio 1 i i i
⋅ ⋅
s s J⋅ s3⋅ L + J⋅ R + b ⋅ L + K⋅ Kd ⋅ s2 + K2 + K⋅ Kp + b ⋅ R ⋅ s + K⋅ Ki
( i) i i
To ( s) :=
Ki + Kp ⋅ s + Kd ⋅ s ⋅ K
2
Kio 1 i i i
1+ + Kpo + Kdo ⋅ s ⋅ ⋅
s s J⋅ s3⋅ L + J⋅ R + b ⋅ L + K⋅ Kd ⋅ s2 + K2 + K⋅ Kp + b ⋅ R ⋅ s + K⋅ Ki
( i) i
33.48679
coeffs , s
Ai := denom ( Ti ( s) ) → 5.329588
float , 7 .2827434
.5e-2
( −.840693 ) ⋅ λ
5
5 4
( −.1312876 ) ⋅ λ − 10.00339⋅ λ
4 5 3
coeffs , s ( −1.562186) ⋅ λ − .559203e-2⋅ λ − 46.00881⋅ λ
Ao := denom ( To ( s) ) →
float , 7 3 4
( −7.285097) ⋅ λ − .6653937e-1 ⋅ λ
3
( −.3660357) ⋅ λ
3
( −.5e-2) ⋅ λ
( −.84070) ⋅ λ 5
coeffs , s
B o := numer( To ( s) ) → ( −.131287 ) ⋅ λ 5
float , 6
5
( −.559199e-2) ⋅ λ
poles i := polyroots Ai ( ) ( )
poles o := polyroots Ao
−38.497281
−15.302026 − 2.312133i
−18.862727
poles i = −18.845535 poles o = −15.302026 + 2.312133i
−18.840418 −2.052903 + 1.505003i
−2.052903 − 1.505003i
S Plane
20
Imaginary Axis
20 0 20
20
Real Axis
Inner Loop Poles
Outer Loop Poles
1
3
10⋅ µ − 9 ⋅ µ ⋅ λ
2 ) −3 3 1
⋅ ( −15) ⋅ µ + 18⋅ µ ⋅ λ − 3 ⋅ λ
2 2
2
−3 3 1
⋅ ( −15) ⋅ µ + 18⋅ µ ⋅ λ − 3
2
⋅µ + ⋅λ − ⋅µ + ⋅λ +
2 2 2 2 2 2
1
3
10⋅ µ − 9 ⋅ µ ⋅ λ
2 ) −3 3 1
⋅ ( −15) ⋅ µ + 18⋅ µ ⋅ λ − 3 ⋅ λ
2 2
2
−3 3 1
⋅ ( −15) ⋅ µ + 18⋅ µ ⋅ λ − 3⋅
2
⋅µ + ⋅λ + ⋅µ + ⋅λ −
2 2 2 2 2 2
1
3
1
2
1
3 1 2 −4 3 2 3 1 2 2
3⋅ − ⋅6 ⋅ + ⋅ 6 + 2⋅ − ⋅6 ⋅λ
5 10 5 10 5 10
1 1
2 2
1
3 1 2 3 1 2 9 4 2
3⋅ − ⋅ 6 ⋅ 5 ⋅ − ⋅6 − + ⋅6 ⋅λ
5 10 5 10 5 5
1
3
1
2
1
3 1 2 3 1 2 22 9 2
10⋅ − ⋅ 6 − 18⋅ − ⋅6 + − ⋅6
5 10 5 10 5 10
1
2
1 1 1
2
3 3 3 1 2 2 3 1 2 2
1
+ ⋅ 6 ⋅ λ − ⋅ ( −3) ⋅ λ + 18⋅ − ⋅ 6 ⋅ λ − 15⋅ − ⋅ 6 ⋅ λ
2 2
5 20 2 5 10 5 10
1
2
1 2
1 1
3 3 2 1 3 1 2 2 3 1 2 2
+ ⋅ 6 ⋅ λ + ⋅ ( −3 ) ⋅ λ + 18⋅ − ⋅ 6 ⋅ λ − 15⋅ − ⋅ 6 ⋅ λ
2
5 20 2 5 10 5 10
2
K
)
2
Kd⋅ s ⋅
3 2 2
K
2 2
J⋅ s ⋅ L + J⋅ s ⋅ R + b ⋅ L⋅ s + s⋅ b ⋅ R + s⋅ K + K⋅ Ki + K⋅ Kp⋅ s + K⋅ Kd⋅ s
simplify
collect , s → K⋅ Kii + Kpi ⋅ s + Kdi ⋅ s
2
⋅
s ⋅ J⋅ L + K⋅ Kdi + J⋅ R + b ⋅ L + K⋅ Kdo ⋅ Kdi ⋅ s + K⋅ Kdo ⋅ Kpi + K
( )
5 4
explicit
Kii
1
2
2
⋅λ
1
2
2
⋅λ
Kio
K⋅ Kpo ⋅ Kdi + K⋅ Kpi + b ⋅ R + K ⋅ s + K⋅ Kio ⋅ Kdi + K⋅ Kpo ⋅ Kpi + K⋅ Kdo ⋅ Kii + K⋅ Kii ⋅ s + K⋅ Kio ⋅ Kpi + K
( ) (
2 3 2
)
K⋅ Kpo ⋅ Kii ⋅ s + K⋅ Kio ⋅ Kii