summaryrefslogtreecommitdiff
path: root/2048/DEPENDENCIES/gmvc_pid.sci
blob: c00f2b000873548f4b9e48939ef13bc290ec1586 (plain)
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
// PID tuning through GMVC law
// 11.17

// function [Kc,tau_i,tau_d,L] = gmvc_pid(A,B,k,T,Ts)
// Determines p,i,d tuning parameters using GMVC
// Plant model: Integrated white noise
// A, B in discrete time form

function [Kc,tau_i,tau_d,L] = gmvc_pid(A,B,k,T,Ts)

dA = length(A)-1; dB = length(B)-1;
dT = length(T)-1;
if dA > 2,
   disp('degree of A cannot be more than 2')
   exit
elseif dB > 1,
   disp('degree of B cannot be more than 1')
   exit
elseif dT > 2,
   disp('degree of T cannot be more than 2')
   exit
end
delta = [1 -1]; ddelta = 1;

[Adelta,dAdelta] = polmul(A,dA,delta,ddelta);

[Q,dQ,P,dP] = ...
xdync(Adelta,dAdelta,B,dB,T,dT);
PAdelta = P(1)*Adelta;

[zk,dzk] = zpowk(k);
[E,degE,F,degF] = ...
xdync(PAdelta,dAdelta,zk,dzk,P,dP);
nu = P(1)*E(1)*B(1);
Kc = -1/nu*(F(2)+2*F(3));
tau_i = -(F(2)+2*F(3))/(F(1)+F(2)+F(3))*Ts;
tau_d = -F(3)/(F(2)+2*F(3))*Ts;
L(1) = 1+Ts/tau_i+tau_d/Ts;
L(2) = -(1+2*tau_d/Ts);
L(3) = tau_d/Ts;
L = Kc * L';
endfunction;