-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_rrt.py
59 lines (40 loc) · 1.48 KB
/
test_rrt.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
from utils.rtt import RRT
import numpy as np
import cv2
# Map
x = np.array([3, 3, 3, 4, 4, 4, 5, 5, 5, 3, 3, 3, 4, 4, 4, 5, 5, 5, 3, 3, 3, 4, 4, 4, 5, 5, 5, 7, 8, 9, 10, 11, 12, 12, 13, 13])
y = np.array([4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 6, 6, 6, 7, 7, 7])
point_cloud2d = np.c_[x.reshape(-1), y.reshape(-1)]*50
#print (point_cloud2d.shape)
start= (np.random.randint(310),np.random.randint(310))
pic = np.zeros((480,640,3))
clrrt = RRT(GOAL_STOP_RADIUS=40,LINE_SIZE=[6,6],COLL_DIST=40, MAP=point_cloud2d)
while True:
stop = (np.random.randint(610),np.random.randint(310))
pic = np.zeros((480,640,3))
clrrt.rtt(start,stop,2000)
points = clrrt.get_points()
path = clrrt.get_path()
# draw obstacles
for i in point_cloud2d:
cv2.circle(pic,(i[0],i[1]),15,[0,0,255],-1)
# draw lines between points generated
for p in points:
p1 = p['prev']
p2 = p['actual']
if p1 is None:
continue
cv2.line(pic,(int(p1[0]),int(p1[1])),(int(p2[0]),int(p2[1])),(0,255,0),1)
# start point / goal
cv2.circle(pic,start,7,[0,255,255],-1)
cv2.circle(pic,stop,7,[0,255,255],-1)
cnt = 0
while len(path) > cnt:
p = path[cnt].ravel()
x = int(p[0])
y = int(p[1])
cv2.circle(pic,(int(p[0]),int(p[1])),5,[255,0,100],-1)
cnt +=1
cv2.imshow("rrt",pic)
if cv2.waitKey(1000) == 27:
break