-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
61 lines (54 loc) · 1.58 KB
/
main.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
% Used for Motion Planning for Mobile Robots
% Thanks to HKUST ELEC 5660
close all; clear all; clc;
addpath('A_star')
% Environment map in 2D space
pos = 30;
xStart = 1.0;
yStart = 1.0;
xTarget = pos;
yTarget = pos;
MAX_X = pos;
MAX_Y = pos;
map = obstacle_map(xStart, yStart, xTarget, yTarget, MAX_X, MAX_Y);
% map = load('map_to_be_improved.mat').map;
% Waypoint Generator Using the A*
% W_h = [0 1 0.5 0 1 0.5];
% W_cost = [1 1 1 2 2 2];
% for i = 1:size(W_h,2)
% time_start = clock();
% [path,OPEN] = A_star_search(map, MAX_X,MAX_Y,W_h(i),W_cost(i));
% time_elapsed = etime(clock,time_start);
% fig = figure(i);
% title(['W_h:' num2str(W_h(i)) ' ' 'W_c:' num2str(W_cost(i)) ' ' num2str(time_elapsed)])
% visualize_map(map, path, OPEN);
% end
% run 10 times to obtain mean time elapsed
for i = 1:10
time_start = clock();
[path,OPEN] = A_star_search(map, MAX_X,MAX_Y,1,1.1);
time_elapsed(i) = etime(clock,time_start);
end
visualize_map(map, path, OPEN);
title(['A* time elapsed: ' num2str(mean(time_elapsed))])
% fig = figure();
% title(num2str(time_elapsed))
% plot(time_elapsed)
% mean(time_elapsed)
% max(time_elapsed)
for i = 1:10
time_start = clock();
[path,OPEN] = A_star_search(map, MAX_X,MAX_Y,0,1);
time_elapsed(i) = etime(clock,time_start);
end
figure()
visualize_map(map, path, OPEN);
title(['Dijikstra time elapsed: ' num2str(mean(time_elapsed))])
% fig = figure();
% title(num2str(time_elapsed))
% plot(time_elapsed)
% mean(time_elapsed)
% max(time_elapsed)
% visualize the 2D grid map
% save map
% save('Data/map.mat', 'map', 'MAX_X', 'MAX_Y');