forked from LazyFalcon/D_star_PathPlanning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASInit.m
61 lines (50 loc) · 1.54 KB
/
ASInit.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
function state = ASInit(startPos, endPos, map, scalling)
%% generate shape pattern
radius = 10/scalling;
mat = zeros(radius*2,radius*2);
dista = @(a,b) sqrt(a*a+b*b);
shapePattern = [];
for x = 1:1:2*radius
for y =1:1:2*radius
if dista(x-radius-0.5,y-radius-0.5) > radius -1 && dista(x-radius-0.5,y-radius-0.5) < radius
mat(x,y) = 1;
shapePattern = [shapePattern; floor(x-radius) floor(y-radius) 0 0];
end
end
end
neighbours = [
0 1 0 0;
-1 0 0 0;
0 -1 0 0;
1 1 0 0;
-1 -1 0 0;
1 0 0 0;
1 -1 0 0;
-1 1 0 0;
]';
%% prepare all data
state.map = map;
state.startPos = [startPos(2:-1:1); 0; 0];
state.endPos = [endPos(2:-1:1); 0; 0];
state.pattern = shapePattern';
state.ucc = neighbours;
state.height = ceil(length(state.map(:,1)));
state.width = ceil(length(state.map(1,:)));
state.graph = zeros(state.height, state.width,1);
state.graph(:,:,1) = -1;
% set comparator
state.comparator = pcmp;
state.stack = java.util.PriorityQueue(180247, state.comparator);
%insert first node
setg(state.startPos, 0);
state.startPos(3:4) = [heur(state.startPos); 0];
add(state.stack, state.startPos);
%%
function out = heur(s)
s = state.endPos - s;
out = sqrt(s(1)^2 + s(2)^2);
end
function setg(s, val)
state.graph(s(1), s(2)) = val;
end
end