-
Notifications
You must be signed in to change notification settings - Fork 0
/
EEL3657.asv
81 lines (64 loc) · 1.67 KB
/
EEL3657.asv
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
%Setup a pid controller
%CL RESPONSE RISE TIME OVERSHOOT SETTLING TIME S-S ERROR
%Kp Decrease Increase Small Change Decrease
%Ki Decrease Increase Increase Eliminate
%Kd Small Change Decrease Decrease No Change
Kp = 1;
Kd = 1;
Ki = 1;
s=tf('s');
GH = (0.2*s +3.2)/((s+1)*(s+.8));
%%
% solve PID control
z=-log(.10)/sqrt(pi^2+log(.10)^2);
wn=4/(8*z);
N=[0 0 wn^2];
D=[1 2*wn*z wn^2];
p= roots(D);
S1 = p(1);
syms kd kp x
GHs = (0.2*S1 +3.2)/((S1+1)*(S1+.8));
%1+P*GHs=0, P = Kp + Kd*s +Ki/s
%Kp + Kd*S1 = -1/GHs-Ki/(S1)
% Ki = .1 small
% use imaginary part to solve Kd
Kd = sym2poly(solve(imag(S1)*kd==imag(-1/GHs-Ki/(S1)),kd));
%use real part to solve Kp
Kp = sym2poly(solve(kp+real(S1)*Kd==real(-1/GHs-Ki/(S1)),kp));
P = Kp+Kd*s+Ki/s;
%%
% find Kv
syms b;
Px = Kp + Ki/x + Kd*x; %pid
Gh = (0.2*x +3.2)/((x+1)*(x+.8)); % plant
c = (x+1/Tg)/(x+1/(b*Tg)); % lag
kv = limit((x*c*Px*Gh),0);
% set Beta to that value
B = double(solve(kv==5,b));
%setup a lag compensator
Kc = 1; % choose Kc = 1
Tg = 0.05;
%B = 1.25; % 1.25;
Gc = (s+1/Tg)/(s+1/(B*Tg)); % = 1 initially (lag)
Px = Kp + Ki/x + Kd*x; %pid
Cg = (x+1/Tg)/(x+1/(B*Tg));
c = (x+1/Tg)/(x+1/(b*Tg)); % lag
limit((x*c*Px*Gh),0)
Kv = limit((x * Cg * Cl * Px * Gh),x,0);
fprintf('The value of Kv is %s\n',char(Kv));
% show root locus
figure()
rlocus(P*Gc*GH)
sgrid
figure()
sys = feedback(P * Gc * GH,1);
% show unit step plot
step(sys)
t = 0:.01:100;
figure()
% show unit ramp plot
lsim(sys,t,t)
title('Response to Unit Ramp Input')
sse = abs(1-dcgain(sys));
fprintf('The sse is %f\n',sse);
minreal(tf(P * Gc * GH,1))