global u0
u0=[0.1;0.36;8.64];



%tuning cascade
%Inner controller
dys=0.1;
dyp=0.045;
dyu=0.025;
t=0.005;
%dyinf=0.0167; 
dyinf=0.45*(dyp+dyu);
Kc0= 0.002;


overshoot= (dyp-dyinf)/dyinf;
b= dyinf/dys;
F=5;
tau=10;
%dead=1.4;
%F=0.5*(tau+dead/dead);
A=1.152*overshoot^2 -1.607*overshoot +1;
Kc1=Kc0*A/F;
t1=min(0.86*A*abs(b/(1-b))*t,2.44*t*F);
tauI1=Kc1/min(0.86*A*abs(b/(1-b))*t,2.44*t*F);




%Outer controller
dys=0.01;
dyp=0.0142;
%dyu=0.01;
t=3.6;
dyinf=0.01; 
Kc0= -200;


overshoot= (dyp-dyinf)/dyinf;
b= dyinf/dys;
F=50;
tau=10;
%dead=1.4;
%F=0.5*(tau+dead/dead);
A=1.152*overshoot^2 -1.607*overshoot +1;
Kc2=Kc0*A/F;
t2=min(0.86*A*abs(b/(1-b))*t,2.44*t*F);
tauI2=Kc2/min(0.86*A*abs(b/(1-b))*t,2.44*t*F);


%tuning only P1
dys=0.01;
dyp=0.0122;
%dyu=0.01;
t=3.9;
dyinf=0.01; 
Kc0= -2;


overshoot= (dyp-dyinf)/dyinf;
b= dyinf/dys;
F=50;
tau=10;
%dead=1.4;
%F=0.5*(tau+dead/dead);
A=1.152*overshoot^2 -1.607*overshoot +1;
Kc=Kc0*A/F;
t3=min(0.86*A*abs(b/(1-b))*t,2.44*t*F);
tauI=Kc/min(0.86*A*abs(b/(1-b))*t,2.44*t*F);