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

Daniel Suzuki's Bootcamp #97

Closed
wants to merge 18 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
18 changes: 17 additions & 1 deletion modules/bootcamp/decision_simple_waypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
# ============

# Add your own
self.halt_at_initialization = True

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
Expand Down Expand Up @@ -69,6 +69,22 @@ def run(
# ============

# Do something based on the report and the state of this class...
if report.status == drone_status.DroneStatus.HALTED:
if self.halt_at_initialization:
command = commands.Command.create_set_relative_destination_command(
self.waypoint.location_x - report.position.location_x,
self.waypoint.location_y - report.position.location_y,
)
self.halt_at_initialization = False
elif (
report.status == drone_status.DroneStatus.HALTED
and (
(report.position.location_x - self.waypoint.location_x) ** 2
+ (report.position.location_y - self.waypoint.location_y) ** 2
)
<= self.acceptance_radius**2
):
command = commands.Command.create_land_command()

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
Expand Down
58 changes: 53 additions & 5 deletions modules/bootcamp/decision_waypoint_landing_pads.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
# ============
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
# ============
# set as closest landing to waypoint
self.halt_at_initialization = True
self.is_halt_at_waypoint = False
self.closest_pad = location.Location(float("inf"), float("inf"))

# Add your own

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============
# self.shortest_distance = [float("inf"), float("inf")]
# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============

def run(
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]"
Expand All @@ -67,8 +70,53 @@ def run(
# ============
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
# ============
def square(number: float) -> float:
return number**2

def squared_distance_from_position(
point: location.Location, current_position: location.Location
) -> float:
distance = square(point.location_x - current_position.location_x) + (
square(point.location_y - current_position.location_y)
)
return distance

# Do something based on the report and the state of this class...
if report.status == drone_status.DroneStatus.HALTED:
if self.halt_at_initialization:

command = commands.Command.create_set_relative_destination_command(
self.waypoint.location_x - report.position.location_x,
self.waypoint.location_y - report.position.location_y,
)
self.halt_at_initialization = False
self.is_halt_at_waypoint = True

elif self.is_halt_at_waypoint:
for landing_pad in landing_pad_locations:
distance_from_position = squared_distance_from_position(
landing_pad, self.waypoint
)
current_shortest_distance = squared_distance_from_position(
self.closest_pad, report.position
)
# self.closest_pad.location_x - report.position.location_x
# ) ** 2 + (self.closest_pad.location_y - report.position.location_y) ** 2
if distance_from_position < current_shortest_distance:
self.closest_pad = landing_pad

command = commands.Command.create_set_relative_destination_command(
self.closest_pad.location_x - report.position.location_x,
self.closest_pad.location_y - report.position.location_y,
)
self.is_halt_at_waypoint = False

elif (
squared_distance_from_position(report.position, self.closest_pad)
<= self.acceptance_radius**2
):

command = commands.Command.create_land_command()

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
Expand Down
20 changes: 11 additions & 9 deletions modules/bootcamp/detect_landing_pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,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 ↑
# ============
Expand Down Expand Up @@ -98,31 +96,35 @@ def run(self, image: np.ndarray) -> "tuple[list[bounding_box.BoundingBox], np.nd
# * conf
# * device
# * verbose
predictions = ...
predictions = self.__model.predict(image, conf=0.7, 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 = ...
for i in range(0, boxes_cpu.shape[0]):
result, box = bounding_box.BoundingBox.create(boxes_cpu[i])
if result:
bounding_boxes.append(box)

return [], image_annotated
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.7 # seconds

# OpenCV ignores your display settings,
# so if the window is too small or too large,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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
#--extra-index-url https://download.pytorch.org/whl/cu124

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