%this script calculates the closed loop model and the belonging tuning
%parameters

% Belonging files: P3_closedloop_3f.txt and P3_closedloop_3_plot.m

clear all
close all
clc

%%
make_plot_P4P2_Kc2_ravg1_filter_42

%From the experiment: 
Kc0=2; %absolute value

%data read from figure 5
dys=3;
tp=1162-1137;
yp=abs(31.1-27.5);
%yu=abs(28-29.4);

%calc

dss_inf= abs(29.6-27.5);
%dss2= 0.45*(yp+yu);
Overshoot= (yp-dss_inf)/dss_inf;
ss_offset= abs((dys-dss_inf)/dss_inf);

A=1.152*Overshoot^2 - 1.607*Overshoot + 1;
r= 2*A/ss_offset;

%model param
k=1/(Kc0*ss_offset);
theta=tp*(0.309+0.209*exp(-0.61*r));
tau1=r*theta;

%plotting the model
% s=tf('s');
% G=(k*exp(-theta*s))/(tau1*s+1);
% x=0:0.25:100;
% output=42+step(-5*30*G,x);




% hold on
% plot(x+100,output,'g')


%tunings

Kc= 1/k*(tau1/(2*theta))
tauI=min(tau1,4*(theta*2))/60


