Skip to content

Commit

Permalink
made changes indicated in review by ashum68
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmoyv27 committed Sep 12, 2024
1 parent ca1bf47 commit 97f669e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
18 changes: 13 additions & 5 deletions modules/bootcamp/decision_waypoint_landing_pads.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# Disable for bootcamp use
# pylint: disable=unused-import

import sys
from .. import commands
from .. import drone_report
from .. import drone_status
Expand Down Expand Up @@ -58,13 +57,18 @@ def find_closest_landing_pad(
self,
current_position: location.Location,
landing_pad_locations: "list[location.Location]",
) -> location.Location:
) -> location.Location | None:
"""
Find the closest landing pad
"""

# Handle case when no landing pads present
if len(landing_pad_locations) == 0:
return None

closest_pad = None
# Setting default to maximum integer value for easy troubleshooting
min_distance = sys.maxsize
min_distance = float("inf")

# Trivial sorter to determine the closest landing pad
for lander in landing_pad_locations:
Expand Down Expand Up @@ -118,9 +122,9 @@ def run(

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

# Removed redundant variable current_position
if not self.arrived:
current_position = report.position
squared_distance_to_waypoint = self.squared_distance(current_position, self.waypoint)
squared_distance_to_waypoint = self.squared_distance(report.position, self.waypoint)

# Check acceptance radius
if squared_distance_to_waypoint <= self.acceptance_radius**2:
Expand All @@ -136,6 +140,10 @@ def run(
if self.arrived:
closest_pad = self.find_closest_landing_pad(report.position, landing_pad_locations)

# Keep simulation running if no landing pad found
if closest_pad is None:
return commands.Command.create_null_command()

# Calculate squared distance to the closest landing pad
squared_distance_to_pad = self.squared_distance(report.position, closest_pad)

Expand Down
12 changes: 5 additions & 7 deletions modules/bootcamp/detect_landing_pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DetectLandingPad:
__MODEL_NAME = "best-2n.pt"

@classmethod
def create(cls, model_directory: pathlib.Path) -> tuple:
def create(cls, model_directory: pathlib.Path) -> "tuple[bool, DetectLandingPad | None]":
"""
model_directory: Directory to models.
"""
Expand Down Expand Up @@ -97,23 +97,21 @@ def run(self, image: np.ndarray) -> "tuple[list[bounding_box.BoundingBox], np.nd

# Plot the annotated image from the Result object
# Include the confidence value
image_annotated = prediction.plot()
image_annotated = prediction.plot(conf=True)

# Get the xyxy-boxes list from the Boxes object in the Result object
boxes_xyxy = prediction.boxes.xyxy

# Detach the xyxy boxes to make a copy,
# move the copy into CPU space,
# and convert to a numpy array
boxes_cpu = boxes_xyxy.cpu().numpy()
boxes_cpu = boxes_xyxy.detach().cpu().numpy()

# Loop over the boxes list and create a list of bounding boxes
bounding_boxes = []

# Use a range-based for-loop based on number of elements
for i in range(boxes_cpu.shape[0]):
box = boxes_cpu[i, :]
result, box = bounding_box.BoundingBox.create(boxes_cpu[i])
for box in boxes_cpu:
result, box = bounding_box.BoundingBox.create(box)
if result:
bounding_boxes.append(box)
# Hint: .shape gets the dimensions of the numpy array
Expand Down

0 comments on commit 97f669e

Please sign in to comment.