-
Notifications
You must be signed in to change notification settings - Fork 236
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 Submission - Emily Qi #135
Changes from 1 commit
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 |
---|---|---|
|
@@ -37,7 +37,9 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non | |
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
# ============ | ||
|
||
# Add your own | ||
self.has_sent_landing_command = False | ||
self.min_flight_boundary = -60 | ||
self.max_flight_boundary = 60 | ||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
|
@@ -70,6 +72,30 @@ def run( | |
|
||
# Do something based on the report and the state of this class... | ||
|
||
if ( | ||
self.waypoint.location_x >= self.min_flight_boundary | ||
and self.waypoint.location_x <= self.max_flight_boundary | ||
and self.waypoint.location_y >= self.min_flight_boundary | ||
and self.waypoint.location_y <= self.max_flight_boundary | ||
): | ||
distance_from_waypoint = ( | ||
self.waypoint.location_x - report.position.location_x | ||
) ** 2 + (self.waypoint.location_y - report.position.location_y) ** 2 | ||
|
||
if ( | ||
report.status == drone_status.DroneStatus.HALTED | ||
and not self.has_sent_landing_command | ||
): | ||
|
||
if distance_from_waypoint <= self.acceptance_radius**2: | ||
command = commands.Command.create_land_command() | ||
self.has_sent_landing_command = True | ||
|
||
elif distance_from_waypoint > self.acceptance_radius**2: | ||
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. do you need the elif or can it just be an else? |
||
command = commands.Command.create_set_relative_destination_command( | ||
self.waypoint.location_x, self.waypoint.location_y | ||
) | ||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
# ============ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,12 +37,25 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non | |
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
# ============ | ||
|
||
# Add your own | ||
self.has_sent_landing_command = False | ||
self.min_flight_boundary = -60 | ||
self.max_flight_boundary = 60 | ||
|
||
self.ready_to_land = False | ||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
# ============ | ||
|
||
def distance_between_locations(self, other_location: location.Location) -> float: | ||
""" | ||
Calculate the squared distance between two Location objects | ||
""" | ||
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. since this is the distance squared, name it accordingly |
||
|
||
return (self.waypoint.location_x - other_location.location_x) ** 2 + ( | ||
self.waypoint.location_y - other_location.location_y | ||
) ** 2 | ||
|
||
def run( | ||
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]" | ||
) -> commands.Command: | ||
|
@@ -70,6 +83,50 @@ def run( | |
|
||
# Do something based on the report and the state of this class... | ||
|
||
if ( | ||
self.waypoint.location_x >= self.min_flight_boundary | ||
and self.waypoint.location_x <= self.max_flight_boundary | ||
and self.waypoint.location_y >= self.min_flight_boundary | ||
and self.waypoint.location_y <= self.max_flight_boundary | ||
): | ||
distance_from_waypoint = ( | ||
self.waypoint.location_x - report.position.location_x | ||
) ** 2 + (self.waypoint.location_y - report.position.location_y) ** 2 | ||
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. consider using your defined function with report.position as the input |
||
|
||
if report.status == drone_status.DroneStatus.HALTED: | ||
|
||
if self.ready_to_land: | ||
command = commands.Command.create_land_command() | ||
self.has_sent_landing_command = True | ||
|
||
elif ( | ||
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. we generally say that an acceptance radius is strictly <, not <= |
||
distance_from_waypoint <= self.acceptance_radius**2 | ||
and not self.has_sent_landing_command | ||
): | ||
smallest_distance = 999999999 | ||
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. it's generally bad practice to use just a very large number like this - try looking for how to represent infinity in python |
||
smallest_distance_x = 0 | ||
smallest_distance_y = 0 | ||
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. consider storing the waypoint object instead of the x and y, this also makes is so you don't need to check |
||
|
||
for landing_pad in landing_pad_locations: | ||
if self.distance_between_locations(landing_pad) < smallest_distance: | ||
smallest_distance = self.distance_between_locations(landing_pad) | ||
smallest_distance_x = landing_pad.location_x - self.waypoint.location_x | ||
smallest_distance_y = landing_pad.location_y - self.waypoint.location_y | ||
|
||
command = commands.Command.create_set_relative_destination_command( | ||
smallest_distance_x, smallest_distance_y | ||
) | ||
|
||
self.ready_to_land = True | ||
|
||
elif ( | ||
distance_from_waypoint > self.acceptance_radius**2 | ||
and not self.has_sent_landing_command | ||
): | ||
command = commands.Command.create_set_relative_destination_command( | ||
self.waypoint.location_x, self.waypoint.location_y | ||
) | ||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
# ============ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,7 @@ | |
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
# ============ | ||
# 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 +96,37 @@ def run(self, image: np.ndarray) -> "tuple[list[bounding_box.BoundingBox], np.nd | |
# * conf | ||
# * device | ||
# * verbose | ||
predictions = ... | ||
predictions = self.__model.predict(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() | ||
|
||
# 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 i in range(0, np.shape(boxes_cpu)[0]): | ||
|
||
# Create BoundingBox object and append to list | ||
(result, box) = bounding_box.BoundingBox.create(boxes_cpu[i]) | ||
|
||
if result: | ||
bounding_boxes.append(box) | ||
Comment on lines
+126
to
+127
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. instead of skipping failed boxes, we want to return no boxes if any of then fail. This is because in data science, when we have corrupted data, we skip the whole data point instead of partial data - in this case, the image is the data point and the boxes are parts of the data |
||
|
||
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.
we generally say that an acceptance radius is strictly <, not <=