function [ C_cho ] = pid_cho(lambda)
%UNTITLED4 Summary of this function goes here
%   Detailed explanation goes here


theta=0;
sys=model;
[num, den]=tfdata(sys);
num=num{1};
den=den{1};

b1=num(2);
b0=num(3);
a1=den(2);
a0=den(3);

disp('CHO TUNING CALCULATION:');
disp('  ')
disp('Controller structure:')
disp('  ')
disp('C=Kc(1 +( 1/(tau_i* s))+ tau_d* s)*((lambda *s +1)^2/(beta_2 * s^2 + beta_1*s +1))')

syms beta1
syms beta2

F1_cho = (3*(lambda^2)+theta*beta1-beta2)/((lambda^3)+theta*beta2)-a1;
F2_cho = (3*lambda+theta-beta1)/(lambda^3+theta*beta2)-a0;

s = solve(F1_cho,F2_cho,beta1,beta2);
beta1 = double(s.beta1);
beta2 = double(s.beta2);


%s=tf('s');
%C=(beta1/(b0*(lambda^3+theta*beta2)))*(1+(1/(beta1*s))+((beta2*s)/beta1));
% Filter

%sys=feedback(F,C);

% PID - Tuning values

kc=beta1/(b1*(lambda^3+theta*beta2));
tau_i=beta1;
tau_d=beta2/beta1;
I=kc/tau_i;
D=kc*tau_d;

% Set-point filter

%numf = [lambda 1];
numf = [lambda^2 2*lambda 1];
denf = [beta2 beta1 1];

%F=(lambda*s+1)/(beta2*s^2+beta1*s+1)


val(5)=kc;
val(6)=I;
val(7)=D;
%val(8)=tf(numf,denf);
filter_transfer_function_cho_tuning=tf(numf,denf);
s = tf('s');
 C_cho =kc*(1 +( 1/(tau_i*s))+ tau_d*s/(4*s+1))*((lambda*s +1)^2/(beta2*s^2 + beta1*s+1));
% C_cho=kc*(1+(1/(tau_i*s))+(tau_d*s));

L_cho = sys*C_cho;
 allmargin(L_cho)



end

