Skip to content

Commit f3b0a4f

Browse files
committed
Added changes from feedback
1 parent 3a12a34 commit f3b0a4f

File tree

3 files changed

+46
-36
lines changed

3 files changed

+46
-36
lines changed

modules/bootcamp/decision_simple_waypoint.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,11 @@ def run(
7070

7171
# Do something based on the report and the state of this class...
7272

73-
on_waypoint = (
74-
report.position.location_x - self.acceptance_radius
75-
<= self.waypoint.location_x
76-
<= report.position.location_x + self.acceptance_radius
77-
) and (
78-
report.position.location_y - self.acceptance_radius
79-
<= self.waypoint.location_y
80-
<= report.position.location_y + self.acceptance_radius
81-
)
82-
8373
if report.status == drone_status.DroneStatus.HALTED:
74+
delta_x = report.position.location_x - self.waypoint.location_x
75+
delta_y = report.position.location_y - self.waypoint.location_y
76+
on_waypoint = delta_x**2 + delta_y**2 < self.acceptance_radius**2
77+
8478
if on_waypoint:
8579
command = commands.Command.create_land_command()
8680

modules/bootcamp/decision_waypoint_landing_pads.py

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
3737
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
3838
# ============
3939

40+
self.above_destination = False
4041
self.target_lp = None
4142

42-
self.reached_wp = False
43-
self.reached_lp = False
43+
self.approaching_wp = False
44+
self.approaching_lp = False
4445

4546
# ============
4647
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
@@ -64,6 +65,10 @@ def run(
6465
put_output(command)
6566
```
6667
"""
68+
# ============
69+
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
70+
# ============
71+
6772
# print("RUN")
6873
# Default command
6974
command = commands.Command.create_null_command()
@@ -75,27 +80,32 @@ def run(
7580
)
7681

7782
# Handle unexpected halts
78-
if report.position != report.destination:
83+
delta_x = report.position.location_x - report.destination.location_x
84+
delta_y = report.position.location_y - report.destination.location_y
85+
self.above_destination = delta_x**2 + delta_y**2 < self.acceptance_radius**2
86+
87+
if not self.above_destination:
7988
print("^^UNEXPECTED HALT")
8089
command = commands.Command.create_set_relative_destination_command(
8190
report.destination.location_x - report.position.location_x,
8291
report.destination.location_y - report.position.location_y,
8392
)
8493

85-
elif not self.reached_wp:
94+
elif not self.approaching_wp:
8695
command = commands.Command.create_set_relative_destination_command(
8796
self.waypoint.location_x, self.waypoint.location_y
8897
)
89-
self.reached_wp = True
98+
self.approaching_wp = True
9099
print("APPROACHING WP: ", self.waypoint.location_x, self.waypoint.location_y)
91100

92-
elif not self.reached_lp:
93-
self.target_lp = landing_pad_locations[self.find_closest_lp(landing_pad_locations)]
101+
elif not self.approaching_lp:
102+
self.target_lp = self.find_closest_lp(report, landing_pad_locations)
94103
lp_relative_x, lp_relative_y = self.relative_target(self.target_lp, report)
104+
95105
command = commands.Command.create_set_relative_destination_command(
96106
lp_relative_x, lp_relative_y
97107
)
98-
self.reached_lp = True
108+
self.approaching_lp = True
99109
print("APPROACHING LP: ", self.target_lp.location_x, self.target_lp.location_y)
100110

101111
else:
@@ -104,43 +114,45 @@ def run(
104114

105115
return command
106116

107-
def find_closest_lp(self, landing_pad_locations: "list[location.Location]") -> int:
117+
# ============
118+
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
119+
# ============
120+
121+
def find_closest_lp(
122+
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]"
123+
) -> int:
108124
"""
109125
Given a list of landing pads,
110126
determines the index of the closest one to the waypoint.
111127
"""
112-
if len(landing_pad_locations) in [0, 1]:
113-
return 0
128+
if len(landing_pad_locations) == 1:
129+
return landing_pad_locations[0]
114130

115-
wp_x = self.waypoint.location_x
116-
wp_y = self.waypoint.location_y
131+
drone_x = report.position.location_x
132+
drone_y = report.position.location_y
117133

118134
i = 0
119-
winning_i = 0
120-
winning_dist = -1
135+
winning_pad = landing_pad_locations[0]
136+
winning_sq_dist = float("inf")
121137

122138
for lp in landing_pad_locations:
123139
lp_x = lp.location_x
124140
lp_y = lp.location_y
125141

126-
same_loc = (
127-
wp_x - self.acceptance_radius <= lp_x <= wp_x + self.acceptance_radius
128-
) and (wp_y - self.acceptance_radius <= lp_y <= wp_y + self.acceptance_radius)
129-
130-
if same_loc:
131-
return i
142+
delta_x = lp_x - drone_x
143+
delta_y = lp_y - drone_y
132144

133-
sq_dist = (lp_x - wp_x) ** 2 + (lp_y - wp_y) ** 2
145+
sq_dist = delta_x**2 + delta_y**2
134146

135-
if (sq_dist < winning_dist) or (winning_dist == -1):
136-
winning_dist = sq_dist
137-
winning_i = i
147+
if sq_dist < winning_sq_dist:
148+
winning_sq_dist = sq_dist
149+
winning_pad = landing_pad_locations[i]
138150

139151
i += 1
140152

141153
# print("TARGET LP FOUND, INDEX: ", winning_i)
142154
# print("^^SQDIST FROM WP: ", winning_dist)
143-
return winning_i
155+
return winning_pad
144156

145157
@staticmethod
146158
def relative_target(

modules/bootcamp/detect_landing_pad.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,13 @@ def run(self, image: np.ndarray) -> "tuple[list[bounding_box.BoundingBox], np.nd
125125
for i in range(0, boxes_cpu.shape[0]):
126126
# Create BoundingBox object and append to list
127127
result, box = bounding_box.BoundingBox.create(boxes_cpu[i])
128+
# print("RESULT: ", result)
129+
# print("BOX: ", box)
128130

129131
if result:
130132
bounding_boxes.append(box)
133+
else:
134+
return []
131135

132136
return bounding_boxes, image_annotated
133137
# ============

0 commit comments

Comments
 (0)