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

Completed Bootcamp #128

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions modules/bootcamp/decision_simple_waypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============

def check_proximity(self, position: location.Location) -> bool:
"""
Returns True if position is within self's acceptance radius of the waypoint.
"""
return (
abs(position.location_x - self.waypoint.location_x) ** 2
+ abs(position.location_y - self.waypoint.location_y) ** 2
< self.acceptance_radius**2
)
Comment on lines +50 to +54

Choose a reason for hiding this comment

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

good job not using sqrt to reduce computation


def run(
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]"
) -> commands.Command:
Expand All @@ -69,6 +79,17 @@ def run(
# ============

# Do something based on the report and the state of this class...
if report.status.name == "HALTED":
Copy link

@AaronWang04 AaronWang04 Nov 28, 2024

Choose a reason for hiding this comment

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

I wouldnt usually do equality by name here, you can directly associate with class type. but you don't have to make the change here since it would still work

if self.check_proximity(report.position):
command = commands.Command.create_land_command()
else:
command = commands.Command.create_set_relative_destination_command(
self.waypoint.location_x - report.position.location_x,
self.waypoint.location_y - report.position.location_y,
)
elif report.status.name == "MOVING":
if self.check_proximity(report.position):
command = commands.Command.create_halt_command()

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
Expand Down
52 changes: 52 additions & 0 deletions modules/bootcamp/decision_waypoint_landing_pads.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,36 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
# ============

# Add your own
self.closest_landing_pad = None
self.reached_waypoint = False

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

def is_same(self, position1: location.Location, position2: location.Location) -> bool:
"""
Returns True if the two position differ by less than the acceptance radius.
"""
return (
abs(position1.location_x - position2.location_x) ** 2
+ abs(position1.location_y - position2.location_y) ** 2
< self.acceptance_radius**2
)

def find_closest(self, landing_pads: "list[location.Location]") -> None:
"""
Finds the closest landing pad to the waypoint and stores it in self.
"""
min_distance = float("inf")
for pad in landing_pads:
new_distance = (pad.location_x - self.waypoint.location_x) ** 2 + (
pad.location_y - self.waypoint.location_y
) ** 2
if new_distance < min_distance:
self.closest_landing_pad = pad
min_distance = new_distance

def run(
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]"
) -> commands.Command:
Expand All @@ -69,6 +94,33 @@ def run(
# ============

# Do something based on the report and the state of this class...
if report.status.name == "HALTED":
if not self.reached_waypoint:
# At waypoint.
if self.is_same(self.waypoint, report.position):
print("reached waypoint")
self.reached_waypoint = True
self.find_closest(landing_pad_locations)
print(self.closest_landing_pad)
command = commands.Command.create_set_relative_destination_command(
self.closest_landing_pad.location_x - report.position.location_x,
self.closest_landing_pad.location_y - report.position.location_y,
)
# At origin.
else:
print("should not be here")
print(self.waypoint)
print(report.position)
print(self.is_same(self.waypoint, report.position))
command = commands.Command.create_set_relative_destination_command(
self.waypoint.location_x - report.position.location_x,
self.waypoint.location_y - report.position.location_y,
)
# At landing pad.
elif self.is_same(self.closest_landing_pad, report.position):
command = commands.Command.create_land_command()
elif report.status.name == "MOVING":
pass

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
Expand Down
28 changes: 15 additions & 13 deletions modules/bootcamp/detect_landing_pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
# ↓ 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 ↑
# ============
Expand Down Expand Up @@ -98,31 +95,36 @@ 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 = ...

return [], image_annotated
for i in range(0, boxes_cpu.shape[0]):
# # Create BoundingBox object and append to list
result, box = bounding_box.BoundingBox.create(boxes_cpu[i])
if not result:
return [], None
bounding_boxes.append(box)

return bounding_boxes, image_annotated
# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============