% Magnitude Optimum controller parameters for Pp_t3ex2plus_sim.slx;
% plant example according to K.G. Papadopoulos, PID Controller Tuning Using
% the Magnitude Optimum Criterion, Springer 2015, pp. 129/130,
% equations (5.36)/(5.37), (5.38)/(5.39), (5.53)
% here: ideal PID structure, no consideration of non-ideal D-terms
%       - in contrast to simulation 

%plant parameters 5.2.3.2:"Process with time delay equal to its...":
% special feature: real plant integrator(s)
Vs=0.254; Td=1;  nump=1;
denop=conv([1 0],conv([1 1],...
                 conv([0.5 1],conv([0.2 1],conv([0.2 1],[0.1 1])))));


[REGd1,A1,F1]=bo_d_gen(13,Vs,nump,denop,Td,19);
[REGd2,A2,F2]=bo_d_gen(04,Vs,nump,denop,Td,19);

REG129a(2  , : )=REGd2;            %length=5
REG129a(1  ,1:4)=REGd1,            %length=4

% special features: real plant integrator
% AND controller with double integrator modelled HERE via second plant
% integrator - see book page 130
denop1=conv([1  0],conv([1  0],conv([1 1],conv([0.5 1],conv([0.2 1],...
       conv([0.2 1],[0.11 1]))))));

[REGd12,A12,F12]=bo_d_gen(13,Vs,nump,denop1,Td,19);
[REGd22,A22,F22]=bo_d_gen(04,Vs,nump,denop1,Td,19);

REG129(2  , : )=REGd22;             %length=5
REG129(1  ,1:4)=REGd12,             %length=4

disp('"Pp_t3ex2plus_sim.slx" will be called - compare parameters')
Pp_t3ex2plus_sim; sim('Pp_t3ex2plus_sim',300),
disp('Repeat bo_d_gen call at MATLAB promt, if search algorithm fails')
