comparison toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/SLAM/slam_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 % Plot how precision matrix changes over time for KF solution
2
3 seed = 0;
4 rand('state', seed);
5 randn('state', seed);
6
7 [A,B,C,Q,R,Qbig,Rbig,init_x,init_V,robot_block,landmark_block,...
8 true_landmark_pos, true_robot_pos, true_data_assoc, ...
9 obs_rel_pos, ctrl_signal] = mk_linear_slam(...
10 'nlandmarks', 6, 'T', 12, 'ctrl', 'leftright', 'data-assoc', 'cycle');
11
12 figure(1); clf
13 hold on
14 for i=1:nlandmarks
15 %text(true_landmark_pos(1,i), true_landmark_pos(2,i), sprintf('L%d',i));
16 plot(true_landmark_pos(1,i), true_landmark_pos(2,i), '*')
17 end
18 hold off
19
20
21 [x, V] = kalman_filter(obs_rel_pos, A, C, Qbig, Rbig, init_x, init_V, ...
22 'model', true_data_assoc, 'u', ctrl_signal, 'B', B);
23
24 est_robot_pos = x(robot_block, :);
25 est_robot_pos_cov = V(robot_block, robot_block, :);
26
27 for i=1:nlandmarks
28 bi = landmark_block(:,i);
29 est_landmark_pos(:,i) = x(bi, T);
30 est_landmark_pos_cov(:,:,i) = V(bi, bi, T);
31 end
32
33
34 if 0
35 figure(1); hold on
36 for i=1:nlandmarks
37 h=plotgauss2d(est_landmark_pos(:,i), est_landmark_pos_cov(:,:,i));
38 set(h, 'color', 'r')
39 end
40 hold off
41
42 hold on
43 for t=1:T
44 h=plotgauss2d(est_robot_pos(:,t), est_robot_pos_cov(:,:,t));
45 set(h,'color','r')
46 h=text(est_robot_pos(1,t), est_robot_pos(2,2), sprintf('R%d', t));
47 set(h,'color','r')
48 end
49 hold off
50 end
51
52
53 P = zeros(size(V));
54 for t=1:T
55 P(:,:,t) = inv(V(:,:,t));
56 end
57
58 if 0
59 figure(2)
60 for t=1:T
61 subplot(T/2,2,t)
62 imagesc(P(1:2:end,1:2:end, t))
63 colorbar
64 end
65 else
66 figure(2)
67 for t=1:T
68 subplot(T/2,2,t)
69 imagesc(V(1:2:end,1:2:end, t))
70 colorbar
71 end
72 end
73
74 % marginalize out robot position and then check structure
75 bi = landmark_block(:);
76 V = V(bi,bi,T);
77 P = inv(V);
78 P(1:2:end,1:2:end)