clc
clear
close all

%% PI Control
Kc = 1.03;
tauI = 26.5;

sim('midterm2017_Exercise5_PI') 
% Save results
y_PI = y;
u_PI = u;
t_PI = t;

%% PID Control
clear('y','u','t','Kc','tauI')

Kc = 1.74;
tauI = 19.2;
tauD = 3.4;

%% Switch between PI and PID
sim('midterm2017_Exercise5_PID')
% Save results
y_PID = y;
u_PID = u;
t_PID = t;


figure
subplot(2,1,1)
plot(t_PI,u_PI,'k')
hold on
plot(t_PID,u_PID,'k--')
legend('PI','PID','Location','best','Orientation','horizontal')
xlabel('Time,(s)','Interpreter','latex')
ylabel('u','Interpreter','latex')
legend('boxoff')
ax = gca;
ax.FontSize = 12;
ax.TickLabelInterpreter = 'latex';
ax.Legend.Interpreter = 'latex';

subplot(2,1,2)
plot(t_PI,y_PI,'k')
hold on
plot(t_PID,y_PID,'k--')
legend('PI','PID','Location','best','Orientation','horizontal')
xlabel('Time,(s)','Interpreter','latex')
ylabel('y','Interpreter','latex')
legend('boxoff')
ax2 = gca;
ax2.FontSize = 12;
ax2.TickLabelInterpreter = 'latex';
ax2.Legend.Interpreter = 'latex';




