-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRRT_Main.py
63 lines (51 loc) · 2.36 KB
/
RRT_Main.py
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
# Main and helper function
from re import A
from PIL import Image
import numpy as np
from RRT import RRT
import time
import matplotlib.pyplot as plt
def load_map(file_path, resolution_scale):
''' Load map from an image and return a 2D binary numpy array
where 0 represents obstacles and 1 represents free space
'''
# Load the image with grayscale
img = Image.open(file_path).convert('L')
# Rescale the image
size_x, size_y = img.size
new_x, new_y = int(size_x*resolution_scale), int(size_y*resolution_scale)
img = img.resize((new_x, new_y), Image.ANTIALIAS)
map_array = np.asarray(img, dtype='uint8')
# Get bianry image
threshold = 127
map_array = 1 * (map_array > threshold)
# Result 2D numpy array
return map_array
if __name__ == "__main__":
'''
#Example one
start = (70,275)
goal = (300,445)
map_array = load_map("D:\Educational\A WPI Assignments and Materials\Motion Planning\Project\Robot-Motion-Planning-for-an-optimal-Watchman-Route\Colored Polygons\GS10.jpeg",1.5)
'''
'''
start = (50,100)
goal = (150,430)
map_array = load_map("D:\Educational\A WPI Assignments and Materials\Motion Planning\Project\Robot-Motion-Planning-for-an-optimal-Watchman-Route\Colored Polygons\GS5.jpeg",1)
# [(12.004002564611195, 2.6748405823643653), (1.8319882514537322, 8.381256634659618), (4.475299130777356, 8.0519414026726), (3.447646309306825, 6.967555834038162)]
points = [(120.04002564611195, 26.748405823643653), (1.8319882514537322, 8.381256634659618), (4.475299130777356, 8.0519414026726), (3.447646309306825, 6.967555834038162)]
points = [(88,134),(133,173),(99,191),(261,377),(88,134)] # 4 guards polygon - zigzag
points = [(105,58),(180,476)] # mega one
points = [(63,159),(121,220),(273,324),(63,159)]
print(points)
points = [(70,275),(300,445),(70,275)]'''
points = [(147,130),(228,90),(265,322),(125,265),(147,130)] # Polygon with holes
map_array = load_map("D:\Educational\A WPI Assignments and Materials\Motion Planning\Project\Results\Colored Polygons\PH_BW1.png",1)
for i in range(len(points)-1):
start = points[i]
goal = points[i+1]
RRT_planner = RRT(map_array, start, goal)
# RRT_planner.RRT(n_pts=4000)
# RRT_planner.RRT_star(n_pts=4000)
RRT_planner.informed_RRT_star(n_pts=5000)
plt.show()