function [Kp,Ti,Td,PM,wc,alfa,beta,a]=...
   pid_tun_maxdelay(K,tau,delta,c,gamma,itun)
% PURPOSE. Tuning PID controller for double 
% integrating plus time delay plant. Where 
% K=plant gain, tau=time delay.
% [Kp,Ti,Td,PM,wc,alfa,beta,a]=...
% pid_tun_maxdelay(K,tau,delta)
% On Input
% K,Tau-Model param.
% delta-The prescribed maximum relative 
%        time delay margin.
% itun -itun=1 (DM=dtau_max=delta*tau). 
%       Ms constant
%       itun=2 (DM=dtau_max=delta. 
%       Varying Ms.
% On output
% Kp   -The proportional constant 
% Ti   -The Integral time constant
% Td   -The derivative time constant
% PM,wc-The phase margin, gain crossover freq.
% Calls:pd_tun_maxdelay, pi_tun_maxdelay.

% The algorithm for tuning PID controller for 
% double int+delay process
if nargin == 5;itun=2;end
if nargin == 4;itun=2;gamma=2.1;end
if nargin == 3;itun=2;gamma=2.1;c=2.5;end
if nargin == 2;itun=2;gamma=2.1;c=2.5;...
        delta=1.6;end
%c=2.5; gamma=2.1;   % Default settings
[Kp,Td,PM,wc,alfa,beta,a]=...
    pd_tun_maxdelay(K,tau,delta,c,itun);
Ti=gamma*Td;
% end pid_tun_maxdelay.m