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

Bootcamp Submission - Emily Qi #135

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 27 additions & 1 deletion modules/bootcamp/decision_simple_waypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
# ============

# Add your own
self.has_sent_landing_command = False
self.min_flight_boundary = -60
self.max_flight_boundary = 60

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
Expand Down Expand Up @@ -70,6 +72,30 @@ def run(

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

if (
self.waypoint.location_x >= self.min_flight_boundary
and self.waypoint.location_x <= self.max_flight_boundary
and self.waypoint.location_y >= self.min_flight_boundary
and self.waypoint.location_y <= self.max_flight_boundary
):
distance_from_waypoint = (
self.waypoint.location_x - report.position.location_x
) ** 2 + (self.waypoint.location_y - report.position.location_y) ** 2

if (
report.status == drone_status.DroneStatus.HALTED
and not self.has_sent_landing_command
):

if distance_from_waypoint <= self.acceptance_radius**2:
Copy link
Contributor

Choose a reason for hiding this comment

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

we generally say that an acceptance radius is strictly <, not <=

command = commands.Command.create_land_command()
self.has_sent_landing_command = True

elif distance_from_waypoint > self.acceptance_radius**2:
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need the elif or can it just be an else?

command = commands.Command.create_set_relative_destination_command(
self.waypoint.location_x, self.waypoint.location_y
)

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============
Expand Down
59 changes: 58 additions & 1 deletion modules/bootcamp/decision_waypoint_landing_pads.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,25 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
# ============

# Add your own
self.has_sent_landing_command = False
self.min_flight_boundary = -60
self.max_flight_boundary = 60

self.ready_to_land = False

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

def distance_between_locations(self, other_location: location.Location) -> float:
"""
Calculate the squared distance between two Location objects
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is the distance squared, name it accordingly


return (self.waypoint.location_x - other_location.location_x) ** 2 + (
self.waypoint.location_y - other_location.location_y
) ** 2

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

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

if (
self.waypoint.location_x >= self.min_flight_boundary
and self.waypoint.location_x <= self.max_flight_boundary
and self.waypoint.location_y >= self.min_flight_boundary
and self.waypoint.location_y <= self.max_flight_boundary
):
distance_from_waypoint = (
self.waypoint.location_x - report.position.location_x
) ** 2 + (self.waypoint.location_y - report.position.location_y) ** 2
Copy link
Contributor

Choose a reason for hiding this comment

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

consider using your defined function with report.position as the input


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

if self.ready_to_land:
command = commands.Command.create_land_command()
self.has_sent_landing_command = True

elif (
Copy link
Contributor

Choose a reason for hiding this comment

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

we generally say that an acceptance radius is strictly <, not <=

distance_from_waypoint <= self.acceptance_radius**2
and not self.has_sent_landing_command
):
smallest_distance = 999999999
Copy link
Contributor

Choose a reason for hiding this comment

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

it's generally bad practice to use just a very large number like this - try looking for how to represent infinity in python

smallest_distance_x = 0
smallest_distance_y = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

consider storing the waypoint object instead of the x and y, this also makes is so you don't need to check ready_to_land to avoid landing the drone and (0, 0)


for landing_pad in landing_pad_locations:
if self.distance_between_locations(landing_pad) < smallest_distance:
smallest_distance = self.distance_between_locations(landing_pad)
smallest_distance_x = landing_pad.location_x - self.waypoint.location_x
smallest_distance_y = landing_pad.location_y - self.waypoint.location_y

command = commands.Command.create_set_relative_destination_command(
smallest_distance_x, smallest_distance_y
)

self.ready_to_land = True

elif (
distance_from_waypoint > self.acceptance_radius**2
and not self.has_sent_landing_command
):
command = commands.Command.create_set_relative_destination_command(
self.waypoint.location_x, self.waypoint.location_y
)

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============
Expand Down
26 changes: 15 additions & 11 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,37 @@ 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=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()

# 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, np.shape(boxes_cpu)[0]):

# Create BoundingBox object and append to list
(result, box) = bounding_box.BoundingBox.create(boxes_cpu[i])

if result:
bounding_boxes.append(box)
Comment on lines +126 to +127
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of skipping failed boxes, we want to return no boxes if any of then fail. This is because in data science, when we have corrupted data, we skip the whole data point instead of partial data - in this case, the image is the data point and the boxes are parts of the data


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

# OpenCV ignores your display settings,
# so if the window is too small or too large,
Expand Down
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.4 # seconds

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