-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdate.m
130 lines (109 loc) · 2.81 KB
/
update.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
function update(z,R,idf,batch)
% function update(z,R,idf,batch)
%
% Inputs:
% z, R - range-bearing measurements and covariances
% idf - feature index for each z
% batch - whether to process measurements together or sequentially
%
% GLOBAL INPUTS:
% XA PA JXA OmegaPB PsiXB PhiPAB
%
% GLOBAL OUTPUTS:
% XA, PA - updated state and covariance of part A
% JXA - will be reset to zeros(1) once used
% OmegaPB PsiXB PhiPAB
%
if batch == 1
batch_update(z,R,idf);
else
single_update(z,R,idf);
end
%
%
%
function batch_update(z,R,idf)
global XA PA JXA OmegaPB PsiXB PhiPAB XB
lenz= size(z,2);
lenXA= length(XA);
H= zeros(2*lenz, lenXA);
v= zeros(2*lenz, 1);
RR= zeros(2*lenz);
for i=1:lenz
ii= 2*i + (-1:0);
[zp,H(ii,:)]= observe_model(XA, idf(i));
v(ii)= [z(1,i)-zp(1);
pi_to_pi(z(2,i)-zp(2))];
RR(ii,ii)= R;
end
%
PHt = PA*H';
S = H*PHt+RR;
Si = inv(S);
Si= make_symmetric(Si);
%PSD_check= chol(Si);
W= PHt*Si;
Kappa = H'*Si*H;
Zeta = W*H;
% update part A
XA = XA + W*v;
PA = PA - make_symmetric(W*S*W');
%PSD_check= chol(PA);
% calculate OmegaPB PsiXB PhiPAB
if length(XB)~=1
if size(OmegaPB,1) == 1
OmegaPB = JXA'*Kappa*JXA;
PsiXB = JXA'*H'*Si*v;
PhiPAB = (eye(size(XA,1)) - Zeta)*JXA;
else
OmegaPB = OmegaPB + PhiPAB'*JXA'*Kappa*JXA*PhiPAB;
PsiXB = PsiXB + PhiPAB'*JXA'*H'*Si*v;
PhiPAB = ((eye(size(XA,1)) - Zeta)*JXA)*PhiPAB;
end
JXA = zeros(1); %
end
%
%
%
function single_update(z,R,idf)
global XA PA JXA OmegaPB PsiXB PhiPAB XB
lenz= size(z,2);
for i=1:lenz
[zp,H]= observe_model(XA, idf(i));
v= [z(1,i)-zp(1);
pi_to_pi(z(2,i)-zp(2))];
% update part A
% this code is copied from KF_tricksimple_update()
Ns = 3 + 2*idf(i) - 1;
Ne = Ns+1;
Hv = H(:,1:3);
Hi = H(:,Ns:Ne);
PHt= PA(:,1:3)*Hv' + PA(:,Ns:Ne)*Hi';
S = Hv*PHt(1:3,:) + Hi*PHt(Ns:Ne,:) + R;
Si= inv(S);
Si= make_symmetric(Si);
%PSD_check= chol(Si);
W= PHt*Si;
Kappa = H'*Si*H;
Zeta = W*H;
XA= XA + W*v;
PA= PA - make_symmetric(W*PHt');
%PSD_check= chol(PA);
%%%
% calculateOmegaPB PsiXB PhiPAB
if length(XB) ~= 1
if size(OmegaPB,1) == 1
OmegaPB = JXA'*Kappa*JXA;
PsiXB = JXA'*H'*Si*v;
PhiPAB = (eye(size(XA,1)) - Zeta)*JXA;
else
OmegaPB = OmegaPB + PhiPAB'*JXA'*Kappa*JXA*PhiPAB;
PsiXB = PsiXB + PhiPAB'*JXA'*H'*Si*v;
PhiPAB = ((eye(size(XA,1)) - Zeta)*JXA)*PhiPAB;
end
JXA = eye(size(JXA));
end
end
JXA = zeros(1); %
function P= make_symmetric(P)
P= (P+P')*0.5;