Open Loop Frequency Response First, we use the design specifications to calculate the natural frequency and damping factor for the closed loop system... Fine-tuning the design to achiev
Trang 1E102 Using MATLAB in Feedback Systems
Part I Classical Design
Classical Control Design with MATLAB is illustrated by means of an example of the design of a dc servomotor control system
The transfer function of the dc motor is given by:
) s s(s
H(s)
48 24
80
2 + +
=
Our task is to design a PID controller
Ds s
I P s
C( ) = + +
or ( )( )
ω
ω + ω
+
= ω
j
T j T
j K j
to achieve the following specifications for the closed loop step response:
• Rise time < 0.5s
• Overshoot < 10%
We shall work through the following steps for the design:
A Calculating the required open loop frequency response
B Determining the PID parameters
C Plotting the step response of the closed loop
D Fine-tuning the design to achieve the specifications
A Open Loop Frequency Response
First, we use the design specifications to calculate the natural frequency and damping factor for the closed loop system For a rise time tr = 0.5 s, overshoot Mp = 0.1 :
=>ωn =3.6 rad/s
=>ζ=0.591
Now use the design relations from the lecture notes to specifiy the open loop crossover frequency and phase margin:
=>
ζ + − ζ
ω
=
ω2c 2n 4 4 1 2 2 => ωc =2.60 rad/s
=>
ω
ζω
=
c
n m
2 tan 1 => φm = 1.02 rad
Trang 2B Determining the PID parameters
We will use a Bode plot to help select the controller parameters for the system First we will look at the frequency response of the dc motor
You can write transfer functions in MATLAB by entering the numerator and
denominator polynomials of a rational transfer function as vectors of coefficients in descending powers of s
For example, to enter the dc motor transfer function given in the problem statement, you would enter the numerator and denominator polynomials as two row vectors and define the system as a transfer function model:
>>num=[80]; den=[1 24 48 0];
>>H=tf(num,den)
Transfer function:
80
-
s^3 + 24 s^2 + 48 s
The bode plot for the dc motor can now be plotted:
>>bode(H)
Trang 3
The bode plot shows a crossover frequency of 1.4 rad/s The crossover frequency must be raised to 2.60 rad/s to speed up the time response
First, find the magnitude and phase of the dc motor at the crossover frequency :
>>[magH,phaseH]=bode(H,2.60)
magH =
0.4117
phaseH =
-146.5225
At 2.60 rad/s, the combined phase of the controller and process must give a phase margin
of 1.02 rad (59o)
The phase lead added by the controller at 2.60 rad/s must be -180 + 59 +147 = 26o (∠C(jωc)=0.44 rad) and the gain added by the controller at 2.60 rad/s must equal the reciprocal of the dc motor gain 2.43
412
1 ) (jωc = =
We can now calculate the controller parameters, assuming that T I =10T D by solving
c
I c D
c c
I c D
c c
T T
K
j
C
T T
j
C
ω
ω + ω
+
=
ω
π
− ω +
ω
=
ω
2 2 2
2
1 1
1 1
)
(
2 ) ( tan ) ( tan
)
(
=> T D =0.256s;=>T I =2.56s
=>K =0.780
So the PID controller is given by
s
s s
s
s s
s
C( ) 0.780 (0.256 1)(2.56 1) 0.512 2.20 0.780
=
=
>>num=[0.512 2.40 0.780];den=[1 0];C=tf(num,den)
Transfer function:
0.512 s^2 + 2.4 s + 0.78
-
s
Now check the phase margin and crossover frequency of our design with the open loop bode plot
Trang 4>>margin(C*H)
The phase margin is 59o at 2.6 rad/s, just as required
C Plotting the step response of the closed loop
Now we check the closed loop behaviour of the system
First find the closed loop transfer function Q(s):
>> Q=feedback(C*H,1)
Transfer function:
40.99 s^2 + 175.9 s + 62.42
-
s^4 + 24 s^3 + 88.99 s^2 + 175.9 s + 62.42
The syntax of the feedback function is :
feedback(forward path transfer function, feedback path transfer function)
In our case we have unity feedback
Trang 5Plot the step response of the closed loop system for 0 < t < 4 s
>>step(Q,4)
The step response meets the rise time requirement (< 0.5 s) but not the overshoot
specification (<10%)
Trang 6D Fine-tuning the design to achieve the specifications
You have found that the controller design did not meet design specs We would like to be able to try different values for the controller parameters and examine the results
• Create the M file PID_tune.m
%PID_tune M file to tune a PID controller
%
%Enter H(s)
num=[80];den=[1 24 48 0];
H=tf(num,den);
%Enter C(s)
P=2.20;I=0.780;D=0.512;
num=[D P I];den=[1 0];
C=tf(num,den);
%Plot closed loop step response
Q=feedback(C*H,1);
step(Q,4)
Run the M- file
>> PID_tune
• Tune the controller parameters to achieve the desired specification
Trang 7E102 Using MATLAB in Feedback Systems
Part II State Space Design
We will carry out the same design as in Part I using State Space Methods
The state space equations describing the dc motor are:
v i
dt di
i dt d dt d
20 12 24
4
+ ω
−
−
=
= ω
ω
= θ
Our task is to design a state space control scheme to achieve the following specifications for the closed loop step response :
• Rise time < 0.5s
• Overshoot < 10%
We shall work through the following steps for the design:
A Entering the state space representation of the system
B Implementing full state feedback with pole placement
C Implementing full state feedback with optimal control
D Implementing feedback with a state observer
A State Space Representation of the System
Enter the state space matrices, with x
ω
θ
=
i
, u = v, y = θ
>>A=[0 1 0;0 0 4;0 –12 –24];B=[0 0 20]’;C=[1 0 0];D=0;
>>H=ss(A,B,C,D)
a =
x1 x2 x3
x1 0 1 0
x2 0 0 4
x3 0 -12 -24
b = u1 x1 0
x2 0
x3 20
Trang 8c =
x1 x2 x3
y1 1 0 0
d =
u1
y1 0
Continuous-time system
The command ss created a state space model of the system We can now look at the
frequency response bode(H), step response step(H ), and so forth, just as we did for the
transfer function models in Part I
With full state feedback, the feedback gain can be evaluated using pole placement or the LQR method
B Pole Placement
First determine the dominant closed loop pole positions
• What values of the dominant poles will give the appropriate time response ( <10% overshoot, <0.5 s settling time => ζ = 0.6, ω n = 3.6 rad/s)?
Choose the remaining pole to be ten times as fast:
>>p=[-2.2 + 2.8j, -2.2 – 2.8j, -22];
Find the full state feedback gain to place these poles
>>K=place(A,B,p)
place: ndigits= 15
K = 3.6437 0.7756 0.1200
The command place matches the eigenvalues of the closed loop system matrix A f = A-BK
with the chosen poles It also measures the number of digits accuracy in the position of the closed loop poles
Next, the reference gain Kr is determined
>>N=inv([A B;C D])*[zeros(length(B),1);1];
>>Nx=N(1:length(B));Nu=N(length(B)+1); Kr= Nu + K*Nx
Kr = 3.6437
The closed loop system can now be defined in state space form
>>Q=ss(A-B*K,B*Kr,C-D*K,D*Kr);
Trang 9and the closed loop step response plotted
>>step(Q)
Rise time = 0.53 s Overshoot 9% Close enough!!
C Optimal Control: LQR Method
First choose the weighting parameters of the performance index
>>Q=[10 0 0;0 0 0;0 0 0];R=.1;
This choice weights the motor angle with a factor of ten and the control input with a factor
of 0.1 Solve the linear quadratic regulator with Matlab function lqr
>>[K,S,e]=lqr(A,B,Q,R)
K =
10.0000 2.2273 0.3267
S =
2.8273 0.3817 0.0500
0.3817 0.0774 0.0111
0.0500 0.0111 0.0016
e =
-21.8628
-4.3360 + 4.2180i
-4.3360 - 4.2180i
Trang 10The values of the feedback gain vector K are the optimum values to minimize the
performance index The matrix S is the solution of the associated Riccati equation and the
e vector contains the closed loop eigenvalues (poles) The closed loop response follows as before
>>Kr= Nu + K*Nx
>>Q=ss(A-B*K,B*Kr,C-D*K,D*Kr); step(Q)
Rise time 0.38 s, Overshoot 4% This looks too easy!!
D Observer Design
Full state feedback of the servo motor requires simultaneous measurement of motor angular position, angular velocity and motor current Typically all of these are not
measured So we need to include an observer to estimate the state of the system We will choose the observer poles to be twice as fast as the system poles:
>>pe=2*e
pe =
-43.7256
-8.6720 + 8.4359i
-8.6720 - 8.4359i
Now match the eigenvalues of A o = A-LC with the chosen poles
>>L=place(A’,C’,pe)’
Trang 11L =
1.0e+003 *
0.0371
-0.0329
1.3527
Note that the place function solves A-BK, so we need to invert the A and C matrices to find the column vector L
The observer gain L is now incorporated into an augmented state space description of
both the system state and the observer state:
>>Ae=[A -B*K;L*C A-L*C-B*K];Be=[B*Kr;B*Kr];
>>Ce=[C -D*K; 0 0 0 C-D*K];De=[D*Kr;D*Kr];
The closed loop step response follows as before:
>>Q=ss(Ae,Be,Ce,De);
>>step(Q);title('LQR Design with observer')
The upper reponse curve corresponds to the measured output y = θ; the lower curve to the estimated output ˆy =θˆ Overshoot 4%, rise time 0.38s, the observer does an excellent
job!
Trang 12Before you come to the conclusion that the problem is solved and you can take the rest of the evening off, you should just check the closed loop response of the other two state variables, the motor speed ω and the motor current i For example to find the closed loop
step response of the motor current, we change the output matrix:
>>C=[0 0 1];Ce=[C -D*K2; 0 0 0 C-D*K2];
>>Qi=ss(Ae,Be,Ce,De);step(Qi)
The motor current exceeds 4 amps for a short duration This current level could burn out the motor windings We need to relax some of the design specifications and penalize
large values of current in our weighting matrix Q
• Fine tune the observer-based state space control scheme for rise time < 1.5 s, overshoot < 10%, motor speed < 1 rad/s and motor current < 2 amps The M-file
stspace_tune.m given on the next page may be helpful:
Trang 13%stspace_tune M file to tune a state space controller
%
%Enter state space matrices
A=[0 1 0;0 0 4;0 -12 -24];B=[0 0 20]';C=[1 0 0];D=0;
H=ss(A,B,C,D);
% LQR design
Q=[10 0 0;0 0 0;0 0 0];R=0.1;
[K,S,e]=lqr(A,B,Q,R);
% Reference Gain
N=inv([A B;C D])*[zeros(length(B),1);1];
Nx=N(1:length(B));Nu=N(length(B)+1); Kr= Nu + K*Nx;
%Observer Design
% place observer poles
p=2*e; L=place(A',C',p)';
% closed loop state space form
Ae=[A -B*K;L*C A-L*C-B*K];Be=[B*Kr;B*Kr];
Ce=[C -D*K; 0 0 0 C-D*K];De=[D*Kr;D*Kr];
% Step Response
Q=ss(Ae,Be,Ce,De);step(Q)
Trang 14E102 Using MATLAB in Feedback Systems
Part III Digital Control Design
We continue the servomotor design with digital control The transfer function of the dc motor is given by:
) 48 24 (
80 )
+ +
=
s s
s s H
We shall work through the following steps for the design:
A Emulating the continuous design with a discrete PID controller
) 1 ( 1
)
− +
T
D z
IT P z C
B Implementing discrete state space feedback
A Emulation of Continuous Control
Choose a sampling frequency ≅ 20 times the closed loop bandwidth (20Hz)
>>fs=20;T=1/fs;
Convert the analog PID settings to discrete form:
>>P=2.44;I=0.864;D=0.567;
>>Cz=tf([(P+I*T+D/T) –(P+2*D/T) D/T],[1 -1 0],T)
Transfer function:
13.82 z^2 - 25.12 z + 11.34
-
z^2 - z
Sampling time: 0.05
Notice that the addition of the sample time T to the transfer function command tf creates
a discrete time model of the PID controller
Trang 15Now we convert the continuous process transfer function to the equivalent discrete
transfer function using the c2d (continuous-to-discrete) command applying a zero order
hold to the input:
>>Hs=tf(80,[1 24 48 0]);Hz=c2d(Hs,T,'zoh')
Transfer function:
0.001259 z^2 + 0.003814 z + 0.0006928
-
z^3 - 2.232 z^2 + 1.533 z - 0.3012
Now we find the step response The output of the system is continuous, but we can find the sampled output from the discrete closed loop transfer function:
>>Qz=feedback(Cz*Hz,1);step(Qz);
If we compare this response to the results for the continuous control system (Part I), the rise time is reduced slightly but the overshoot is increased
Trang 16B Discrete State Space Design
The continuous state space equations for the system can be converted to discrete form and state feedback strategies applied to the discrete system
First find the equivalent discrete state model for the process:
>>A=[0 1 0;0 0 4;0 -12 -24];B=[0 0 20]';C=[1 0 0];D=0;
>>Hc=ss(A,B,C,D);
>>Hd=c2d(Hc,T,'zoh');
>>Ad=Hd.a
>>Bd=Hd.b
Ad =
1.0000 0.0492 0.0034
0 0.9586 0.1142
0 -0.3426 0.2734
Bd =
0.0013
0.0690
0.5710
To apply the optimal control LQR method for the state feedback gain, choose the
weighting parameters of the objective function
>>Q=[10 0 0;0 0 0;0 0 ];R=0.1;
Now solve the discrete linear quadratic regulator with Matlab function dlqr
>>[K,S,e]=dlqr(Ad,Bd,Q,R)
K =
8.4950 2.0222 0.3007
S =
61.7350 7.6247 1.0043
7.6247 1.5544 0.2236
1.0043 0.2236 0.0328
e =
0.7875 + 0.1689i
0.7875 - 0.1689i
0.3350
Trang 17Now the reference gain is found:
>> N=inv([Ad-eye(3) Bd;C D])*[zeros(length(Bd),1);1];
>>Nx=N(1:length(Bd));Nu=N(length(Bd)+1); Kr= Nu + K*Nx
Kr = 8.4950
The observer is designed by pole placement Choose estimator poles to be one half the value of the system poles (making them about twice as fast in the discrete domain), and solve for the estimator gain:
>>pe=e/2, L=place(Ad',C',pe)'
pe =
0.3938 + 0.0845i
0.3938 - 0.0845i
0.1675
place: ndigits= 15
L =
1.2769
7.0198
-3.3579
Write the augmented discrete state space equations for both the state variables and the estimates of the state variables and plot the step response:
>>Ae=[Ad -Bd*K;L*C Ad-L*C-Bd*K];Be=[Bd*Kr;Bd*Kr];Ce=[C -D*K];De=D*Kr
>>Q=ss(Ae,Be,Ce,De,T);step(Q)
Trang 18The response is practically identical to the results from the continuous state space system and leaves open the same questions about the behavior of the other state variables
• Fine tune the observer-based digital state space control scheme for rise time < 1.5 s, overshoot < 10%, motor speed < 1 rad/s and motor current < 2 amps The following M-file may be helpful:
%digi_tune M file to tune a digital state space controller
%
% Enter sample time
fs=20;T=1/fs;
% LQR design
A=[0 1 0;0 0 4;0 -12 -24];B=[0 0 20]';C=[1 0 0];D=0;
Hc=ss(A,B,C,D);Hd=c2d(Hc,T,'zoh');
Ad=Hd.a;Bd=Hd.b;
Q=[10 0 0;0 0 0;0 0 0];R=0.1;
[K,S,e]=dlqr(Ad,Bd,Q,R)
% Reference Gain
N=inv([Ad-eye(3) Bd;C D])*[zeros(length(Bd),1);1];
Nx=N(1:length(Bd));Nu=N(length(Bd)+1); Kr= Nu + K*Nx;
% place estimator poles
pe=e/2; L=place(Ad',C',pe)';
% closed loop state space form
Ae=[Ad -Bd*K;L*C Ad-L*C-Bd*K];Be=[Bd*Kr;Bd*Kr];Ce=[C -D*K];De=D*Kr
% Step Response
Q=ss(Ae,Be,Ce,De,T);step(Q)