-
Notifications
You must be signed in to change notification settings - Fork 0
/
lqr_speed.m
59 lines (48 loc) · 1.09 KB
/
lqr_speed.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
function [K, W_t] = lqr_speed(dX_t)
global UUV
a = 0;
b = atan(-dX_t(3)/dX_t(1));
c = atan(dX_t(2)/dX_t(1));
W_t = [a,b,c].';
Tv = [
cos(c)*cos(b), -cos(a)*sin(c)+cos(c)*sin(a)*sin(b), sin(c)*sin(a)+cos(c)*cos(a)*sin(b);
sin(c)*cos(b), cos(c)*cos(a)+sin(c)*sin(a)*sin(b), -cos(c)*sin(a)+cos(a)*sin(c)*sin(b);
-sin(b), cos(b)*sin(a), cos(b)*cos(a)
];
dX_ = Tv\dX_t;
Ru = -UUV.Cu*abs(dX_(1))*dX_(1);
Tx_h = UUV.TxMax + Ru;
A = [
0 0 0 -sin(b)*cos(c)*Tx_h/UUV.Mu -sin(c)*cos(b)*UUV.TxMax/UUV.Mu 0 0;
0 0 0 -sin(b)*sin(c)*Tx_h/UUV.Mv cos(b)*cos(c)*UUV.TxMax/UUV.Mv 0 0;
0 0 0 -cos(b)*Tx_h/UUV.Mw 0 0 0;
0 0 0 0 0 1 0;
0 0 0 0 0 0 1;
0 0 0 0 0 0 0;
0 0 0 0 0 0 0;
];
B = [
cos(c)*cos(b)/UUV.Mu 0 0;
sin(c)*cos(b)/UUV.Mv 0 0;
-sin(b)/UUV.Mw 0 0;
0 0 0;
0 0 0;
0 1/UUV.Iq 0;
0 0 1/UUV.Ir;
];
Q = [
1 0 0 0 0 0 0;%dx
0 1 0 0 0 0 0;%dy
0 0 1 0 0 0 0;%dz
0 0 0 1 0 0 0;%b
0 0 0 0 1 0 0;%c
0 0 0 0 0 0 0;%db
0 0 0 0 0 0 0;%dc
];
R = [
1e3 0 0;
0 1e11 0;
0 0 1e11;
];
K = lqr(A,B,Q,R);
end