-
Notifications
You must be signed in to change notification settings - Fork 249
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
Lucas Kim's bootcamp #102
Lucas Kim's bootcamp #102
Changes from 11 commits
f9afc28
8859512
4be946d
f549fca
0ddbeed
fa467cd
9eadad1
2d19edc
bf526d3
37ba797
49ec15f
49ac6e7
09557ec
d30b4bc
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 |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
from .. import location | ||
from ..private.decision import base_decision | ||
|
||
|
||
# Disable for bootcamp use | ||
# No enable | ||
# pylint: disable=duplicate-code,unused-argument | ||
|
@@ -37,7 +36,7 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non | |
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
# ============ | ||
|
||
# Add your own | ||
self.has_reached_waypoint = False | ||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
|
@@ -68,10 +67,52 @@ def run( | |
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
# ============ | ||
|
||
# Do something based on the report and the state of this class... | ||
allowed_error = 0.01 | ||
|
||
if report.status == drone_status.DroneStatus.HALTED: | ||
closest_landing_pad = min( | ||
landing_pad_locations, | ||
key=lambda pad: self.__squared_distance(report.position, pad), | ||
) | ||
|
||
# Check if the landing pad or waypoint has already been reached | ||
if ( | ||
self.__squared_distance(report.position, closest_landing_pad) < allowed_error | ||
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. For this, the function |
||
and self.has_reached_waypoint | ||
): | ||
command = commands.Command.create_land_command() | ||
elif self.__squared_distance(report.position, self.waypoint) < allowed_error: | ||
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. Same here |
||
# Calculate relative x and y distance required to reach landing pad | ||
relative_x = closest_landing_pad.location_x - report.position.location_x | ||
relative_y = closest_landing_pad.location_y - report.position.location_y | ||
|
||
command = commands.Command.create_set_relative_destination_command( | ||
relative_x, relative_y | ||
) | ||
|
||
self.has_reached_waypoint = True | ||
else: | ||
# Calculate relative x and y distance required to reach waypoint | ||
relative_x = self.waypoint.location_x - report.position.location_x | ||
relative_y = self.waypoint.location_y - report.position.location_y | ||
|
||
command = commands.Command.create_set_relative_destination_command( | ||
relative_x, relative_y | ||
) | ||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
# ============ | ||
|
||
return command | ||
|
||
def __squared_distance( | ||
self, location1: location.Location, location2: location.Location | ||
) -> float: | ||
""" | ||
Calculate the distance between two Location objects. | ||
""" | ||
|
||
return ((location2.location_x - location1.location_x) ** 2) + ( | ||
(location2.location_y - location1.location_y) ** 2 | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ | |
# Bootcampers remove the following lines: | ||
# Allow linters and formatters to pass for bootcamp maintainers | ||
# No enable | ||
# pylint: disable=unused-argument,unused-private-member,unused-variable | ||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
# ============ | ||
|
@@ -98,31 +97,37 @@ 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=True) | ||
|
||
# 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 | ||
bounding_boxes = [] | ||
# Hint: .shape gets the dimensions of the numpy array | ||
# for i in range(0, ...): | ||
# # Create BoundingBox object and append to list | ||
# result, box = ... | ||
for xyxy_box in boxes_cpu: | ||
# Create BoundingBox object and append to list | ||
success, box = bounding_box.BoundingBox.create(xyxy_box) | ||
|
||
if not success: | ||
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. In statistics, we normally discard the entire data point (the whole image) if part of it has gone wrong (a bounding box). |
||
continue | ||
|
||
bounding_boxes.append(box) | ||
|
||
return [], image_annotated | ||
return bounding_boxes, image_annotated | ||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
# ============ |
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.
I think you moved it outside of the conditions. It should probably be after line 84, when you have reached the waypoint.