comparison toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/SLAM/slam_partial_kf.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 % See how well partial Kalman filter updates work
2
3 seed = 0;
4 rand('state', seed);
5 randn('state', seed);
6 nlandmarks = 6;
7 T = 12;
8
9 [A,B,C,Q,R,Qbig,Rbig,init_x,init_V,robot_block,landmark_block,...
10 true_landmark_pos, true_robot_pos, true_data_assoc, ...
11 obs_rel_pos, ctrl_signal] = mk_linear_slam(...
12 'nlandmarks', nlandmarks, 'T', T, 'ctrl', 'leftright', 'data-assoc', 'cycle');
13
14 % exact
15 [xe, Ve] = kalman_filter(obs_rel_pos, A, C, Qbig, Rbig, init_x, init_V, ...
16 'model', true_data_assoc, 'u', ctrl_signal, 'B', B);
17
18
19 % approx
20 %k = nlandmarks-1; % exact
21 k = 3;
22 ndx = {};
23 for t=1:T
24 landmarks = unique(true_data_assoc(t:-1:max(t-k,1)));
25 tmp = [landmark_block(:, landmarks) robot_block'];
26 ndx{t} = tmp(:);
27 end
28
29 [xa, Va] = kalman_filter(obs_rel_pos, A, C, Qbig, Rbig, init_x, init_V, ...
30 'model', true_data_assoc, 'u', ctrl_signal, 'B', B, ...
31 'ndx', ndx);
32
33
34
35 nrows = 10;
36 stepsize = T/(2*nrows);
37 ts = 1:stepsize:T;
38
39 if 1 % plot
40
41 clim = [0 max(max(Va(:,:,end)))];
42
43 figure(2)
44 if 0
45 imagesc(Ve(1:2:end,1:2:end, T))
46 clim = get(gca,'clim');
47 else
48 i = 1;
49 for t=ts(:)'
50 subplot(nrows,2,i)
51 i = i + 1;
52 imagesc(Ve(1:2:end,1:2:end, t))
53 set(gca, 'clim', clim)
54 colorbar
55 end
56 end
57 suptitle('exact')
58
59
60 figure(3)
61 if 0
62 imagesc(Va(1:2:end,1:2:end, T))
63 set(gca,'clim', clim)
64 else
65 i = 1;
66 for t=ts(:)'
67 subplot(nrows,2,i)
68 i = i+1;
69 imagesc(Va(1:2:end,1:2:end, t))
70 set(gca, 'clim', clim)
71 colorbar
72 end
73 end
74 suptitle('approx')
75
76
77 figure(4)
78 i = 1;
79 for t=ts(:)'
80 subplot(nrows,2,i)
81 i = i+1;
82 Vd = Va(1:2:end,1:2:end, t) - Ve(1:2:end,1:2:end,t);
83 imagesc(Vd)
84 set(gca, 'clim', clim)
85 colorbar
86 end
87 suptitle('diff')
88
89 end % all plot
90
91
92 for t=1:T
93 %err(t)=rms(xa(:,t), xe(:,t));
94 err(t)=rms(xa(1:end-2,t), xe(1:end-2,t)); % exclude robot
95 end
96 figure(5);plot(err)
97 title('rms mean pos')
98
99
100 for t=1:T
101 i = 1:2*nlandmarks;
102 denom = Ve(i,i,t) + (Ve(i,i,t)==0);
103 Vd =(Va(i,i,t)-Ve(i,i,t)) ./ denom;
104 Verr(t) = max(Vd(:));
105 end
106 figure(6); plot(Verr)
107 title('max relative Verr')