-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bootcamp Complete?- Muhammad Awan #19
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
from .. import commands | ||
from .. import drone_report | ||
from .. import drone_status | ||
import math | ||
from .. import location | ||
from ..private.decision import base_decision | ||
|
||
|
@@ -37,8 +38,6 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float): | |
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
# ============ | ||
|
||
# Add your own | ||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
# ============ | ||
|
@@ -61,6 +60,7 @@ def run(self, | |
put_output(command) | ||
``` | ||
""" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: No spaces between docstring and code (remember to only change things inside the area indicated by the comments). |
||
# Default command | ||
command = commands.Command.create_null_command() | ||
|
||
|
@@ -69,12 +69,38 @@ def run(self, | |
# ============ | ||
|
||
# Do something based on the report and the state of this class... | ||
|
||
# Remove this when done | ||
raise NotImplementedError | ||
|
||
# Assuming 'commands' and 'drone_status' are imported modules | ||
# and self.waypoint, report are provided context | ||
|
||
status = report.status | ||
pos = report.position | ||
way_x = self.waypoint.location_x | ||
way_y = self.waypoint.location_y | ||
rel_dest_x = way_x - pos.location_x | ||
rel_dest_y = way_y - pos.location_y | ||
|
||
within_range = self.within_range_of(self.waypoint, pos) | ||
|
||
if within_range and status == drone_status.DroneStatus.MOVING: | ||
command = commands.Command.create_halt_command() | ||
|
||
elif within_range and status == drone_status.DroneStatus.HALTED: | ||
command = commands.Command.create_land_command() | ||
|
||
elif not within_range and status == drone_status.DroneStatus.HALTED: | ||
command = commands.Command.create_set_relative_destination_command(way_x, way_y) | ||
Comment on lines
+90
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this one to also be relative distance, think about the cases where the drone doesn't start simulation at (0, 0). |
||
|
||
elif status == drone_status.DroneStatus.HALTED: | ||
command = commands.Command.create_set_relative_destination_command(rel_dest_x, rel_dest_y) | ||
|
||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
# ============ | ||
|
||
return command | ||
|
||
def within_range_of(self, l1: location.Location, l2: location.Location): | ||
distance = math.sqrt((l1.location_x - l1.location_x)**2 + (l1.location_y - l2.location_x)**2) | ||
return distance < self.acceptance_radius | ||
Comment on lines
+103
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Adding a type annotation for the return would help readability (you do not need to change anything here, just something to thing about). |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,8 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float): | |
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
# ============ | ||
|
||
# Add your own | ||
self.waypoint_found = False | ||
self.landing_pad_found = False | ||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
|
@@ -68,13 +69,35 @@ def run(self, | |
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
# ============ | ||
|
||
# Do something based on the report and the state of this class... | ||
|
||
# Remove this when done | ||
raise NotImplementedError | ||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
# ============ | ||
Comment on lines
-76
to
-78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure you're not deleting the comment guards, place your code inside of them. You're allowed to write helper functions outside of the comments. |
||
|
||
if report.status == drone_status.DroneStatus.HALTED and not self.waypoint_found: | ||
command = commands.Command.create_set_relative_destination_command( | ||
self.waypoint.location_x, | ||
self.waypoint.location_y | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Add a comma after each argument, including the last argument. |
||
) | ||
self.waypoint_found = True | ||
|
||
elif report.status == drone_status.DroneStatus.HALTED and not self.landing_pad_found: | ||
min_distance = float('inf') | ||
closest_pad = None | ||
|
||
for pad in landing_pad_locations: | ||
distance = self.distance(report.position, pad) | ||
if distance < min_distance: | ||
min_distance = distance | ||
closest_pad = pad | ||
|
||
if closest_pad is not None: | ||
command = commands.Command.create_set_relative_destination_command( | ||
closest_pad.location_x - report.position.location_x, | ||
closest_pad.location_y - report.position.location_y | ||
) | ||
self.landing_pad_found = True | ||
|
||
elif report.status == drone_status.DroneStatus.HALTED and self.landing_pad_found: | ||
command = commands.Command.create_land_command() | ||
Comment on lines
+96
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the bootcamp specifies that the drone will always complete its movement, what if this wasn't guaranteed and it could halt on its own at any random time? (You do not need to change anything here, just something to think about). |
||
|
||
return command | ||
|
||
def distance(self, l1: location.Location, l2: location.Location): | ||
return (l1.location_x - l2.location_x)**2 + (l1.location_y - l2.location_y)**2 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,8 @@ | |
import numpy as np | ||
import torch | ||
import ultralytics | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: One empty line between importing installed modules and importing local modules (remember to not modify anything outside of the area indicated by the comments). |
||
from .. import bounding_box | ||
|
||
|
||
# This is just an interface | ||
# pylint: disable=too-few-public-methods | ||
class DetectLandingPad: | ||
|
@@ -86,32 +84,44 @@ def run(self, image: np.ndarray) -> "tuple[list[bounding_box.BoundingBox], np.nd | |
# * conf | ||
# * device | ||
# * verbose | ||
predictions = ... | ||
predictions = self.__model.predict(source=image,conf=0.7,device=self.__DEVICE,verbose=False) | ||
|
||
# Get the Result object | ||
prediction = ... | ||
prediction = predictions[0] | ||
|
||
# Plot the annotated image from the Result object | ||
# Include the confidence value | ||
image_annotated = ... | ||
image_annotated = prediction.plot(conf=0.7) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've already set the confidence above - how do you tell it to use the confidence here? |
||
|
||
# Get the xyxy boxes list from the Boxes object in the Result object | ||
boxes_xyxy = ... | ||
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_cpu = boxes_xyxy.detach().cpu().numpy() | ||
|
||
# Loop over the boxes list and create a list of bounding boxes | ||
# Loop over the boxes list and create a list of bounding boxes | ||
bounding_boxes = [] | ||
for box in boxes_cpu: | ||
result, new_box = bounding_box.BoundingBox.create(np.array(box)) | ||
if result: | ||
bounding_boxes.append(new_box) | ||
else: | ||
return [] | ||
|
||
return bounding_boxes, image_annotated | ||
|
||
|
||
|
||
# Hint: .shape gets the dimensions of the numpy array | ||
# for i in range(0, ...): | ||
# Create BoundingBox object and append to list | ||
# result, box = ... | ||
Comment on lines
118
to
121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete commented out or unreachable code. Git and GitHub will keep track of it if we need it again. |
||
|
||
# Remove this when done | ||
raise NotImplementedError | ||
|
||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,7 @@ | ||
# BOOTCAMPERS TO COMPLETE. | ||
|
||
# This file lists the required Python packages to install. | ||
|
||
# Packages listed in alphabetical order | ||
numpy | ||
opencv-python | ||
pytest | ||
|
||
# PyTorch | ||
--extra-index-url https://download.pytorch.org/whl/cu117 | ||
|
||
# ============ | ||
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
# ============ | ||
|
||
# Based on: https://pytorch.org/get-started/previous-versions/#wheel-1 | ||
# If you are on MacOS, remove +cu117 | ||
# Otherwise, you can keep as is, or use +cpu if you | ||
# have a CUDA capable GPU but don't want to use it | ||
torch==1.13.1+cu117 | ||
torchvision==0.14.1+cu117 | ||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
# ============ | ||
|
||
torch==1.13.1 | ||
torchvision==0.14.1 | ||
ultralytics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: System-level module imports before local module imports with one empty space in between.
However, for this bootcamp, we're not allowing you to import any additional libraries. Try to do it without importing math.
Hint
What's another way to compute the square root? (Also do you need to compare the square root?)