% This script is used to calculated the tuning parameters from the SIMC
% method.
%
% Written by : Knut Åge Meland
% email: knutagemeland@gmail.com
clear all
close all
clc

%%
make_plot_P1_Kc10_38


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

%data read from figure 5
dys=2;
tp=18-7;
yp=abs(25-27.5);
yu=abs(27-27.5);

%calc

dss_inf= abs(26-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


