Commit b1203ab9 authored by Kristian Soltesz's avatar Kristian Soltesz
Browse files

Code clean

parent 821bcd8c
function w = defaultGrid(P)
% Get default angular frequency grid based on process dynamics.
%
% P - LTI process model.
%
% Downloaded from git@gitlab.control.lth.se:kristian/PIDopt.git
% See the git repo for further documentation.
N = 5e2; % Number of grid points
[~,~,w]=bode(P); % Grequenies Matlab considers interesting
wMax = w(end);
wMin = min(w(1),wMax/100); % ensure to include low frequencies
w=logspace(log10(wMin),log10(wMax),N)';
\ No newline at end of file
......@@ -13,24 +13,26 @@ s = zpk('s');
P = 1/(s^2+2*.5*s+1)*exp(-0.5*s);
% Robustness consraints
Ms = 1.6; % Maximum allowed sensitivity function magnitude
Mt = 1.6; % Maximum allowed complementary sensitivity function magnitude
Ms = 1.8; % Maximum allowed sensitivity function magnitude
Mt = Ms; % Maximum allowed complementary sensitivity function magnitude
Mks = 2; % Maximum allowed magnitude of transfer function from process
% output to control signal, sometimes referred to as noise
% sensitivity.
%% Design
% IE-optimal design
p0 = [0 0 0]'; % Parameters of any PID controller, which stabilizes P.
% See pidIE.m for details. Use p = [0 0] to synthesize PI
% controller.
[K1,p1] = pidIE(P,Ms,Mt,Mks,p0)
% controller
w = defaultGrid(P); % default angular frequency grid
[K1,p1] = pidIE(P,Ms,Mt,Mks,p0,w) % IE-optial PID controller without filter
% IAE-optimal design
[K2,p2] = pidIAE(P,Ms,Mt,Mks,p1) % Hot-start with K1 parameters
[K2,p2] = pidIAE(P,Ms,Mt,Mks,p1,w) % Hot-start with K1 parameters
% IAE-optimal design with filter
[K3,p3,w] = pidfIAE(P,Ms,Mt,Mks,p2); % Hot-start with K2 parameters
[K3,p3,w] = pidfIAE(P,Ms,Mt,Mks,p2,w); % Hot-start with K2 parameters
K3
p3
......@@ -40,7 +42,7 @@ L = @(K)series(P,K);
S = @(K)feedback(1,L(K));
T = @(K)feedback(L(K),1);
KS = @(K)feedback(K,P);
PS = @(K)feedback(P,K)
PS = @(K)feedback(P,K);
wMin = w(1);
wMax = w(end);
......
function [K,p,w] =pidIAE(P,Ms,Mt,Mks,p)
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.
% The length of p decides if the controller is of PI or PID type.
%
% K(s) = kp + ki/s + kd*s
% K(s) = kp + ki/s + kd*s
%
% P - LTI process model.
% Ms - Maximum allowed sensitivity.
% Mt - Maximum allowed complementary sensitivity.
% Mks - Maxium allowed noise sensitivity.
% p - Vector of initial controller parameters. Length must be 2 (PI)
% or 3 (PID). Controller must stabilize plant.
% P - LTI process model.
% Ms - Maximum allowed sensitivity.
% Mt - Maximum allowed complementary sensitivity.
% Mks - Maxium allowed noise sensitivity.
% p - Vector of initial controller parameters. Length must be 2 (PI)
% or 3 (PID). Controller must stabilize plant.
% w - angular freqency grid. Use [] for default grid.
%
% Downloaded from git@gitlab.control.lth.se:kristian/PIDopt.git
% See the git repo for further documentation.
......@@ -26,9 +27,9 @@ else
end
% Frequency grid (heuristic) - change as needed
N = 500; % Number of grid points
[~,~,w] = bode(P);
w = logspace(log10(w(1)),log10(w(end)),N)';
if isempty(w)
w = defaultGrid(P);
end
% Helper functions
mdot = @(x,y)(bsxfun(@times,x,y)); % (row vector)-matrix column-wise dot
......
function [K,p,w] = pidIE(P,Ms,Mt,Mks,p)
%Computes PID parameters
function [K,p,w] = pidIE(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 functions.
......@@ -13,16 +12,15 @@ function [K,p,w] = pidIE(P,Ms,Mt,Mks,p)
% Mks - Maxium allowed noise sensitivity.
% p - Vector of controller parameters. Length must be 2 (PI)
% or 3 (PID). Controller must stabilize plant.
% w - angular freqency grid. Use [] for default grid.
%
% Downloaded from git@gitlab.control.lth.se:kristian/PIDopt.git
% See the git repo for further documentation.
% Frequency grid (heuristic) - change as needed
N = 500; % Number of grid points
[~,~,w]=bode(P);
wMax = w(end);
wMin = min(w(1),wMax/100);
w=logspace(log10(wMin),log10(wMax),N)';
if isempty(w)
w = defaultGrid(P);
end
% Frequency response
P = squeeze(freqresp(balreal(P),w));
......
function [KF,p,w]=getK2F(P,Ms,Mt,Mks,pK)
function [KF,p,w]=pidfIAE(P,Ms,Mt,Mks,pK,w)
% Computes PID parameters, that minimize load step IAE, and filter for
% noise attenuation.
%
% K(s) * F(s) = (kp + ki/s + kd*s) * 1/((s*T)^2+2*z*T*s+1)
% K(s) = F(s) * C(s) = (kp + ki/s + kd*s) * 1/((s*T)^2+2*z*T*s+1)
%
% P - LTI process model.
% Ms - Maximum allowed sensitivity.
% Mt - Maximum allowed complementary sensitivity.
% Mks - Maxium allowed noise sensitivity. This is only meaningful if
% there is high-frequency roll-off (through e.g. a filter).
% pK - Vector of initial controller parameters [kp ki kd].
% Length must be 2 (PI)
% or 3 (PID). Controller must stabilize plant.
% P - LTI process model.
% Ms - Maximum allowed sensitivity.
% Mt - Maximum allowed complementary sensitivity.
% Mks - Maxium allowed noise sensitivity. This is only meaningful if
% there is high-frequency roll-off (through e.g. a filter).
% pC - Vector of initial controller parameters [kp ki kd].
% Length must be 2 (PI)
% or 3 (PID). Controller must stabilize plant.
%
% Downloaded from git@gitlab.control.lth.se:kristian/PIDopt.git
% See the git repo for further documentation.
......@@ -26,9 +26,9 @@ else
end
% Frequency grid (heuristic) - change as needed
N = 500; % Number of grid points
[~,~,w] = bode(P);
w = logspace(log10(w(1)),log10(w(end)),N)';
if isempty(w)
w = defaultGrid(P);
end
% Ensure LP filter breakdown within grid
Tmin = 1/w(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