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

Victor Huang Bootcamp #141

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
17 changes: 14 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,23 @@ 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 self.acceptance_radius**2 >= self.find_squared_dist(self.waypoint, report.position):
command = command.create_land_command()
else:
command = command.create_set_relative_destination_command(
self.waypoint.location_x - report.position.location_x,
self.waypoint.location_y - report.position.location_y,
)

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

return command

# helper functions
@staticmethod
def find_squared_dist(loc1: location.Location, loc2: location.Location) -> int:
"""helper function that finds the squared distance between two Location instances"""
return (loc1.location_x - loc2.location_x) ** 2 + (loc1.location_y - loc2.location_y) ** 2
57 changes: 55 additions & 2 deletions modules/bootcamp/decision_waypoint_landing_pads.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
# ============

# Add your own
self.waypoint_achieved = False
self.final_destination = None

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
Expand Down Expand Up @@ -68,10 +69,62 @@ 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
and self.waypoint_achieved
and (
self.acceptance_radius**2
>= self.find_squared_dist(self.final_destination, report.position)
)
):
# landing at closest landing pad
command = command.create_land_command()
elif report.status == drone_status.DroneStatus.HALTED and (
self.acceptance_radius**2 >= self.find_squared_dist(self.waypoint, report.position)
):
# find closest landing pad
self.waypoint_achieved = True
self.final_destination = self.find_closest_location(
report.position, landing_pad_locations
)

if self.final_destination is not None:
command = command.create_set_relative_destination_command(
self.final_destination.location_x - report.position.location_x,
self.final_destination.location_y - report.position.location_y,
)
else:
# leave control of drone to higher-order function if no landing pad is available
command = command.create_null_command()
elif report.status == drone_status.DroneStatus.HALTED:
command = command.create_set_relative_destination_command(
self.waypoint.location_x - report.position.location_x,
self.waypoint.location_y - report.position.location_y,
)

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

return command

# helper functions
@staticmethod
def find_squared_dist(loc1: location.Location, loc2: location.Location) -> int:
"""helper function that finds the squared distance between two Location instances"""
return (loc1.location_x - loc2.location_x) ** 2 + (loc1.location_y - loc2.location_y) ** 2

@staticmethod
def find_closest_location(
curr_loc: location.Location, location_list: "list[location.Location]"
) -> location.Location | None:
"""find the closest location in a list of locations"""
min_dist, closest_location = float("inf"), None

for loc in location_list:
dist = DecisionWaypointLandingPads.find_squared_dist(curr_loc, loc)
if dist < min_dist:
closest_location = loc
min_dist = dist

return closest_location
26 changes: 14 additions & 12 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, verbose=False, conf=0.75, device=None)
Copy link
Member

Choose a reason for hiding this comment

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

Although using default or letting it choose is fine, there is a variable in this bootcamp that indicates which device you should use (You don't have to change anything here, just something to think about)


# 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 raw_box in boxes_cpu:
# Create BoundingBox object and append to list
result, box = bounding_box.BoundingBox.create(raw_box)
# discard image if failed
if not result:
return [], image_annotated

return [], image_annotated
bounding_boxes.append(box)

return bounding_boxes, image_annotated
# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============
2 changes: 1 addition & 1 deletion modules/bootcamp/tests/run_decision_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# to reach the 1st command
# Increase the step size if your computer is lagging
# Larger step size is smaller FPS
TIME_STEP_SIZE = 0.1 # seconds
TIME_STEP_SIZE = 0.5 # seconds

# OpenCV ignores your display settings,
# so if the window is too small or too large,
Expand Down
Loading