-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
115 lines (99 loc) · 3.22 KB
/
run.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
import argparse
import json
import time
from suas_helmsman import SUASGraph
def upload_json(graph, json_file):
json_file["autogenPoints"] = []
for lat, lon, alt in graph.path_lat_lon_alt():
json_file["autogenPoints"].append(
{"latitude": lat, "longitude": lon, "altitude": alt}
)
with open("./autogen_output.json", "w") as output:
output.write(json.dumps(json_file, indent=2))
def construct_graph(interop_data, drop, off_axis, obstacles):
"""Constructs an Instance of SUASGraph.
This generates a SUASGraph from the interop data provided.
This generates all the points of interest and possible paths
while accounting for obstacles.
Args:
interop_data (Dictionary): JSON file of the interop data
parsed_args (argparse.ArgumentParser): The argument parser,
used to determine whether of not to generate features.
Returns:
SUASGraph: The constructed graph
"""
# Initial graph constructor
g = SUASGraph(
interop_data["lostCommsPos"],
(
int(interop_data["flyZones"][0]["altitudeMin"]),
int(interop_data["flyZones"][0]["altitudeMax"]),
),
)
print("Adding Boundaries to Graph")
# Adds waypoint boundaries to map
g.add_boundaries(interop_data["flyZones"][0]["boundaryPoints"])
# Adds waypoint to map
print("Adding Waypoints to Graph")
g.add_waypoints(interop_data["waypoints"])
# Adds obstacles to map
if obstacles:
print("Adding Obstacles to Graph")
g.add_obstacles(interop_data["stationaryObstacles"])
# Adds drop point to map
if drop:
print("Adding Drop to Graph")
g.add_drop(interop_data["airDropPos"])
# Adds off-axis point to map
if off_axis:
print("Adding Off Axis to Graph")
g.add_off_axis(interop_data["offAxisOdlcPos"])
# Constructs possible flight paths
g.add_edges()
# Constructs the flight path using A* Algorithm
g.construct_path()
return g
if __name__ == "__main__":
"""Main function for the program.
Example:
python3 run.py -f ~/file/path.json -o -d
"""
# Add command line arguments
parser = argparse.ArgumentParser()
parser.add_argument(
"-f",
"--file",
help="Path of interop file",
default="./test-files/suas_2019_missions.json",
)
parser.add_argument(
"-d",
"--drop",
help="Toggle to generate drop point",
action="store_false",
)
parser.add_argument(
"-o",
"--off",
help="Toggle to generate off axis point",
action="store_false",
)
parser.add_argument(
"--obstacles",
help="Toggle for generating obstacles",
action="store_false",
)
parsed_args = parser.parse_args()
# Open Interop File
with open(parsed_args.file, "r") as json_file:
interop_data = json.load(json_file)
# Construct Graph
time1 = time.process_time()
graph = construct_graph(
interop_data, parsed_args.drop, parsed_args.off, parsed_args.obstacles
)
time2 = time.process_time()
print("Graph: ", (time2 - time1))
# print(graph.path)
# Upload Flight Path
upload_json(graph, interop_data)