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