-
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
Initial Submission - Manjot #100
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 |
---|---|---|
|
@@ -36,9 +36,8 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non | |
# ============ | ||
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
# ============ | ||
|
||
# Add your own | ||
|
||
self.landpad_reached = False | ||
self.waypoint_reached = False | ||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
# ============ | ||
|
@@ -68,10 +67,54 @@ def run( | |
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
# ============ | ||
|
||
# Do something based on the report and the state of this class... | ||
if report.status == drone_status.DroneStatus.HALTED: | ||
|
||
if not self.waypoint_reached: | ||
# Moves towards the waypoint | ||
x_dist = self.waypoint.location_x - report.position.location_x | ||
y_dist = self.waypoint.location_y - report.position.location_y | ||
command = commands.Command.create_set_relative_destination_command(x_dist, y_dist) | ||
|
||
self.waypoint_reached = True | ||
Comment on lines
+72
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. Same here, please use accpetance_radius |
||
|
||
# Once you get to the waypoint, you have to go to the nearest landpad | ||
elif not self.landpad_reached: | ||
# Find the closest pad and store it in closest_landpad | ||
# This is using the min() method to iterate through each pad, get the distance to it and compare it with others | ||
closest_pad = min( | ||
landing_pad_locations, key=lambda pad: self.get_distance(report.position, pad) | ||
) | ||
print(f"Closest Landpad: {closest_pad.location_x}, {closest_pad.location_y}") | ||
Comment on lines
+84
to
+87
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. This can be moved to the section where you first reach the waypoint. Right now, it recalculates your landing pad continuously (whenever it stops), which is unnecessary. |
||
|
||
# Move to the closest landpad | ||
x_dist = closest_pad.location_x - report.position.location_x | ||
y_dist = closest_pad.location_y - report.position.location_y | ||
# print(f"{x_dist}, {y_dist}") | ||
command = commands.Command.create_set_relative_destination_command(x_dist, y_dist) | ||
|
||
self.landpad_reached = True | ||
|
||
else: | ||
command = commands.Command.create_land_command() | ||
|
||
# raise NotImplementedError | ||
|
||
return command | ||
|
||
# Method used to check distance sqaured between two locations | ||
# We don't need the square root since this is for comparison only | ||
def get_distance(self, loc_1: location.Location, loc_2: location.Location) -> float: | ||
""" | ||
This method is used to get the distance squared between any two locations | ||
|
||
""" | ||
x = loc_1.location_x - loc_2.location_x | ||
y = loc_1.location_y - loc_2.location_y | ||
|
||
# Don't need to square root when comparing between squares | ||
hypotenuse_squared = (x**2) + (y**2) | ||
return hypotenuse_squared | ||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
# ============ | ||
|
||
return command |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,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 +95,41 @@ 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 = ... | ||
|
||
# Only 1 image was used therefore we access the first result in the list | ||
prediction = predictions[0] | ||
# Plot the annotated image from the Result object | ||
# Include the confidence value | ||
image_annotated = ... | ||
image_annotated = prediction.plot(conf=True, boxes=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 = [] | ||
# .shape returns a tuple with the 0th index being the number of lists in the numpy array | ||
for i in range(0, boxes_cpu.shape[0]): | ||
# This func returns a tuple, with whether the operation was a sucess (bool) & the bounding box itself | ||
successful, box = bounding_box.BoundingBox.create(bounds=boxes_cpu[i]) | ||
|
||
if successful: | ||
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. Normally, in statistics, we discard the entire data point (the entire image) if one part of it (the bounding box) is invalid. |
||
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 | ||
# result, 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.
Although this works for the simulation, in real life your drone won't be this precise. Please use the acceptnace_radius to account for minor errors in positioning.