-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpid_optim.m
86 lines (71 loc) · 1.75 KB
/
pid_optim.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function [J] = pid_optim(x)
%DC Motor TF
s = tf('s');
plant = 104.9/(s^2 + 103.5*s + 2617);
%PID Controller:
Kp = x(1)
Ki = x(2)
Kd = x(3)
cont = Kp + Ki/s + Kd*s;
%Closed Loop System Response
%step(feedback(plant*cont,1));
dt = 0.01;
time = 0:dt:1;
S = stepinfo(feedback(plant*cont,1));
%IAE
% [y t]=step(feedback(plant*cont,1),time);
% for i=1:length(t)
% error(i)=1-y(i);
% end
% J=sum(abs(error));
%ITAE
% [y t]=step(feedback(plant*cont,1),time);
% for i=1:length(t)
% error(i)=abs(1-y(i))*t(i);
% end
% J=sum(error);
%ISE
% [y t]=step(feedback(plant*cont,1),time);
% for i=1:length(t)
% error(i)=1-y(i);
% end
% error=error*error';
% J=sum(error);
%ITSE
% [y t]=step(system,time);
% for i=1:length(t)
% error(i)=((1-y(i))^2)*t(i);
% end
% J=sum(error);
%Modified ITAE 1
% ITAE = ITAE + a*Overshoot + b*SSError + c*SettlingTime + d*RiseTime
[y t]=step(feedback(plant*cont,1),time);
for i=1:length(t)
error(i)=abs(1-y(i))*t(i);
end
St = S.SettlingTime;
Rt = S.RiseTime;
Ov = S.Overshoot;
SSE = abs(1-y);
JE =sum(error);
% JRt = (sum(Rt))';
% JSt = (sum(St))';
% JOv = (sum(Ov))';
JSSE = (sum(SSE(end)))';
a= 1; b=2; c=3; d=4;
J = JE + c*St + a*Ov + b*JSSE + c*St + d*Rt;
%Modified ITAE 2
%Settling Time, Rise Time Peak Time & Overshoot
% S = stepinfo(feedback(plant*cont,1));
% [y t]=step(feedback(plant*cont,1),time);
% for i=1:length(t)
% error(i)=abs(1-y(i))*t(i);
% SSE(i) = abs(1-y(i))*t(i);
% end
% JE =sum(error);
% JRt = S.RiseTime;
% JSt = S.SettlingTime;
% JOv = S.Overshoot;
% JSSE = sum(SSE);
% a= 1.5; b=15; c=7; d=1;
% J = JE + a*JOv + b*JSSE + c*JSt + d*JRt