-
Notifications
You must be signed in to change notification settings - Fork 20
/
extendMap.m
72 lines (68 loc) · 3.82 KB
/
extendMap.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
63
64
65
66
67
68
69
70
71
function [particle, atRow, atCol]= extendMap(particle, gridlen)
%If current position is out of the exist grid map, extend the map
extendStep = 20; %How many rows/cols be added every time.
[atRow, atCol] = getCurrentMapIndex(particle, gridlen); %Get the idx of the vehicle in the current grid map according to its current position
[curRows, curCols] = size(particle.gridmap);
rowBlock = zeros(extendStep, curCols);
colBlock = zeros(curRows + extendStep, extendStep);
% Add matrix block to the grid map at a propriate position (depend on the vehicle direction) every time.
if (atRow > curRows)
if (atCol >= particle.preIdxinMap(2))
particle.gridmap = [particle.gridmap;rowBlock];
particle.gridmap = [particle.gridmap colBlock];
else
particle.gridmap = [particle.gridmap;rowBlock];
particle.gridmap = [colBlock particle.gridmap];
particle.originIdx(2) = particle.originIdx(2) + extendStep;
particle.preIdxinMap(2) = particle.preIdxinMap(2) + extendStep;
atCol = atCol + extendStep;
end
elseif (atRow <= 0)
if (atCol >= particle.preIdxinMap(2))
particle.gridmap = [rowBlock;particle.gridmap];
particle.gridmap = [particle.gridmap colBlock];
particle.originIdx(1) = particle.originIdx(1) + extendStep;
particle.preIdxinMap(1) = particle.preIdxinMap(1) + extendStep;
atRow = atRow + extendStep;
else
particle.gridmap = [rowBlock;particle.gridmap];
particle.gridmap = [colBlock particle.gridmap];
particle.originIdx(1) = particle.originIdx(1) + extendStep;
particle.originIdx(2) = particle.originIdx(2) + extendStep;
particle.preIdxinMap(1) = particle.preIdxinMap(1) + extendStep;
particle.preIdxinMap(2) = particle.preIdxinMap(2) + extendStep;
atCol = atCol + extendStep;
atRow = atRow + extendStep;
end
else
if (atCol > curCols)
if (atRow >= particle.preIdxinMap(1))
particle.gridmap = [particle.gridmap;rowBlock];
particle.gridmap = [particle.gridmap colBlock];
else
particle.gridmap = [rowBlock;particle.gridmap];
particle.gridmap = [particle.gridmap colBlock];
particle.originIdx(1) = particle.originIdx(1) + extendStep;
particle.preIdxinMap(1) = particle.preIdxinMap(1) + extendStep;
atRow = atRow + extendStep;
end
elseif (atCol <= 0)
if (atRow >= particle.preIdxinMap(1))
particle.gridmap = [particle.gridmap;rowBlock];
particle.gridmap = [colBlock particle.gridmap];
particle.originIdx(2) = particle.originIdx(2) + extendStep;
particle.preIdxinMap(2) = particle.preIdxinMap(2) + extendStep;
atCol = atCol + extendStep;
else
particle.gridmap = [rowBlock;particle.gridmap];
particle.gridmap = [colBlock particle.gridmap];
particle.originIdx(1) = particle.originIdx(1) + extendStep;
particle.originIdx(2) = particle.originIdx(2) + extendStep;
particle.preIdxinMap(1) = particle.preIdxinMap(1) + extendStep;
particle.preIdxinMap(2) = particle.preIdxinMap(2) + extendStep;
atRow = atRow + extendStep;
atCol = atCol + extendStep;
end
end
end
end