Commit 57ac81d1 authored by Kristian Soltesz's avatar Kristian Soltesz
Browse files

Added code for tuning IE-optimal robust PID

parent 4f4c694f
function [K,p,w] = pidIE(P,Ms,Mt,Mks,p,wN,N,tol)
%Computes PID parameters
% Computes PID controller that maximizes the integral gain subject to
% constraints on the magnitude of the sensitivity, complementary
% sensitivity and noise sensitivity functions.
% The length of p decides if the controller is of PI or PID type.
%
% 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 controller parameters. Length must be 2 (PI).
% and 3 (PID). Controller must stabilize plant.
% wN - intended Nyquist frequency when implementing controller
% N - number of points in frequency grid. Optional, use [].
% tol - relative stopping tolerance. Optional, use [].
%
% Downloaded from git@gitlab.control.lth.se:kristian/PIDopt.git
% optional argument defaults
if N == []
N=500; % number of grid points
end
if tol == []
tol = 1e-3;
end
% frequency grid (heuristic)
[~,~,w]=bode(P);
wMax = min(wN,w(end));
wMin = min(w(1),wMax/100);
w=logspace(log10(wMin),log10(wMax),N)';
% frequency response
P = squeeze(freqresp(balreal(P),w));
% Constraint represented as circles with centresa and radii :
cs = -1; % Ms center
rs = 1./Ms; % Ms radius
ct = -Mt.^2./(Mt.^2-1); % Mt center
rt = Mt./(Mt.^2-1); % Mt radius
% controller structure
K1=[1+0*w 1./(1i*w) 1i*w];
n=numel(p);
K1=K1(:,1:n);
K=K1*p;
% Optimization routine
prev_obj = -inf; % Used for the stopping criterion
max_iters = 10; % max number of iterations (heuristic)
for iter = 1:max_iters
Lc = P.*K; % Loop transfer funtion
cvx_begin
cvx_quiet(true)
variable p(n)
maximize (p(2)) % Maximize integral gain
subject to
K = K1*p;
L = P.*K;
real(conj((Lc-cs)./abs(Lc-cs)).*(L-cs)) >= rs; % Sensitivity constraint
real(conj((Lc - ct)./abs(Lc-ct)).*(L-ct)) >= rt; % Complementary sensitivity constraint
abs(K) - Mks.*real(conj(1+Lc)./(abs(1+Lc)).*(1+L)) <= 0; % Noise sensitivity constraint
cvx_end
if n == 2
p(3) = NaN;
end
% Stopping criterion (heuristic):
if (p(2)-prev_obj) < 1e-3*prev_obj
break;
end
prev_obj = p(2);
end
s = zpk('s');
K1 = [1 1/s s];
K1 = K1(1:n);
K = K1*p;
\ No newline at end of file
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