-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcoverage_path_planner.py
More file actions
292 lines (209 loc) · 10.8 KB
/
coverage_path_planner.py
File metadata and controls
292 lines (209 loc) · 10.8 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#Global imports
import math
from enum import Enum
from shapely.geometry import LineString
#Local modules
from pkg.time_keeping import time_keeping as tk
from pkg.poly_operations.hard_coded_lib import polygon_library
from pkg.poly_operations.others import adjacency
from pkg.decompositions.greedy import greedy_decompose
from pkg.decompositions.min_alt import min_alt_decompose
from pkg.discritizers.line import min_alt_discrt
from pkg.discritizers.point import point_discrt
from pkg.discritizers import get_mapping
from pkg.costs import dubins_cost
from pkg.gtsp.GLKH import solver
from pkg.visuals.static import coverage_plot as splot
from pkg.analysis import tour_length
from pkg.analysis import tour_area
from pkg.poly_operations.others import operations
class Robot:
"""
Robot class cotaining specs
"""
def __init__(self, footprint_width, dynamics):
self.footprint_width = footprint_width
self.dynamics = dynamics
GLKH_LOCATION = "/home/sbochkar/misc/GLKH-1.0/"
def coverage_path_planner(map_num, robot, method):
"""
Wrapper for all avaialble path planners
:param map_num: Id of a map
:param method: Method to use for planning
:param robot: RObot specs
:return path: Coverage path
"""
# Generating a polygon
print("[%18s] Generating a polygon."%tk.current_time())
P = polygon_library.polygon_generator(map_num)
print("[%18s] Polygon generated."%tk.current_time())
width = 2*robot.footprint_width
if method == 0: # Greed convex decomposion method
print("[%18s] Invoking greedy decomposition."%tk.current_time())
decomposition = greedy_decompose.decompose(P)
print("[%18s] Finished greedy decomposition."%tk.current_time())
print("[%18s] Forming an adjacency matrix for polygons."%tk.current_time())
adjacency_matrix = adjacency.get_adjacency_as_matrix(decomposition)
print("[%18s] Adjacency matrix complete."%tk.current_time())
print("[%18s] Populating the free space with segments."%tk.current_time())
segments = min_alt_discrt.discritize_set(decomposition, width)
print("[%18s] Finished generating segments."%tk.current_time())
print("[%18s] Obtain a mapping between nodes and segments."%tk.current_time())
mapping = get_mapping.get_mapping(segments)
print("[%18s] Obtained mapping."%tk.current_time())
print("[%18s] Started computing the cost matrix."%tk.current_time())
cost_matrix, cluster_list = dubins_cost.compute_costs(P, mapping, width/2)
print("[%18s] Finished computing the cost matrix."%tk.current_time())
print("[%18s] Generating and launching GTSP instance."%tk.current_time())
solver.solve("cpp_test", GLKH_LOCATION, cost_matrix, cluster_list)
print("[%18s] Sovled GTSP instance."%tk.current_time())
print("[%18s] Reading the results."%tk.current_time())
tour = solver.read_tour("cpp_test")
print("[%18s] Plotting the results."%tk.current_time())
ax = splot.init_axis()
print("[%18s] Plotting decomposition."%tk.current_time())
splot.plot_decomposition(ax, decomposition, adjacency_matrix, P)
print("[%18s] Plotting sampling."%tk.current_time())
splot.plot_samples(ax, segments)
print("[%18s] Plotting path."%tk.current_time())
#splot.plot_tour(ax, tour, lines, dict_mapping)
splot.plot_tour_dubins(ax, tour, mapping, width/2)
print("Tour Length %2f."%tour_length.length(tour, segments, cost_matrix))
print("Polygon Area: %2f"%tour_area.polygon_area(P))
print("Area covered: %2f"%tour_area.covered_area(tour, mapping, width/2))
splot.display()
elif method == 1:
print("[%18s] Invoking min_alt decomposition."%tk.current_time())
decomposition = min_alt_decompose.decompose(P)
print("[%18s] Finished min_alt decomposition."%tk.current_time())
# print decomposition
print("[%18s] Forming an adjacency matrix for polygons."%tk.current_time())
adjacency_matrix = adjacency.get_adjacency_as_matrix(decomposition)
print("[%18s] Adjacency matrix complete."%tk.current_time())
print("[%18s] Populating the free space with segments."%tk.current_time())
segments = min_alt_discrt.discritize_set(decomposition, width)
print("[%18s] Finished generating segments."%tk.current_time())
print("[%18s] Obtain a mapping between nodes and segments."%tk.current_time())
mapping = get_mapping.get_mapping(segments)
print("[%18s] Obtained mapping."%tk.current_time())
print("[%18s] Started computing the cost matrix."%tk.current_time())
cost_matrix, cluster_list = dubins_cost.compute_costs(P, mapping, width/2)
print("[%18s] Finished computing the cost matrix."%tk.current_time())
print("[%18s] Generating and launching GTSP instance."%tk.current_time())
solver.solve("cpp_test", GLKH_LOCATION, cost_matrix, cluster_list)
print("[%18s] Sovled GTSP instance."%tk.current_time())
print("[%18s] Reading the results."%tk.current_time())
tour = solver.read_tour("cpp_test")
print("[%18s] Plotting the results."%tk.current_time())
ax = splot.init_axis()
print("[%18s] Plotting decomposition."%tk.current_time())
splot.plot_decomposition(ax, decomposition, adjacency_matrix)
print("[%18s] Plotting sampling."%tk.current_time())
splot.plot_samples(ax, segments)
print("[%18s] Plotting path."%tk.current_time())
#splot.plot_tour(ax, tour, lines, dict_mapping)
splot.plot_tour_dubins(ax, tour, mapping, width/2)
print("Tour Length %2f."%tour_length.length(tour, segments, cost_matrix))
splot.display()
elif method == 2:
print("[%18s] Populating the free space with segments."%tk.current_time())
segments = point_discrt.discritize_polygon(P, width/2)
print("[%18s] Finished generating segments."%tk.current_time())
print("[%18s] Obtain a mapping between nodes and segments."%tk.current_time())
mapping = get_mapping.get_mapping(segments)
print("[%18s] Obtained mapping."%tk.current_time())
print("[%18s] Started computing the cost matrix."%tk.current_time())
# cost_matrix, cluster_list = dubins_cost.compute_costs(P, mapping, width/2)
print("[%18s] Finished computing the cost matrix."%tk.current_time())
print("[%18s] Generating and launching GTSP instance."%tk.current_time())
# solver.solve("gtsp_13_coverage", GLKH_LOCATION, cost_matrix, cluster_list)
print("[%18s] Sovled GTSP instance."%tk.current_time())
print("[%18s] Reading the results."%tk.current_time())
tour = solver.read_tour("gtsp_13_coverage")
print("[%18s] Plotting the results."%tk.current_time())
ax = splot.init_axis()
print("[%18s] Plotting decomposition."%tk.current_time())
splot.plot_polygon_outline(ax, P)
print("[%18s] Plotting sampling."%tk.current_time())
splot.plot_samples(ax, segments)
print("[%18s] Plotting path."%tk.current_time())
#splot.plot_tour(ax, tour, lines, dict_mapping)
splot.plot_tour_dubins(ax, tour, mapping, width/2)
# print("Tour Length %2f."%tour_length.length(tour, segments, cost_matrix))
splot.display()
print("Polygon Area: %2f"%tour_area.polygon_area(P))
print("Area covered: %2f"%tour_area.covered_area(tour, mapping, width/2))
elif method == 3:
print("[%18s] Invoking min_alt decomposition."%tk.current_time())
# decomposition = [
# [[(0.0, 0.0), (10.0, 0.0),(1.0, 1.0)],[]],
# [[(1.0, 1.0), (10.0, 0.0),(9.0, 1.0)],[]],
# [[(10.0, 0.0), (10.0, 10.0),(9.0, 9.0)],[]],
# [[(10.0, 0.0), (9.0, 9.0),(9.0, 1.0)],[]],
# [[(10.0, 10.0),(9.0, 9.0),(1.0, 9.0)],[]],
# [[(1.0, 9.0), (0.0, 10.0),(10.0, 10.0)],[]],
# [[(0.0, 0.0), (1.0, 1.0),(0.0, 10.0)], []],
# [[(0.0, 10.0), (1.0, 1.0),(1.0, 9.0)], []]
# ]
decomposition = greedy_decompose.decompose(P)
print("[%18s] Finished min_alt decomposition."%tk.current_time())
print("[%18s] Forming an adjacency matrix for polygons."%tk.current_time())
adjacency_matrix = adjacency.get_adjacency_as_matrix(decomposition)
print("[%18s] Adjacency matrix complete."%tk.current_time())
print("[%18s] Forming an adjacency matrix for polygons."%tk.current_time())
decomposition = min_alt_decompose.reoptimize(P, decomposition, adjacency_matrix)
print("[%18s] Adjacency matrix complete."%tk.current_time())
print("[%18s] Forming an adjacency matrix for polygons."%tk.current_time())
adjacency_matrix = adjacency.get_adjacency_as_matrix(decomposition)
print("[%18s] Adjacency matrix complete."%tk.current_time())
print("[%18s] Populating the free space with segments."%tk.current_time())
segments = min_alt_discrt.discritize_set(decomposition, width)
print("[%18s] Finished generating segments."%tk.current_time())
print("[%18s] Obtain a mapping between nodes and segments."%tk.current_time())
mapping = get_mapping.get_mapping(segments)
print("[%18s] Obtained mapping."%tk.current_time())
print("[%18s] Started computing the cost matrix."%tk.current_time())
cost_matrix, cluster_list = dubins_cost.compute_costs(P, mapping, width/2)
print("[%18s] Finished computing the cost matrix."%tk.current_time())
print("[%18s] Generating and launching GTSP instance."%tk.current_time())
solver.solve("cpp_test", GLKH_LOCATION, cost_matrix, cluster_list)
print("[%18s] Sovled GTSP instance."%tk.current_time())
print("[%18s] Reading the results."%tk.current_time())
tour = solver.read_tour("cpp_test")
print("[%18s] Plotting the results."%tk.current_time())
ax = splot.init_axis()
print("[%18s] Plotting decomposition."%tk.current_time())
splot.plot_decomposition(ax, decomposition, adjacency_matrix, P)
# splot.display()
print("[%18s] Plotting sampling."%tk.current_time())
splot.plot_samples(ax, segments)
print("[%18s] Plotting path."%tk.current_time())
#splot.plot_tour(ax, tour, lines, dict_mapping)
splot.plot_tour_dubins(ax, tour, mapping, width/2)
print("Tour Length %2f."%tour_length.length(tour, segments, cost_matrix))
splot.display()
print("Polygon Area: %2f"%tour_area.polygon_area(P))
print("Area covered: %2f"%tour_area.covered_area(tour, mapping, width/2))
elif method == 4:
print("[%18s] Populating the free space with segments."%tk.current_time())
segments = point_discrt.discritize_polygon(P, width/2)
print("[%18s] Finished generating segments."%tk.current_time())
print("[%18s] Obtain a mapping between nodes and segments."%tk.current_time())
mapping = get_mapping.get_mapping(segments)
print("[%18s] Obtained mapping."%tk.current_time())
print("[%18s] Reading the results."%tk.current_time())
tour = solver.read_tour("cpp_test")
print("[%18s] Plotting the results."%tk.current_time())
ax = splot.init_axis()
print("[%18s] Plotting decomposition."%tk.current_time())
splot.plot_polygon_outline(ax, P)
print("[%18s] Plotting sampling."%tk.current_time())
splot.plot_samples(ax, segments)
print("[%18s] Plotting path."%tk.current_time())
#splot.plot_tour(ax, tour, lines, dict_mapping)
splot.plot_tour_dubins(ax, tour, mapping, width/2)
#print("Tour Length %2f."%tour_length.length(tour, segments, cost_matrix))
splot.display()
if __name__ == "__main__":
robot = Robot(0.2, "dubins")
coverage_path_planner(13, robot, 3)