clear all
clc
sim('pi_controllers')
% Kc=-25;%bar^-1;
% taui=10;%s
tout=tout/60;
tid_reg=2;
tid_av=8;
P1=P1-1;
sp=sp-1;
z=z*100;
index_paa=find(abs(tout-tid_reg)==min(abs(tout-tid_reg)));
index_av=find(abs(tout-tid_av)==min(abs(tout-tid_av)));

sp=sp(index_paa:index_av);
t_sp=tout(index_paa:index_av);

P1(1:index_paa)=P1(1:index_paa)-0.013; %retter paa feil konvertering til barg
% index=find(abs(tout-9.8054)==min(abs(tout-9.8054)));
% P1(index:end)=P1(index:end)-0.013;


figure(1)
subplot(2,1,1)
plot(tout,P1)
hold on
plot(t_sp,sp,'r','linewidth',2)
ylabel('P_1 [barg]')
legend('P_1 [barg]','SP [barg]',0)
hold off

subplot(2,1,2)
plot(tout,z)
xlabel('tid [min]')
ylabel('Ventilåpning %')
axis([0 10 0 80])
g=gcf;
set(g,'PaperUnits','centimeters','PaperType','A4')
opts = struct('FontMode','fixed','FontSize',9,'Width',15,'Color','rgb');
exportfig(g,'enkel_regulering_P1_z_30.eps',opts)

figure(2)
subplot(4,1,1)
plot(tout,P2)
ylabel('P_2 [barg]')

subplot(4,1,2)
plot(tout,W)
ylabel('W [kg/s]')

subplot(4,1,3)
plot(tout,Q)
ylabel('Q  [10^{-4} m^3/s]')

subplot(4,1,4)
plot(tout,z)
xlabel('tid [min]')
ylabel('Ventilåpning %')
g=gcf;
set(g,'PaperUnits','centimeters','PaperType','A4')
opts = struct('FontMode','fixed','FontSize',9,'Width',15,'Color','rgb');
exportfig(g,'enkel_regulering_data_z_30.eps',opts)