-
Notifications
You must be signed in to change notification settings - Fork 266
Arushi's pull request #149
base: main
Are you sure you want to change the base?
Changes from 5 commits
2b4ab39
e3bc1c1
75e2d2d
64ddfa2
30a8381
81a075f
40b438c
a80f03c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,15 +8,12 @@ | |
| from .. import drone_report | ||
|
|
||
| # Disable for bootcamp use | ||
| # pylint: disable-next=unused-import | ||
| from .. import drone_status | ||
| from .. import location | ||
| from ..private.decision import base_decision | ||
|
|
||
|
|
||
| # Disable for bootcamp use | ||
| # No enable | ||
| # pylint: disable=duplicate-code,unused-argument | ||
|
|
||
|
|
||
| class DecisionSimpleWaypoint(base_decision.BaseDecision): | ||
|
|
@@ -39,6 +36,10 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non | |
|
|
||
| # Add your own | ||
|
|
||
| self.has_sent_landing_command = False | ||
| self.min_bounds = -60 | ||
| self.max_bounds = 60 | ||
|
|
||
| # ============ | ||
| # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
| # ============ | ||
|
|
@@ -69,6 +70,28 @@ def run( | |
| # ============ | ||
|
|
||
| # Do something based on the report and the state of this class... | ||
| # ensuring drone is within bounds | ||
| if ( | ||
| self.waypoint.location_x >= self.min_bounds | ||
| and self.waypoint.location_x <= self.max_bounds | ||
| and self.waypoint.location_y >= self.min_bounds | ||
| and self.waypoint.location_y <= self.max_bounds | ||
| ): | ||
| # when the drone is halted but not at the destination | ||
| if ( | ||
| report.status == drone_status.DroneStatus.HALTED | ||
| and report.destination != self.waypoint | ||
| ): | ||
| command = commands.Command.create_set_relative_destination_command( | ||
| self.waypoint.location_x, self.waypoint.location_y | ||
|
||
| ) | ||
| # when the drone is at the destination and is halted | ||
| if ( | ||
| report.status == drone_status.DroneStatus.HALTED | ||
| and report.destination == self.waypoint | ||
|
||
| ): | ||
| command = commands.Command.create_land_command() | ||
| self.has_sent_landing_command = True | ||
|
|
||
| # ============ | ||
| # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,15 +8,12 @@ | |
| from .. import drone_report | ||
|
|
||
| # Disable for bootcamp use | ||
| # pylint: disable-next=unused-import | ||
| from .. import drone_status | ||
| from .. import location | ||
| from ..private.decision import base_decision | ||
|
|
||
|
|
||
| # Disable for bootcamp use | ||
| # No enable | ||
| # pylint: disable=duplicate-code,unused-argument | ||
|
|
||
|
|
||
| class DecisionWaypointLandingPads(base_decision.BaseDecision): | ||
|
|
@@ -38,11 +35,21 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non | |
| # ============ | ||
|
|
||
| # Add your own | ||
| self.has_sent_landing_command = False | ||
| self.min_bounds = -60 | ||
| self.max_bounds = 60 | ||
|
|
||
| # ============ | ||
| # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
| # ============ | ||
|
|
||
| def min_dist_squared(self, landing_pads: location.Location) -> float: | ||
|
||
| """returns distance squared""" | ||
| dist = (self.waypoint.location_x - landing_pads.location_x) ** 2 + ( | ||
| self.waypoint.location_y - landing_pads.location_y | ||
| ) ** 2 | ||
| return dist | ||
|
|
||
| def run( | ||
| self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]" | ||
| ) -> commands.Command: | ||
|
|
@@ -69,6 +76,43 @@ def run( | |
| # ============ | ||
|
|
||
| # Do something based on the report and the state of this class... | ||
| if ( | ||
| self.waypoint.location_x >= self.min_bounds | ||
| and self.waypoint.location_x <= self.max_bounds | ||
| and self.waypoint.location_y >= self.min_bounds | ||
| and self.waypoint.location_y <= self.max_bounds | ||
| ): | ||
| proximity = (self.waypoint.location_x - report.position.location_x) ** 2 + ( | ||
| self.waypoint.location_y - report.position.location_y | ||
| ) ** 2 | ||
|
||
| new_pad = location.Location(0, 0) | ||
| # checking if the drone is halted | ||
| if report.status == drone_status.DroneStatus.HALTED: | ||
|
|
||
| # when drone is at the nearest landing pad | ||
| if self.has_sent_landing_command: | ||
|
||
| command = commands.Command.create_land_command() | ||
|
|
||
| # finding nearest landing pad and setting relative destination | ||
| elif not self.has_sent_landing_command and proximity < self.acceptance_radius**2: | ||
maxlou05 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| smallest_dist = float("inf") | ||
| for landing_pads in landing_pad_locations: | ||
| new_dist = self.min_dist_squared(landing_pads) | ||
| if new_dist < smallest_dist: | ||
| smallest_dist = new_dist | ||
| new_pad = landing_pads | ||
|
|
||
| command = commands.Command.create_set_relative_destination_command( | ||
| new_pad.location_x - self.waypoint.location_x, | ||
|
||
| new_pad.location_y - self.waypoint.location_y, | ||
| ) | ||
| self.has_sent_landing_command = True | ||
|
|
||
| # setting relative destination to designated waypoint | ||
| elif proximity > self.acceptance_radius and not self.has_sent_landing_command: | ||
|
||
| command = commands.Command.create_set_relative_destination_command( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you know that you should go to the waypoint and not the landing pad? What if you were en route towards the landing pad? |
||
| self.waypoint.location_x, self.waypoint.location_y | ||
|
||
| ) | ||
|
|
||
| # ============ | ||
| # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 ↑ | ||
| # ============ | ||
|
|
@@ -98,31 +96,42 @@ def run(self, image: np.ndarray) -> "tuple[list[bounding_box.BoundingBox], np.nd | |
| # * conf | ||
| # * device | ||
| # * verbose | ||
| predictions = ... | ||
| # model = ultralytics.YOLO("yolov8n.pt") | ||
|
||
| 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 = ... | ||
| # result, box = ... | ||
| # result=0 | ||
|
|
||
| for i in range(0, np.shape(boxes_cpu)[0]): | ||
|
|
||
| (result, box) = bounding_box.BoundingBox.create(boxes_cpu[i]) | ||
|
|
||
| if result: | ||
| bounding_boxes.append(box) | ||
| else: | ||
| return [], image_annotated | ||
|
|
||
| return [], image_annotated | ||
| return bounding_boxes, image_annotated | ||
| # ============ | ||
| # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
| # ============ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than using direct equality comparison of floating point numbers (which are not very accurate and may not give you the result you want), you should use the
self.acceptance_radiusas a guide.