Skip to content
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

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions modules/bootcamp/decision_simple_waypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
# ============

# Add your own

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============
Expand Down Expand Up @@ -68,10 +66,32 @@ 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:
# Check if the waypoint has already been reached
if self.__squared_distance(self.waypoint, report.position) < allowed_error:
command = commands.Command.create_land_command()
else:
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
)
47 changes: 44 additions & 3 deletions modules/bootcamp/decision_waypoint_landing_pads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ↑
Expand Down Expand Up @@ -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),
)
Copy link
Member

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.


# Check if the landing pad or waypoint has already been reached
if (
self.__squared_distance(report.position, closest_landing_pad) < allowed_error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, the function run() has a parameter acceptance_radius which you should use. The "error" should thus be squared for this case.

and self.has_reached_waypoint
):
command = commands.Command.create_land_command()
elif self.__squared_distance(report.position, self.waypoint) < allowed_error:
Copy link
Member

Choose a reason for hiding this comment

The 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
)
27 changes: 16 additions & 11 deletions modules/bootcamp/detect_landing_pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ↑
# ============
Expand Down Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The 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).
(You do not need to change anything, just something to think about)

continue

bounding_boxes.append(box)

return [], image_annotated
return bounding_boxes, image_annotated
# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pytest
# If you are on MacOS, don't have a CUDA capable GPU,
# or if things don't work and you just want to use the CPU,
# comment out the "--extra-index-url" option
--extra-index-url https://download.pytorch.org/whl/cu124

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
Expand Down