This repository was archived by the owner on Sep 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 266
Tanmay Shah #114
Open
TanMan-CAL
wants to merge
2
commits into
UWARG:main
Choose a base branch
from
TanMan-CAL:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Tanmay Shah #114
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| """ | ||
| BOOTCAMPERS TO COMPLETE. | ||
|
|
||
| Travel to designated waypoint and then land at a nearby landing pad. | ||
| Travel to the designated waypoint and then land at a nearby landing pad. | ||
| """ | ||
|
|
||
| from .. import commands | ||
|
|
@@ -21,7 +21,7 @@ | |
|
|
||
| class DecisionWaypointLandingPads(base_decision.BaseDecision): | ||
| """ | ||
| Travel to the designed waypoint and then land at the nearest landing pad. | ||
| Travel to the designated waypoint and then land at the nearest landing pad. | ||
| """ | ||
|
|
||
| def __init__(self, waypoint: location.Location, acceptance_radius: float) -> None: | ||
|
|
@@ -33,25 +33,25 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non | |
|
|
||
| self.acceptance_radius = acceptance_radius | ||
|
|
||
| # ============ | ||
| # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
| # ============ | ||
| self.halt_at_initialization = True | ||
| self.has_reached_waypoint = False | ||
| self.closest_landing_pad = None | ||
|
|
||
| # Add your own | ||
|
|
||
| # ============ | ||
| # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
| # ============ | ||
| def squared_distance(self, point1: location.Location, point2: location.Location) -> float: | ||
| """ | ||
| Calculate the squared distance between two locations. | ||
| """ | ||
| diff_distance_x = point1.location_x - point2.location_x | ||
| diff_distance_y = point1.location_y - point2.location_y | ||
| distance_net_squared = (diff_distance_x**2) + (diff_distance_y**2) | ||
| return distance_net_squared | ||
|
|
||
| def run( | ||
| self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]" | ||
| ) -> commands.Command: | ||
| """ | ||
| Make the drone fly to the waypoint and then land at the nearest landing pad. | ||
|
|
||
| You are allowed to create as many helper methods as you want, | ||
| as long as you do not change the __init__() and run() signatures. | ||
|
|
||
| This method will be called in an infinite loop, something like this: | ||
|
|
||
| ```py | ||
|
|
@@ -61,17 +61,55 @@ def run( | |
| put_output(command) | ||
| ``` | ||
| """ | ||
| # Default command | ||
| command = commands.Command.create_null_command() | ||
|
|
||
| # ============ | ||
| # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
| # ============ | ||
|
|
||
| # Do something based on the report and the state of this class... | ||
|
|
||
| # ============ | ||
| # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
| # ============ | ||
|
|
||
| # get current position | ||
| current_position = report.position | ||
| distance_net_squared = self.squared_distance(self.waypoint, current_position) | ||
|
|
||
| if report.status == drone_status.DroneStatus.HALTED: | ||
| # check if at the waypoint | ||
| if not self.has_reached_waypoint and distance_net_squared <= self.acceptance_radius**2: | ||
| command = commands.Command.create_land_command() | ||
| print("Drone is landing at the waypoint!") | ||
| self.has_reached_waypoint = True | ||
|
|
||
| elif not self.has_reached_waypoint: | ||
| diff_distance_x = self.waypoint.location_x - current_position.location_x | ||
| diff_distance_y = self.waypoint.location_y - current_position.location_y | ||
| command = commands.Command.create_set_relative_destination_command( | ||
| diff_distance_x, diff_distance_y | ||
| ) | ||
| print("Going to waypoint!") | ||
| self.has_reached_waypoint = False | ||
|
|
||
| # find the closest landing pad | ||
| if self.has_reached_waypoint and not self.closest_landing_pad: | ||
| closest_distance_squared = float("inf") # infinity | ||
|
|
||
| for landing_pad in landing_pad_locations: | ||
| distance_from_waypoint_squared = self.squared_distance( | ||
| landing_pad, self.waypoint | ||
| ) | ||
|
|
||
| # update closest_landing_pad | ||
| if distance_from_waypoint_squared < closest_distance_squared: | ||
| closest_distance_squared = distance_from_waypoint_squared | ||
| self.closest_landing_pad = landing_pad | ||
|
|
||
| # EGDE CASE: landing pad is on the waypoint | ||
| if closest_distance_squared == 0: | ||
| command = commands.Command.create_land_command() | ||
| print("Drone is landing directly on the waypoint!") | ||
| else: | ||
| diff_distance_x = ( | ||
| self.closest_landing_pad.location_x - current_position.location_x | ||
| ) | ||
| diff_distance_y = ( | ||
| self.closest_landing_pad.location_y - current_position.location_y | ||
| ) | ||
| command = commands.Command.create_set_relative_destination_command( | ||
| diff_distance_x, diff_distance_y | ||
| ) | ||
| print("Moving to closest landing pad!") | ||
|
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. There doesn't seem to be an implementation for actually reaching and landing on the landing pad, this just gets the drone to move towards the closest landing pad |
||
| return command | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,7 @@ | |
| # 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 ↑ | ||
| # ============ | ||
|
|
||
|
|
@@ -94,35 +93,38 @@ def run(self, image: np.ndarray) -> "tuple[list[bounding_box.BoundingBox], np.nd | |
|
|
||
| # Use the model's predict() method to run inference | ||
| # Parameters of interest: | ||
| # * source | ||
| # * conf | ||
| # * device | ||
| # * source: image | ||
| # * conf: 0.7 as outlined by the bootcamp | ||
| # * device: | ||
| # * verbose | ||
| predictions = ... | ||
| predictions = self.__model.predict(image, conf=0.7, device=self.__DEVICE, verbose=False) | ||
|
|
||
| # Get the Result object | ||
| prediction = ... | ||
| # Get the Result object: need to loop through the predictions | ||
| prediction = predictions[0] | ||
|
|
||
| # Plot the annotated image from the Result object | ||
| # Include the confidence value | ||
| image_annotated = ... | ||
| # Include the confidence value --> defaulted to be true anyways | ||
| image_annotated = prediction.plot() | ||
|
|
||
| # Get the xyxy boxes list from the Boxes object in the Result object | ||
| boxes_xyxy = ... | ||
| boxes_xyxy = prediction.boxes.xyxy | ||
| # boxes.xyxyn not needed | ||
|
|
||
| # 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(0, boxes_cpu.shape[0]): | ||
| # Create BoundingBox object and append to list | ||
| result, box = bounding_box.BoundingBox.create(boxes_cpu[i]) | ||
| if result: # this way only valid boxes are added | ||
|
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. Normally in statistics, we discard the whole datapoint (the entire image) if a part of it goes wrong (one bounding box). |
||
| bounding_boxes.append(box) | ||
|
|
||
| return bounding_boxes, image_annotated | ||
| # ============ | ||
| # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
| # ============ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You don't need to land at the waypoint, just get there and then go towards the landing pad (you land at the landing pad)