-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFuncJacobian.m
100 lines (88 loc) · 2.91 KB
/
FuncJacobian.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function [Jacobian] = FuncJacobian(Zstate,Xstate)
nRowNum = length(Zstate(:,1));
ID1 = [];
ID2 = [];
Val = [];
i = 1;
while i<=nRowNum;
if Zstate(i,2)==1;
a = find(Xstate(:,1)==-Zstate(i,4));
b = find(Xstate(:,1)==-Zstate(i,3));
P1 = Xstate(a(:),2);
P2 = Xstate(b(:),2);
%%
Alpha = P1(4);
Beta = P1(5);
Gamma = P1(6);
RZ = FuncRZ(Alpha);
RY = FuncRY(Beta);
RX = FuncRX(Gamma);
R = FuncR(RZ,RY,RX);
t = P1(1:3);
dRZdA = FuncdRZdA(Alpha);
dRYdB = FuncdRYdB(Beta);
dRXdG = FuncdRXdG(Gamma);
dRdA = FuncR(dRZdA,RY,RX);
dRdB = FuncR(RZ,dRYdB,RX);
dRdG = FuncR(RZ,RY,dRXdG);
%%
t2 = P2(1:3);
Alpha2 = P2(4);
Beta2 = P2(5);
Gamma2 = P2(6);
%%
RZ2 = FuncRZ(Alpha2);
RY2 = FuncRY(Beta2);
RX2 = FuncRX(Gamma2);
R2 = FuncR(RZ2,RY2,RX2);
Ri = R'*R2;
dRZ2dA2 = FuncdRZdA(Alpha2);
dRY2dB2 = FuncdRYdB(Beta2);
dRX2dG2 = FuncdRXdG(Gamma2);
dR2dA2 = FuncR(dRZ2dA2,RY2,RX2);
dR2dB2 = FuncR(RZ2,dRY2dB2,RX2);
dR2dG2 = FuncR(RZ2,RY2,dRX2dG2);
%%
dRidA2 = R'*dR2dA2;
dRidB2 = R'*dR2dB2;
dRidG2 = R'*dR2dG2;
dRidA = dRdA'*R2;
dRidB = dRdB'*R2;
dRidG = dRdG'*R2;
%%
ddA2 = FuncdRi(dRidA2,Ri);
ddB2 = FuncdRi(dRidB2,Ri);
ddG2 = FuncdRi(dRidG2,Ri);
ddA = FuncdRi(dRidA,Ri);
ddB = FuncdRi(dRidB,Ri);
ddG = FuncdRi(dRidG,Ri);
R_T = R';
%% add the values in Jacobian
ID1 = [ID1;i;i+1;i+2;i;i+1;i+2;i;i+1;i+2;i;i+1;i+2;i;i+1;i+2;i;i+1;i+2;i;i+1;i+2;i;i+1;i+2;i;i+1;i+2;i+3;i+4;i+5;i+3;i+4;i+5;i+3;i+4;i+5;i+3;i+4;i+5;i+3;i+4;i+5;i+3;i+4;i+5];
ID2 = [ID2;a(1);a(1);a(1);a(2);a(2);a(2);a(3);a(3);a(3);a(4);a(4);a(4);a(5);a(5);a(5);a(6);a(6);a(6);b(1);b(1);b(1);b(2);b(2);b(2);b(3);b(3);b(3);a(4);a(4);a(4);a(5);a(5);a(5);a(6);a(6);a(6);b(4);b(4);b(4);b(5);b(5);b(5);b(6);b(6);b(6)];
Val = [Val;-R_T(:,1);-R_T(:,2);-R_T(:,3);dRdA'*(t2-t);dRdB'*(t2-t);dRdG'*(t2-t);R_T(:,1);R_T(:,2);R_T(:,3);ddA;ddB;ddG;ddA2;ddB2;ddG2];
i = i+6;
elseif Zstate(i,2)==2
i = i+3;
elseif Zstate(i,2)==0 % direct measurement of length, width and/or height
p=find(Xstate(:,1)==1);
%pause
if Zstate(i,4)==-1
ID1 = [ID1; i];
ID2 = [ID2; p(1)];
Val = [Val; 1];
elseif Zstate(i,4)==-2
ID1 = [ID1; i];
ID2 = [ID2; p(2)];
Val = [Val; 1];
elseif Zstate(i,4)==-3
ID1 = [ID1; i];
ID2 = [ID2; p(3)];
Val = [Val; 1];
end
i=i+1;
end
end
Jacobian = sparse(ID1,ID2,Val);
Jacobian = Jacobian(:,7:end);
end