Commit 814213e3 authored by Kristian Soltesz's avatar Kristian Soltesz
Browse files

cleaned up pidIAE

parent 8a45acaf
% This example demonstrates how to invoke the scripts for obtaining
%IE-optimal and IAE optimal (with or without LP filter) PID controllers.
% IE-optimal and IAE optimal (with or without LP filter) PID controllers.
%
% Downloaded from git@gitlab.control.lth.se:kristian/PIDopt.git
% See the git repo for further documentation.
......
function [K,p,w] =pidIAE(P,Ms,Mt,Mks,p,w)
function [K,p,w] = pidIAE(P,Ms,Mt,Mks,p,w)
% Computes PID controller that maximizes the integral gain subject to
% constraints on the magnitude of the sensitivity, complementary
% sensitivity and noise sensitivity fu nctions.
......@@ -54,7 +54,7 @@ cfg = optimset('algorithm','active-set','GradConstr','on','GradObj','on',...
p = p*k0;
K = K(p);
% Objective and gradient
% Objective and gradient
function [J,J_p] = J(p)
% Objective
[e,t] = step(P*S(p));
......@@ -66,30 +66,47 @@ K = K(p);
J_p = trapz(t,mdot(sign(e),e_p));
end
% Constraints and gradients
% Constraints and gradients
function [c,cEq,c_p,cEq_p]=cNL(p)
% Ms
Sw = fr(S(p));
Sm = abs(Sw);
% Sensitivity
if Ms < inf
Sw = fr(S(p));
Sm = abs(Sw);
cS = Sm-Ms;
Sm_p = -mdot(Sm,real(mdot(Sw.*Pw,K_pw)));
else
cS = [];
Sm_p = [];
end
% Mt
Tw = 1-Sw;
Tm = abs(Tw);
% Complementary sensitivity
if Mt < inf
Tw = 1-Sw;
Tm = abs(Tw);
cT = Tm-Mt;
Tm_p = mdot(Tm,real(mdot(Sw.^2.*Pw./Tw,K_pw)));
else
cT = [];
Tm_p = [];
end
% Mks
Kw = fr(K(p));
Km = abs(Kw);
KSm = Km.*Sm*k0; % Undo regularization
% Noise sensitivity
if Mks < inf
Kw = fr(K(p));
Km = abs(Kw);
KSm = Km.*Sm*k0; % Undo regularization
cKS = KSm-Mks;
KSm_p = mdot(Sm./Km,real(mdot(conj(Kw).*Sw,K_pw)));
else
cKS = [];
KSm_p = [];
end
% Constraints
c = [Sm-Ms,Tm-Mt,KSm-Mks];
c = [cS cT cKS];
cEq = [];
% Gradients
SPdotK_pw = fr(P*S(p)*K_p);
Sm_p = -mdot(Sm,real(mdot(Sw.*Pw,K_pw)));
Tm_p = mdot(Tm,real(mdot(Sw.^2.*Pw./Tw,K_pw)));
KSm_p = mdot(Sm./Km,real(mdot(conj(Kw).*Sw,K_pw)));
c_p = [Sm_p;Tm_p;KSm_p].';
cEq_p = [];
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment