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

Colin Wang's Pull Request #148

Closed
wants to merge 9 commits into from
17 changes: 17 additions & 0 deletions modules/bootcamp/decision_simple_waypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ def run(

# Do something based on the report and the state of this class...

curr_position = report.position

# Find the distance between the current position and the waypoint
distance_x = self.waypoint.x - curr_position.x
distance_y = self.waypoint.y - curr_position.y

if report.status == drone_status.DroneStatus.HALTED:

# check if the drone is close enough to the waypoint
if (distance_x**2 + distance_y**2) < self.acceptance_radius**2:
command = commands.Command.create_landing_command()

else:
command = commands.Command.create_set_relative_destination_command(
distance_x, distance_y
)

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

# Add your own

self.waypoint_reached = False
self.closest_landing_pad = None

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

def sqaure_distance(
self, start_location: location.Location, final_location: location.Location
) -> float:
"""
Calculate the square distance between two locations.
"""
return (start_location.location_x - final_location.location_x) ** 2 + (
start_location.location_y - final_location.location_y
) ** 2

def within_accepted_radius(
self, start_location: location.Location, final_location: location.Location
) -> bool:
"""
Check if the start location is within the acceptance radius of the final location.
"""
return self.sqaure_distance(start_location, final_location) < self.acceptance_radius**2

def run(
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]"
) -> commands.Command:
Expand Down Expand Up @@ -70,6 +91,46 @@ def run(

# Do something based on the report and the state of this class...

if report.status == drone_status.DroneStatus.HALTED:

# land the drone if it has reached the waypoint, no more landing pads and is within the acceptance radius
if (
self.waypoint_reached
and self.closest_landing_pad is not None
maxlou05 marked this conversation as resolved.
Show resolved Hide resolved
and self.within_accepepted_radius(report.position, self.closest_landing_pad)
):
command = commands.Command.create_land_command()

# move the drone to the waypoint
elif (
not self.within_accepepted_radius(report.position, self.waypoint)
and not self.waypoint_reached
):
distance_x = self.waypoint.location_x - report.position.location_x
distance_y = self.waypoint.location_y - report.position.location_y
command = commands.Command.create_set_relative_destination_command(
distance_x, distance_y
)

# find the next closest landing pad
else:
shortest_distance = float("inf")

for landing_pad in landing_pad_locations:
if self.sqaure_distance(report.position, landing_pad) < shortest_distance:
shortest_distance = self.sqaure_distance(report.position, landing_pad)
self.closest_landing_pad = landing_pad

if self.closest_landing_pad is not None:
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,
)
elif self.closest_landing_pad is None:
command = command.create_halt_command()

self.waypoint_reached = True

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============
Expand Down
20 changes: 14 additions & 6 deletions modules/bootcamp/detect_landing_pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,39 @@ 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.8, device=self.__DEVICE, verbose=True
)

# 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(boxes_cpu.shape[0]):
result, box = bounding_box.BoundingBox.create(boxes_cpu[i])
if result:
bounding_boxes.append(box)
Copy link
Member

Choose a reason for hiding this comment

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

Normally in statistics, we would discard the entire data point (the whole image) if part of it is bad (a bounding box). (You do not need to change anything here, just something to think about)


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.2 # seconds

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