annotate toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/SLAM/slam_kf.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 % Plot how precision matrix changes over time for KF solution
Daniel@0 2
Daniel@0 3 seed = 0;
Daniel@0 4 rand('state', seed);
Daniel@0 5 randn('state', seed);
Daniel@0 6
Daniel@0 7 [A,B,C,Q,R,Qbig,Rbig,init_x,init_V,robot_block,landmark_block,...
Daniel@0 8 true_landmark_pos, true_robot_pos, true_data_assoc, ...
Daniel@0 9 obs_rel_pos, ctrl_signal] = mk_linear_slam(...
Daniel@0 10 'nlandmarks', 6, 'T', 12, 'ctrl', 'leftright', 'data-assoc', 'cycle');
Daniel@0 11
Daniel@0 12 figure(1); clf
Daniel@0 13 hold on
Daniel@0 14 for i=1:nlandmarks
Daniel@0 15 %text(true_landmark_pos(1,i), true_landmark_pos(2,i), sprintf('L%d',i));
Daniel@0 16 plot(true_landmark_pos(1,i), true_landmark_pos(2,i), '*')
Daniel@0 17 end
Daniel@0 18 hold off
Daniel@0 19
Daniel@0 20
Daniel@0 21 [x, V] = kalman_filter(obs_rel_pos, A, C, Qbig, Rbig, init_x, init_V, ...
Daniel@0 22 'model', true_data_assoc, 'u', ctrl_signal, 'B', B);
Daniel@0 23
Daniel@0 24 est_robot_pos = x(robot_block, :);
Daniel@0 25 est_robot_pos_cov = V(robot_block, robot_block, :);
Daniel@0 26
Daniel@0 27 for i=1:nlandmarks
Daniel@0 28 bi = landmark_block(:,i);
Daniel@0 29 est_landmark_pos(:,i) = x(bi, T);
Daniel@0 30 est_landmark_pos_cov(:,:,i) = V(bi, bi, T);
Daniel@0 31 end
Daniel@0 32
Daniel@0 33
Daniel@0 34 if 0
Daniel@0 35 figure(1); hold on
Daniel@0 36 for i=1:nlandmarks
Daniel@0 37 h=plotgauss2d(est_landmark_pos(:,i), est_landmark_pos_cov(:,:,i));
Daniel@0 38 set(h, 'color', 'r')
Daniel@0 39 end
Daniel@0 40 hold off
Daniel@0 41
Daniel@0 42 hold on
Daniel@0 43 for t=1:T
Daniel@0 44 h=plotgauss2d(est_robot_pos(:,t), est_robot_pos_cov(:,:,t));
Daniel@0 45 set(h,'color','r')
Daniel@0 46 h=text(est_robot_pos(1,t), est_robot_pos(2,2), sprintf('R%d', t));
Daniel@0 47 set(h,'color','r')
Daniel@0 48 end
Daniel@0 49 hold off
Daniel@0 50 end
Daniel@0 51
Daniel@0 52
Daniel@0 53 P = zeros(size(V));
Daniel@0 54 for t=1:T
Daniel@0 55 P(:,:,t) = inv(V(:,:,t));
Daniel@0 56 end
Daniel@0 57
Daniel@0 58 if 0
Daniel@0 59 figure(2)
Daniel@0 60 for t=1:T
Daniel@0 61 subplot(T/2,2,t)
Daniel@0 62 imagesc(P(1:2:end,1:2:end, t))
Daniel@0 63 colorbar
Daniel@0 64 end
Daniel@0 65 else
Daniel@0 66 figure(2)
Daniel@0 67 for t=1:T
Daniel@0 68 subplot(T/2,2,t)
Daniel@0 69 imagesc(V(1:2:end,1:2:end, t))
Daniel@0 70 colorbar
Daniel@0 71 end
Daniel@0 72 end
Daniel@0 73
Daniel@0 74 % marginalize out robot position and then check structure
Daniel@0 75 bi = landmark_block(:);
Daniel@0 76 V = V(bi,bi,T);
Daniel@0 77 P = inv(V);
Daniel@0 78 P(1:2:end,1:2:end)