-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportanceFactor.m
63 lines (59 loc) · 1.8 KB
/
importanceFactor.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
function [particleWeight] = importanceFactor(z_t, localMap, particle)
% Takes a observarion and local map and returns how well its explained.
%Obs is full grid, but -1 where there are no updates
correleationMap = ones(particle.height, particle.width);
truePos = 0.9;
trueNeg = 0.95;
x = particle.robotPose(1);
y = particle.robotPose(2);
theta = particle.robotPose(3);
% for j = 1:particle.height
% for k = 1:particle.width
if theta == 1
xObs = x + particle.observationXVector;
yObs = y + particle.observationYVector;
elseif theta == 2
xObs = x + particle.observationYVector;
yObs = y + particle.observationXVector;
elseif theta == 3
xObs = x + particle.observationXVector;
yObs = y - particle.observationYVector;
else
xObs = x - particle.observationYVector;
yObs = y + particle.observationXVector;
end
for index = 1:length(xObs)
j = yObs(index);
k = xObs(index);
if ( j <= 0 || j > particle.height || k <= 0 || k > particle.width)
continue;
end
if (z_t(j,k) == -1 )
continue;
end
if z_t(j,k) == 1 && localMap(j,k) == 1
correleationMap(j,k) = truePos;
elseif z_t(j,k) == 0 && localMap(j,k) == 1
correleationMap(j,k) = 1-truePos;
elseif z_t(j,k) == 0 && localMap(j,k) == 0
correleationMap(j,k) = trueNeg;
elseif z_t(j,k) == 1 && localMap(j,k) == 0
correleationMap(j,k) = 1-trueNeg;
end
end
weight = 1;
% for j = 1:particle.height
% for k = 1:particle.width
for j = 1:length(xObs)
row = yObs(j);
col = xObs(j);
if row <= 0 || row > particle.width
continue;
end
if col <= 0 || col > particle.height
continue;
end
weight = weight*correleationMap(row,col);
end
particleWeight = weight;
end