example.m 2.24 KB
Newer Older
1
2
3
4
% This example demonstrates how to invoke the scripts for obtaining
%IE-optimal and IAE optimal (with or without LP filter) PID controllers.
%
% Downloaded from git@gitlab.control.lth.se:kristian/PIDopt.git
5
% See the git repo for further documentation.
6

7
8
9
%% Setup
clear all
clc
10

11
12
% Process model (continuous time LTI SISO system)
s = zpk('s');
Kristian Soltesz's avatar
Kristian Soltesz committed
13
P = 1/(s^2+2*.5*s+1)*exp(-0.5*s);
14

15
16
17
18
% Robustness consraints
Ms = 1.6; % Maximum allowed sensitivity function magnitude
Mt = 1.6; % Maximum allowed complementary sensitivity function magnitude
Mks = 2; % Maximum allowed magnitude of transfer function from process
19
20
21
22
23
24
25
26
27
28
29
30
31
32
          % 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)

% IAE-optimal design
[K2,p2] = pidIAE(P,Ms,Mt,Mks,p1) % Hot-start with K1 parameters

% IAE-optimal design with filter
33
34
35
36
37
38
39
40
41
42
[K3,p3,w] = pidfIAE(P,Ms,Mt,Mks,p2); % Hot-start with K2 parameters
K3
p3

%% Evaluation
% Closed-loop transfer functions
L = @(K)series(P,K);
S = @(K)feedback(1,L(K));
T = @(K)feedback(L(K),1);
KS = @(K)feedback(K,P);
Kristian Soltesz's avatar
Kristian Soltesz committed
43
PS = @(K)feedback(P,K)
44
45
46
47
48

% Bode magnitudes (to verify robustness constraints)
wMin = w(1);
wMax = w(end);

Kristian Soltesz's avatar
Kristian Soltesz committed
49
50
close all

51
52
figure(1)
subplot(311)
Kristian Soltesz's avatar
Kristian Soltesz committed
53
bodemag(S(K1),{wMin,wMax},'b',S(K2),'r',S(K3),'g')
54
55
56
57
58
59
60
61
62
hold on
ylim([1e-1 2*Ms])
set(gca,'ytick',[1 Ms])
plot([wMin wMax],Ms*[1 1],'k')
title('Sensitivity magnitude')
legend('IE-optimal','IAE-optimal','IAE-optimal w. filter','Constraint',...
    'Location','NorthWest')

subplot(312)
Kristian Soltesz's avatar
Kristian Soltesz committed
63
bodemag(T(K1),{wMin,wMax},'b',T(K2),'r',T(K3),'g')
64
65
66
67
68
69
70
hold on
ylim([1e-1 2*Mt])
set(gca,'ytick',[1 Mt])
plot([wMin wMax],Mt*[1 1],'k')
title('Complementary sensitivity')

subplot(313)
Kristian Soltesz's avatar
Kristian Soltesz committed
71
bodemag(KS(K1),{wMin,wMax},'b',KS(K2),'r',KS(K3),'g')
72
73
74
75
76
77
78
hold on
ylim([1e-1 2*Mks])
set(gca,'ytick',[1 Mks])
plot([wMin wMax],Mks*[1 1],'k')
title('Noise sensitivity')

% Load disturbance response (to compute IE and IAE)
Kristian Soltesz's avatar
Kristian Soltesz committed
79
80
81
82
83
84
85
figure(2)
step(PS(K1),'b',PS(K2),'r',PS(K3),'g',P,'k')
hold on
title('Load step response')
legend('IE-optimal','IAE-optimal','IAE-optimal w. filter','Open-loop',...
    'Location','East')

86
87
88