Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyducky037 committed Sep 12, 2024
1 parent de1dda3 commit e5af4cd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion modules/bootcamp/decision_simple_waypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def run(
command = commands.Command.create_land_command()
else:
command = commands.Command.create_halt_command()
elif not report.status == report.status.MOVING:
elif report.status != report.status.MOVING:
command = commands.Command.create_set_relative_destination_command(
self.waypoint.location_x - report.position.location_x,
self.waypoint.location_y - report.position.location_y,
Expand Down
77 changes: 38 additions & 39 deletions modules/bootcamp/decision_waypoint_landing_pads.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
# ============

# Add your own
self.to_waypoint = True
self.to_landing = False
self.route_status = "waypoint"

self.closest = None

Expand All @@ -48,24 +47,23 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
# ============

def closest_landing_pad(
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]"
self,
report: drone_report.DroneReport,
landing_pad_locations: "list[location.Location] | None",
) -> commands.Command:
"""
Finds the closest landing pad given the current location of the drone.
The assumption that the boundaries of the drone are from -60 to 60,
it is possible to set a maximum squared distance of greater than 2 * 120**2,
hence the initial distance is 1000000.
"""
distance = 1000000
idx = None
for loc in landing_pad_locations:
dist = (loc.location_x - report.position.location_x) ** 2 + (
loc.location_y - report.position.location_y
) ** 2
if dist < distance:
idx = loc
distance = dist
return idx
min_distance = float("inf")
closest_landing_pad_location = None
for landing_pad_location in landing_pad_locations:
distance_to_landing_pad = (
landing_pad_location.location_x - report.position.location_x
) ** 2 + (landing_pad_location.location_y - report.position.location_y) ** 2
if distance_to_landing_pad < min_distance:
closest_landing_pad_location = landing_pad_location
min_distance = distance_to_landing_pad
return closest_landing_pad_location

def run(
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]"
Expand Down Expand Up @@ -93,33 +91,34 @@ def run(
# ============

# Do something based on the report and the state of this class...
if self.to_waypoint:
if (self.waypoint.location_x - report.position.location_x) ** 2 + (
self.waypoint.location_y - report.position.location_y
) ** 2 <= self.acceptance_radius**2:
self.to_waypoint = False
self.to_landing = True
elif not report.status == report.status.MOVING:
command = commands.Command.create_set_relative_destination_command(
self.waypoint.location_x - report.position.location_x,
self.waypoint.location_y - report.position.location_y,
)
elif self.to_landing:
if self.closest is None:
self.closest = self.closest_landing_pad(report, landing_pad_locations)
command = commands.Command.create_set_relative_destination_command(
self.closest.location_x - report.position.location_x,
self.closest.location_y - report.position.location_y,
)
elif (self.closest.location_x - report.position.location_x) ** 2 + (
self.closest.location_y - report.position.location_y
) ** 2 <= self.acceptance_radius**2:
self.to_landing = False
else:

if self.route_status == "landing":
if report.status == report.status.HALTED:
command = commands.Command.create_land_command()
self.route_status = "landed"
else:
command = commands.Command.create_halt_command()
elif self.route_status == "landed":
command = commands.Command.create_null_command()
else:
if self.route_status == "waypoint":
destination = self.waypoint
elif self.route_status == "pad":
if self.closest is None:
self.closest = self.closest_landing_pad(report, landing_pad_locations)
destination = self.closest
if (destination.location_x - report.position.location_x) ** 2 + (
destination.location_y - report.position.location_y
) ** 2 <= self.acceptance_radius**2:
if self.route_status == "waypoint":
self.route_status = "pad"
elif self.route_status == "pad":
self.route_status = "landing"
elif report.status != report.status.MOVING:
command = commands.Command.create_set_relative_destination_command(
destination.location_x - report.position.location_x,
destination.location_y - report.position.location_y,
)
# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============
Expand Down
5 changes: 3 additions & 2 deletions modules/bootcamp/detect_landing_pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ def run(self, image: np.ndarray) -> "tuple[list[bounding_box.BoundingBox], np.nd
# Loop over the boxes list and create a list of bounding boxes
bounding_boxes = []
for i in range(0, boxes_cpu.shape[0]):
box = bounding_box.BoundingBox.create(boxes_cpu[i])[1]
bounding_boxes.append(box)
result, box = bounding_box.BoundingBox.create(boxes_cpu[i])
if result:
bounding_boxes.append(box)
# Hint: .shape gets the dimensions of the numpy array
# for i in range(0, ...):
# # Create BoundingBox object and append to list
Expand Down

0 comments on commit e5af4cd

Please sign in to comment.