-
Notifications
You must be signed in to change notification settings - Fork 0
/
partB.py
208 lines (140 loc) · 5.37 KB
/
partB.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
"""
This file provides methods for Part B
"""
from grid import Grid
from path import Astar
from navigate import Navigation
import numpy as np
def question_9():
print("----------------------")
print("Results for question 9")
print("Driving paths from 7")
print("----------------------")
# creat grid with cell size = 0.1
cell_size = 0.1
grid = Grid(cell_size)
# load landmarks into grid
landmarks = grid.get_landmarks()
# create paths for A, B, C in question 7 on small grid size
astar_online_A = Astar([2.45, -3.55], [0.95, -1.55], grid)
astar_online_B = Astar([4.95, -0.05], [2.45, 0.25], grid)
astar_online_C = Astar([-0.55, 1.45], [1.95, 3.95], grid)
# run online implementation
astar_online_A.online()
astar_online_A.get_path()
astar_online_B.online()
astar_online_B.get_path()
astar_online_C.online()
astar_online_C.get_path()
# init pose
pose_A = np.array([2.45, -3.55, -np.pi/2])
pose_B = np.array([4.95, -0.05, -np.pi/2])
pose_C = np.array([-0.55, 1.45, -np.pi/2])
# init controls
u = np.array([0, 0])
# drive the paths
print("Path A [2.45, -3.55], [0.95, -1.55]")
nav_A = Navigation(grid, astar_online_A, False)
nav_A.drive_paths(astar_online_A.path_world, pose_A, u)
print("Path B [4.95, -0.05], [2.45, 0.25]")
nav_B = Navigation(grid, astar_online_B, False)
nav_B.drive_paths(astar_online_B.path_world, pose_B, u)
print("Path C [-0.55, 1.45], [1.95, 3.95]")
nav_C = Navigation(grid, astar_online_C, False)
nav_C.drive_paths(astar_online_C.path_world, pose_C, u)
def question_10():
print("----------------------")
print("Results for question 10")
print("Planning while driving paths from 7")
print("----------------------")
# creat grid with cell size = 0.1
cell_size = 0.1
grid = Grid(cell_size)
# load landmarks into grid
landmarks = grid.get_landmarks()
# create paths for A, B, C in question 7 on small grid size
astar_online_A = Astar([2.45, -3.55], [0.95, -1.55], grid)
astar_online_B = Astar([4.95, -0.05], [2.45, 0.25], grid)
astar_online_C = Astar([-0.55, 1.45], [1.95, 3.95], grid)
# init pose
pose_A = np.array([2.45, -3.55, -np.pi/2])
pose_B = np.array([4.95, -0.05, -np.pi/2])
pose_C = np.array([-0.55, 1.45, -np.pi/2])
# init controls
u = np.array([0, 0])
# plan and drive
print("Path A [2.45, -3.55], [0.95, -1.55]")
nav_A = Navigation(grid, astar_online_A, True)
nav_A.plan_drive(pose_A, u)
print("Path B [4.95, -0.05], [2.45, 0.25]")
nav_B = Navigation(grid, astar_online_B, True)
nav_B.plan_drive(pose_B, u)
print("Path C [-0.55, 1.45], [1.95, 3.95]")
nav_C = Navigation(grid, astar_online_C, True)
nav_C.plan_drive(pose_C, u)
def question_11():
question_11_fine()
question_11_coarse()
def question_11_fine():
print("----------------------")
print("Results for question 11")
print("Planning while driving paths from 3")
print("Fine Grid")
print("----------------------")
# creat grid with cell size = 0.1
cell_size = 0.1
grid_small = Grid(cell_size)
# load landmarks into grid
landmarks = grid_small.get_landmarks()
# init pose
pose_A = np.array([0.5, -1.5, -np.pi/2])
pose_B = np.array([4.5, 3.5, -np.pi/2])
pose_C = np.array([-0.5, 5.5, -np.pi/2])
# init controls
u = np.array([0, 0])
# create paths for A, B, C in question 3 on small grid size
astar_A_fine = Astar([0.5, -1.5], [0.5, 1.5], grid_small)
astar_B_fine = Astar([4.5, 3.5], [4.5, -1.5], grid_small)
astar_C_fine = Astar([-0.5, 5.5], [1.5, -3.5], grid_small)
# plan and drive
print("Path A [0.5, -1.5], [0.5, 1.5]")
nav_A_fine = Navigation(grid_small, astar_A_fine, True)
nav_A_fine.plan_drive(pose_A, u)
print("Path B [4.5, 3.5], [4.5, -1.5]")
nav_B_fine = Navigation(grid_small, astar_B_fine, True)
nav_B_fine.plan_drive(pose_B, u)
print("Path C [-0.5, 5.5], [1.5, -3.5]")
nav_C_fine = Navigation(grid_small, astar_C_fine, True)
nav_C_fine.plan_drive(pose_C, u)
def question_11_coarse():
print("----------------------")
print("Results for question 11")
print("Planning while driving paths from 3")
print("Coarse Grid")
print("----------------------")
# creat grid with cell size = 0.1
cell_size = 1
grid_large = Grid(cell_size)
# load landmarks into grid
landmarks = grid_large.get_landmarks()
# init pose
pose_A = np.array([0.5, -1.5, -np.pi/2])
pose_B = np.array([4.5, 3.5, -np.pi/2])
pose_C = np.array([-0.5, 5.5, -np.pi/2])
# init controls
u = np.array([0, 0])
# create paths for A, B, C in question 3 on large grid size
astar_A_coarse = Astar([0.5, -1.5], [0.5, 1.5], grid_large)
astar_B_coarse = Astar([4.5, 3.5], [4.5, -1.5], grid_large)
astar_C_coarse = Astar([-0.5, 5.5], [1.5, -3.5], grid_large)
# plan and drive
print("Path A [0.5, -1.5], [0.5, 1.5]")
nav_A_coarse = Navigation(grid_large, astar_A_coarse, True)
nav_A_coarse.plan_drive(pose_A, u)
print("Path B [4.5, 3.5], [4.5, -1.5]")
nav_B_coarse = Navigation(grid_large, astar_B_coarse, True)
nav_B_coarse.plan_drive(pose_B, u)
print("Path C [-0.5, 5.5], [1.5, -3.5]")
nav_C_coarse = Navigation(grid_large, astar_C_coarse, True)
nav_C_coarse.plan_drive(pose_C, u)
#