-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (55 loc) · 1.93 KB
/
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
64
65
66
67
68
69
70
71
72
73
74
75
76
from robot_driving_states import RobotController
from rrt import *
import time
def main():
path_res = 0.05
map = grid_occ.GridOccupancyMap(low=(-2, 0), high=(2, 4), res=path_res)
map.populate()
robot = robot_models.PointMassModel(ctrl_range=[-path_res, path_res]) #
rrt = RRT(
start=[0, 0],
goal=[0, 2.3],
robot_model=robot,
map=map,
expand_dis=1.0,
path_resolution=path_res,
)
show_animation = False
metadata = dict(title="RRT Test")
writer = FFMpegWriter(fps=15, metadata=metadata)
fig = plt.figure()
path = rrt.planning(animation=show_animation, writer=writer)
with writer.saving(fig, "rrt_test.mp4", 100):
if path is None:
print("Cannot find path")
else:
print("found path!!")
# Draw final path
if show_animation:
rrt.draw_graph()
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
# write the node number
plt.grid(True)
plt.pause(0.01) # Need for Mac
plt.show()
writer.grab_frame()
rrt.draw_graph()
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
pathPrint = np.flip(np.array(path)) # might need np.array here
for i in range(0, len(pathPrint)):
plt.text(pathPrint[i][1], pathPrint[i][0], str(
i), color="blue", fontsize=10)
plt.grid(True)
plt.pause(0.01) # Need for Mac
plt.savefig("map_with_path.png")
# Use github to push the image
r = RobotController(path)
maxTime = 60 + time.perf_counter()
ctime = time.perf_counter()
while (maxTime > time.perf_counter()):
# only update every 0.1 seconds
if ctime + 0.001 < time.perf_counter():
r.update()
ctime = time.perf_counter()
if __name__ == '__main__':
main()