% Fig. 5.27  Feedback Control of Dynamic Systems, 8e 
%             Franklin, Powell, Emami
% script for Figure 5.27, Revised Lead design for more damping

close all; clear all;

%clf 
s=tf('s');

sysG=1/((s*(s+1)));
sysD=(s+2)/(s+13);
 
figure(1)

rlocus(sysD*sysG)
set(findall(gcf,'type','line'),'linewidth',3);

axis([-14 4 -8 8])
title('Root locus for lead design')

hold on

z=0.1:.2:.9;
 wn=2:2:15;
 sgrid(z, wn)

 
r=roots([1 14 (13+91) 91*2]);  % s(s+1)(s+13)+91(s+2)
plot( r, 'r*', "MarkerSize", 20)
% hold off


figure(2)

rlocus(sysD*sysG)
set(findall(gcf,'type','line'),'linewidth',3);

axis([-14 4 -8 8])
title('Root locus for lead design')

hold on

 
r=roots([1 14 (13+91) 91*2]);  % s(s+1)(s+13)+91(s+2)
plot( r, 'r*', "MarkerSize", 20)
% hold off


sys4=(s+2)/((s*(s+1))*(s+10));
rlocus(sys4)
set(findall(gcf,'type','line'),'linewidth',3);
axis([-14 4 -8 8])

title('Root locus for lead design')
hold on

r=roots([1 11 80 140]);  % s(s+1)(s+10)+70(s+2)
plot(r,'*c', "MarkerSize", 20)

set(findall(gcf,'type','line'),'linewidth',3);


z=0.1:.2:.9;
 wn=2:2:15;
 sgrid(z, wn)
% hold off



figure(3)

sys4=(s+2)/((s*(s+1))*(s+10));

K=70;
sysCL=feedback(K*sys4,1);

step(sysCL)
grid on 
axis([0 1.8 0 1.4])
title('Step response for lead design')

%set(gco,'LineWidth',4)

set(findall(gcf,'type','line'),'linewidth',3);

hold on

K=91;
sysCL=feedback(K*sysD*sysG,1);

step(sysCL)
grid on

axis( [ 0 1.7 0 1.4 ] )
title('Step response for lead design with K = 70(s+2)/(s+10) and K=91(s+2)/(s+13)')

%set(gco,'LineWidth',4)

set(findall(gcf,'type','line'),'linewidth',3);
