clc
close all
clear all

set(0,'DefaultTextFontName','Times',...
'DefaultTextFontSize',16,...
'DefaultAxesFontName','Times',...
'DefaultAxesFontSize',16,...
'DefaultLineLineWidth',2,...
'DefaultLineMarkerSize',7.75)

Kc = 0.1;
taui = 20;
%out = sim("tunepid1_ex1.mdl");
%plot(time,u,'red:',time,Tf,'blue-.',time,T,'green')
%hold on;

%Kc = 2/15;
%taui = 20;
%taud = 0;
%out = sim("tunepid1_ex1.mdl");
%plot(time,u,'red:',time,Tf,'blue-.',time,T,'green')

Kc = 1.13;
taui = 99999;
taud = 0;
out = sim("tunepid1_ex1.mdl");
plot(time,u,'red:',time,Tf,'blue-.',time,T,'green')

%ylim([-1.5 1.5])
legend('u', 'Tf', 'T')

% Finner toppene og perioden til exercise 7 oppgave 1.3
bigboi1 = 0;
peaktime1 = 0;
bigboi2 = 0;
peaktime2 = 0;
for i = 1:size(T)
    if time(i) > 400 & time(i) < 600
        if u(i) < bigboi1
            bigboi1 = u(i);
            peaktime1 = time(i);
        end
    elseif time(i) > 700
        if u(i) < bigboi2
            bigboi2 = u(i);
            peaktime2 = time(i);
        end
    end
end

disp('Perioden er')
disp(peaktime2)
disp(peaktime1)
disp(peaktime2 - peaktime1)


