-
Notifications
You must be signed in to change notification settings - Fork 0
/
popcorn_planner.py
73 lines (56 loc) · 2.09 KB
/
popcorn_planner.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
from wadl.survey import Survey
from wadl.solver.solver import SolverParameters
from wadl.lib.route import RouteParameters
from wadl.mission import MissionParameters, Mission
from flask import request
import tempfile
import json
import os
import shutil
import logging
CSV_FILENAME = '__polygon.csv'
SURVEY_NAME = '.__TEMP_SURVEY'
def plan_paths_wadl(json_data):
"""
Plan paths using wadl and reading data from request.data
:return:
"""
logger = logging.getLogger()
logger.setLevel("WARNING")
fly_zone = json_data["fly-zone"]
home_point = (json_data["start-point"][0], json_data["start-point"][1])
with open(CSV_FILENAME, 'w') as f:
print("fid,lat,lon", file=f)
i = 1
for p in fly_zone:
print(f"{i},{float(p[0])},{float(p[1])}", file=f)
i += 1
survey = Survey(SURVEY_NAME)
survey.setKeyPoints({'home': home_point})
route_params = RouteParameters()
route_params['limit'] = 60000
route_params['speed'] = 9
route_params['altitude'] = 20
survey.addTask(CSV_FILENAME, step=float(json_data['sweeping-step']), home=['home'], routeParameters=route_params)
solver_params = SolverParameters()
solver_params['subgraph_size'] = 18
solver_params['SATBound_offset'] = 4
solver_params['timeout'] = 60
survey.setSolverParamters(solver_params)
os.remove(CSV_FILENAME)
# Delete all the existing planned paths
for p in filter(lambda x: x.startswith(CSV_FILENAME[:-4]), os.listdir(SURVEY_NAME)):
shutil.rmtree(SURVEY_NAME + '/' + p)
try:
survey.plan()
except Exception as e:
pass
os.sync()
routes_path = SURVEY_NAME + '/' + list(filter(lambda x: x.startswith(CSV_FILENAME[:-4]), os.listdir(SURVEY_NAME)))[0] + '/routes/'
routes = os.listdir(routes_path)
res = []
for route in routes:
print("Route:", route)
with open(routes_path + route, 'r') as f:
res.append(list(map(lambda line: tuple(reversed(tuple(map(float, line.split(',')[:2])))), list(filter(lambda x: bool(x.strip()), f.readlines()))))[2:-2])
return res