Root Locus Design Example #2

MATLAB Code



%      ***** MATLAB Code Starts Here *****
%

%DSGN_421_ROOT_02_MAT
%
fig_size = [232 84 774 624];
%
numpi = 1.7; % open-loop plant transfer function
denpi = conv([.25 1],[1 1]);
%
PO_spec_il = 3; % specifications
Ts_spec = 1;
PO_spec_ol = 30;
%
[nclpi,dclpi] = feedback(numpi,denpi,1,1,-1);
%
t = linspace(0,2,1001);
yspi = step(nclpi,dclpi,2*t);
y_ss_pi = yspi(1001);
POpi = 100*((max(yspi)-y_ss_pi)/y_ss_pi); POpi = round(100*POpi)/100;
Tspi = timesetl(2*t,yspi); Tspi = round(100*Tspi)/100;
msg = ['PO = ' num2str(POpi) ', T_s = ' num2str(Tspi) ' s'];
%
zeta1 = 0.75; % desired inner loop closed-loop pole s1
slope1 = tan(acos(zeta1));
s1 = 4 * (-1 + j*slope1);
%
figure(1),clf,subplot(211),root_locus(numpi,denpi),...
title('Inner Loop Uncompensated'),...
hold on,plot(s1,'r*'),hold off,text(-4.1,4.2,'s_1')
subplot(212),plot(2*t,yspi,[0 4],y_ss_pi*[1 1],'r--'),grid,xlabel('Time (s)'),...
ylabel('Step Response'),title('Inner Loop Uncompensated'),set(1,'Position',fig_size),...
text(1.6,0.35,msg)
%
phps1 = -unwrap(angle(polyval(denpi,s1)))*180/pi; % plant phase at s = s1
phc1s1 = 180 - phps1;
%
zc1 = 7; % compensator zero
nc1 = [1 zc1];
phzc1s1 = unwrap(angle(polyval(nc1,s1)))*180/pi;
%
phpc1s1 = phzc1s1 - phc1s1; % phase for compensator pole
%
pc1 = abs(real(s1)) + imag(s1) / tan(phpc1s1*pi/180); % compensator pole
dc1 = [1 pc1];
%
nf1 = conv(numpi,nc1);
df1 = conv(denpi,dc1);
Kc1 = abs(polyval(df1,s1)) / abs(polyval(nf1,s1)); % gain for inner loop compensator
%
nf1 = Kc1*nf1; nc1 = Kc1*nc1;
[ncl1,dcl1] = feedback(numpi,denpi,nc1,dc1,-1); % inner loop closed-loop system
clp1 = roots(dcl1);
ys1 = step(ncl1,dcl1,2*t);
y_ss_1 = ys1(1001);
PO1 = 100*((max(ys1)-y_ss_1)/y_ss_1);PO1 = round(100*PO1)/100;
Ts1 = timesetl(2*t,ys1);Ts1 = round(100*Ts1)/100;
msg = ['PO = ' num2str(PO1) ', T_s = ' num2str(Ts1) ' s'];
%
figure(2),clf,subplot(211),root_locus(nf1,df1),title('Inner Loop Compensated'),...
axis([-30 10 -20 20]),hold on,plot(s1,'r*'),hold off,text(-4.1,5,'s_1')
subplot(212),plot(2*t,ys1,[0 4],y_ss_1*[1 1],'r--'),grid,xlabel('Time (s)'),...
ylabel('Step Response'),title('Inner Loop Compensated'),set(2,'Position',fig_size),...
text(1.6,0.125,msg)
%
nf2 = ncl1; % outer loop open-loop system
df2 = [dcl1 0];
%
[ncl2,dcl2] = feedback(nf2,df2,1,1,-1); % outer loop uncompensated closed-loop
clp2 = roots(dcl2);
%
ys2 = step(ncl2,dcl2,10*t); % outer loop uncompensated step response
%
Ts2 = timesetl(10*t,ys2); Ts2 = round(10*Ts2)/10;
msg = ['PO = 0%, T_s = ' num2str(Ts2) ' s'];
%
Kv2 = nf2(length(nf2)) / df2(length(df2)-1);
ess2 = 1 / Kv2;
%
zeta2 = 0.4; % desired inner loop closed-loop pole s2
slope2 = tan(acos(zeta2));
s2 = 4*(-1 + j*slope2);
%
figure(3),clf,subplot(211),root_locus(nf2,df2),title('Outer Loop Uncompensated'),...
set(3,'Position',fig_size),hold on,plot(s2,'r*'),hold off,...
text(-5,14,'s_2')
subplot(212),plot(10*t,ys2),grid,...
xlabel('Time (s)'),ylabel('Step Response'),title('Outer Loop Uncompensated'),...
text(8.5,0.5,msg)
%
% Outer loop phase shift at s = s2
%
phps2 = (unwrap(angle(polyval(nf2,s2))) - unwrap(angle(polyval(df2,s2))))*180/pi;
phc2s2 = 180 - phps2;
%
phzc2s2 = 60;
dist_zc2 = imag(s2)/tan(phzc2s2*pi/180);
zc2 = abs(real(s2))+dist_zc2;
nc2 = conv([1 zc2],[1 zc2]);
%
phpc2s2 = phzc2s2 - phc2s2/2; % outer loop compensator poles
pc2 = abs(real(s2)) + imag(s2)/tan(phpc2s2*pi/180);
dc2 = [1 2*pc2 pc2^2];
%
nf3 = conv(nf2,nc2);
df3 = conv(df2,dc2);
Kc2 = abs(polyval(df3,s2)) / abs(polyval(nf3,s2)); % gain for outer loop compensator
%
nf3 = Kc2*nf3; nc2=Kc2*nc2;
%
[ncl3,dcl3] = feedback(nf3,df3,1,1,-1); % outer loop closed-loop system
clp3 = roots(dcl3);
%
ys3 = step(ncl3,dcl3,t); % outer loop step response
PO3 = 100 * (max(ys3)-1); PO3 = round(10*PO3)/10;
Ts3 = timesetl(t,ys3); Ts3 = round(1000*Ts3)/1000; % outer loop performance
msg = ['PO = ' num2str(PO3) '%, T_s = ' num2str(Ts3) ' s'];
%
figure(4),clf,subplot(2,2,1),root_locus(nf3,df3),title('Outer Loop Compensated'),...
subplot(2,2,2),root_locus(nf3,df3),title('Outer Loop Compensated'),...
axis([-60 20 -40 40]),hold on,plot(s2,'r*'),hold off,text(-5,14,'s_2'),set(4,'Position',fig_size)
subplot(2,2,3:4),plot(t,ys3),grid,xlabel('Time (s)'),ylabel('Step Response'),...
title('Outer Loop Compensated'),text(0.85,0.5,msg)
%
Kp = sqrt(Kc2)*zc2/pc2;
tau = 1/pc2;
Kd = (sqrt(Kc2)-Kp)*tau;
%
[nfpd,dfpd] = series(sqrt(Kc2)*[1 zc2],[1 pc2],nf2,df2);
[nfpd1,dfpd1] = feedback(nfpd,dfpd,Kd*[1 0],[tau 1],-1);
[nfpd2,dfpd2] = series(Kp,1,nfpd1,dfpd1);
[nclpd,dclpd] = feedback(nfpd2,dfpd2,1,1,-1);
yspd = step(nclpd,dclpd,t);
POpd = 100*(max(yspd)-1); POpd = round(100*POpd)/100;
Tspd = timesetl(t,yspd); Tspd = round(1000*Tspd)/1000;
%
figure(5),clf,subplot(2,2,1),root_locus(nf3,df3),title('Outer Loop, Normal Configuration'),...
subplot(2,2,2),root_locus(nf3,df3),title('Outer Loop, Normal Configuration'),...
axis([-60 20 -40 40]),hold on,plot(s2,'r*'),hold off,text(-5,14,'s_2'),set(5,'Position',fig_size),...
subplot(2,2,3),root_locus(nfpd2,dfpd2),title('Outer Loop, PD-DOO Configuration'),...
subplot(2,2,4),root_locus(nfpd2,dfpd2),title('Outer Loop, PD-DOO Configuration'),...
axis([-60 20 -40 40]),hold on,plot(s2,'r*'),hold off,text(-8,15,'s_2')
%
alfag = 3;
zcg = abs(real(s2))/100;
pcg = zcg/alfag;
ncg = [1 zcg];
dcg = [1 pcg];
[nfpdg,dfpdg] = series(ncg,dcg,nfpd2,dfpd2);
[nclpdg,dclpdg] = feedback(nfpdg,dfpdg,1,1,-1);
yspdg = step(nclpdg,dclpdg,t);
POpdg = 100*(max(yspdg)-1); POpdg = round(10*POpdg)/10;
Tspdg = timesetl(t,yspdg); Tspdg = round(1000*Tspdg)/1000;
%
msg1 = ['Normal: PO = ' num2str(PO3) '%, T_s = ' num2str(Ts3) 's'];
msg2 = ['Solid = PD-DOO: PO = ' num2str(POpd) '%, T_s = ' num2str(Tspd) ' s'];
msg3 = ['Dashed = PD-DOO with Special Lag: PO = ' num2str(POpdg) '%, T_s = ' num2str(Tspdg) ' s'];
%
figure(6),clf,plot(t,ys3,t,yspd,t,yspdg,'r--'),grid,xlabel('Time (s)'),ylabel('Step Responses'),...
title('Outer Loop: Normal and PD-DOO Configurations'),set(6,'Position',fig_size),...
text(0.22,1.24,msg1),text(0.5,1.1,msg2),text(0.55,1.05,msg3)
%
yr3 = step(ncl3,[dcl3 0],t);
yrpd = step(nclpd,[dclpd 0],t);
yrpdg = step(nclpdg,[dclpdg 0],t);
%
figure(7),clf,subplot(211),plot(t,yr3,t,yrpd,t,yrpdg,[0 2],[0 2],'k--'),grid,xlabel('Time (s)'),...
ylabel('Ramp Responses'),title('Outer Loop: Normal, PD-DOO, and PD-DOO+Lag Configurations'),...
text(1.05,0.8,'PD-DOO and PD-DOO+Lag'),set(7,'Position',fig_size)
%
yr3 = step(ncl3,[dcl3 0],50*t);
yrpd = step(nclpd,[dclpd 0],50*t);
yrpdg = step(nclpdg,[dclpdg 0],50*t);
%
subplot(212),plot(50*t,yr3,50*t,yrpd,50*t,yrpdg,[0 100],[0 100],'k--'),grid,xlabel('Time (s)'),...
ylabel('Ramp Responses'),title('Outer Loop: Expanded View'),...
text(99.53,99.35,'PD-DOO'),axis([99 100 99 100])
%
%      ***** MATLAB Code Stops Here *****

Click the icon to return to the Dr. Beale's home page  

Lastest revision on Friday, May 26, 2006 9:22 PM