%P_controller.m
%P Controller


clc
%echo on

%Plant
fprintf('\nPLANT: G(s)=A/(s^2+s+1)\n')
A=1
numG=[A];
denG=[1 1 1];
zG=roots(numG)
pG=roots(denG)
sysG=tf(numG,denG)
figure(1)
pzmap(sysG)


fprintf('\nPress a key to continue ... \n')
pause

while 1
   
   Kp=input('\nEnter proportional gain (0 to end): ');
   if Kp==0
      break;
   end
	numK=Kp;
	denK=1;
	sysK=tf(numK,denK)

	%Series connection
	sys_series=series(sysK,sysG);
	
	%Feeback connection
	sys_feedback=feedback(sys_series,1)

	[Z_feedback,P_feedback,K_feedback]=zpkdata(sys_feedback,'v')
	figure(2)
	pzmap(sys_feedback)

	fprintf('\nPress a key to continue ... \n')
	pause

	tfinal=15;
	[y,t]=step(sys_feedback,tfinal);

	figure(3)
   plot(t,y,'r-',t,ones(size(t)),'b:')
   title(['STEP RESPONSE - PROPORTIONAL CONTROLLER: K_{p}=',num2str(Kp)])
	axis([0 tfinal 0 2])

end

%echo off

