-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmission_loader.py
150 lines (122 loc) · 5.01 KB
/
mission_loader.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
import requests
import json
from mission import Mission
from mission_type import MissionType
class MissionLoader:
def __init__(self, host, missionId, verbose):
self.missionId = missionId
self.verbose = verbose
self.host = host
# Translate mission configuration to array of mission
# Return: array of Mission, mission max altitude, and mission speed
def load(self):
missionConfiguration = None
url = "http://" + self.host + ":6868" + "/api/v1/config/" + self.missionId
r = requests.get(url)
if r.status_code != 200:
raise Exception("Response status code: %d" % r.status_code)
missionConfiguration = r.json()
# with open("./mission-configuration.example.json") as f:
# missionConfiguration = json.load(f)
maxAlt = float(missionConfiguration["max_altitude"])
minAlt = float(missionConfiguration["min_altitude"])
missionSpeed = float(missionConfiguration["mission_speed"])
sweepConfig = missionConfiguration["sweep_config"]
endPoint = missionConfiguration["end_point"]
turningPoint = missionConfiguration["turning_point"]
defaultTransitionMission = MissionType[missionConfiguration["orientation"]]
missions = []
# add takeoff
missions.append(Mission(MissionType.takeoff))
fromBottom = True
for index, sweep in enumerate(sweepConfig):
rackSize = sweep["rack_size"]
levelHeights = self.transformLevelHeights(rackSize["level_height"], maxAlt)
if sweep["scan"]:
for i, levelHeight in (
enumerate(levelHeights)
if fromBottom
else enumerate(reversed(levelHeights))
):
missions.append(Mission(MissionType.wait_for_alt, [levelHeight]))
missions.append(
Mission(
MissionType.publish_rack_id,
[
"%s-%d"
% (
sweep["rack_id"],
i + 1 if fromBottom else len(levelHeights) - i,
)
],
)
)
# missions.append(
# Mission(
# MissionType.align_with_barcode,
# [
# "%s-%d"
# % (
# sweep["rack_id"],
# i + 1 if fromBottom else len(levelHeights) - i,
# )
# ],
# )
# )
# isHighestLevel = (
# (i == len(levelHeights) - 1) if fromBottom else (i == 0)
# )
# missions.append(
# Mission(
# MissionType.wait_for_cv,
# [isHighestLevel],
# )
# )
fromBottom = not fromBottom
if sweep["rack"] != endPoint:
if sweep["rack"] == turningPoint:
missions.append(Mission(MissionType.rotate, [180.0]))
else:
missions.append(
Mission(
defaultTransitionMission,
[
rackSize["width"] / 2
+ sweepConfig[index + 1]["rack_size"]["width"] / 2
],
)
)
missions.append(
Mission(
MissionType.publish_rack_id,
[
"%s-%d"
% (
sweepConfig[index + 1]["rack_id"],
1
if fromBottom
else len(
sweepConfig[index + 1]["rack_size"]["level_height"]
),
)
],
)
)
# land after finishing missions
missions.append(Mission(MissionType.land))
if self.verbose:
print("MissionLoader: load:", missions)
return {
"missions": missions,
"max_altitude": maxAlt,
"min_altitude": minAlt,
"mission_speed": missionSpeed,
}
def transformLevelHeights(self, levelHeights, maxAlt):
newLevelHeights = []
sum = 0
for height in levelHeights:
alt = min(sum + height / 2, maxAlt)
newLevelHeights.append(alt)
sum += height
return newLevelHeights