From f9afc28fc7cf4de6cc959ef814b6e22580a3c042 Mon Sep 17 00:00:00 2001 From: Lucas Kim Date: Tue, 10 Sep 2024 15:40:15 -0400 Subject: [PATCH 01/14] Remove --extra-index-url line from requirements.txt --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fa1ed662..c98debf1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,7 +17,6 @@ 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 # ============ # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ From 8859512091abf01fa8a3af83ff7e4cee9b9862b0 Mon Sep 17 00:00:00 2001 From: Lucas Kim Date: Tue, 10 Sep 2024 15:52:16 -0400 Subject: [PATCH 02/14] Task 1: Implement ML inference --- modules/bootcamp/detect_landing_pad.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/modules/bootcamp/detect_landing_pad.py b/modules/bootcamp/detect_landing_pad.py index f17aa677..dc5cde2e 100644 --- a/modules/bootcamp/detect_landing_pad.py +++ b/modules/bootcamp/detect_landing_pad.py @@ -19,7 +19,6 @@ # 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 +97,38 @@ 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.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 xyxy_box in boxes_cpu: + # Create BoundingBox object and append to list + _, box = bounding_box.BoundingBox.create(xyxy_box) + + if box is None: + continue + + bounding_boxes.append(box) - return [], image_annotated + return bounding_boxes, image_annotated # ============ # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ # ============ From 4be946d52f5653f9c9fa9596a70dd46344872c27 Mon Sep 17 00:00:00 2001 From: Lucas Kim Date: Wed, 18 Sep 2024 19:14:10 -0400 Subject: [PATCH 03/14] Change verbose to False --- modules/bootcamp/detect_landing_pad.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/bootcamp/detect_landing_pad.py b/modules/bootcamp/detect_landing_pad.py index dc5cde2e..9ca8d816 100644 --- a/modules/bootcamp/detect_landing_pad.py +++ b/modules/bootcamp/detect_landing_pad.py @@ -98,7 +98,7 @@ def run(self, image: np.ndarray) -> "tuple[list[bounding_box.BoundingBox], np.nd # * device # * verbose predictions = self.__model.predict( - source=image, conf=0.7, device=self.__DEVICE, verbose=True + source=image, conf=0.7, device=self.__DEVICE, verbose=False ) # Get the Result object From f549fca0df96113e2cbfbba8ad31f5f56727d0bb Mon Sep 17 00:00:00 2001 From: Lucas Kim Date: Thu, 19 Sep 2024 17:32:18 -0400 Subject: [PATCH 04/14] Complete Task 3: making the drone move to and land at a waypoint --- modules/bootcamp/decision_simple_waypoint.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/bootcamp/decision_simple_waypoint.py b/modules/bootcamp/decision_simple_waypoint.py index 26098c2e..3096e5b5 100644 --- a/modules/bootcamp/decision_simple_waypoint.py +++ b/modules/bootcamp/decision_simple_waypoint.py @@ -68,7 +68,17 @@ def run( # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ # ============ - # Do something based on the report and the state of this class... + ALLOWED_ERROR = 0.1 + + # Calculate relative x and y distance required to reach waypoint + relative_x = self.waypoint.location_x - report.position.location_x + relative_y = self.waypoint.location_y - report.position.location_y + if report.status == drone_status.DroneStatus.HALTED: + # Check if the waypoint has already been reached + if abs(relative_x) < ALLOWED_ERROR and abs(relative_y) < ALLOWED_ERROR: + command = commands.Command.create_land_command() + else: + command = commands.Command.create_set_relative_destination_command(relative_x, relative_y) # ============ # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ From 0ddbeede5cbcaecdfeaf1ada55238fc90cf7b068 Mon Sep 17 00:00:00 2001 From: Lucas Kim Date: Thu, 19 Sep 2024 17:58:17 -0400 Subject: [PATCH 05/14] Complete Task 4: Putting it all together --- modules/bootcamp/decision_simple_waypoint.py | 13 ++++---- .../decision_waypoint_landing_pads.py | 30 +++++++++++++++++-- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/modules/bootcamp/decision_simple_waypoint.py b/modules/bootcamp/decision_simple_waypoint.py index 3096e5b5..cb378ad0 100644 --- a/modules/bootcamp/decision_simple_waypoint.py +++ b/modules/bootcamp/decision_simple_waypoint.py @@ -37,8 +37,6 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ # ============ - # Add your own - # ============ # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ # ============ @@ -68,16 +66,19 @@ def run( # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ # ============ - ALLOWED_ERROR = 0.1 + allowed_error = 0.1 # Calculate relative x and y distance required to reach waypoint - relative_x = self.waypoint.location_x - report.position.location_x - relative_y = self.waypoint.location_y - report.position.location_y if report.status == drone_status.DroneStatus.HALTED: + relative_x = self.waypoint.location_x - report.position.location_x + relative_y = self.waypoint.location_y - report.position.location_y + # Check if the waypoint has already been reached - if abs(relative_x) < ALLOWED_ERROR and abs(relative_y) < ALLOWED_ERROR: + if abs(relative_x) < allowed_error and abs(relative_y) < allowed_error: command = commands.Command.create_land_command() else: + relative_x = self.waypoint.location_x - report.position.location_x + relative_y = self.waypoint.location_y - report.position.location_y command = commands.Command.create_set_relative_destination_command(relative_x, relative_y) # ============ diff --git a/modules/bootcamp/decision_waypoint_landing_pads.py b/modules/bootcamp/decision_waypoint_landing_pads.py index ade6f118..5bbf9826 100644 --- a/modules/bootcamp/decision_waypoint_landing_pads.py +++ b/modules/bootcamp/decision_waypoint_landing_pads.py @@ -13,6 +13,7 @@ from .. import location from ..private.decision import base_decision +import math # Disable for bootcamp use # No enable @@ -37,7 +38,8 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ # ============ - # Add your own + self.started_moving_to_waypoint = False + self.started_moving_to_landing_pad = False # ============ # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ @@ -68,10 +70,34 @@ def run( # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ # ============ - # Do something based on the report and the state of this class... + # Calculate relative x and y distance required to reach waypoint + if report.status == drone_status.DroneStatus.HALTED: + # Check if the waypoint has already been reached + if self.started_moving_to_landing_pad: + command = commands.Command.create_land_command() + elif self.started_moving_to_waypoint: + closest_landing_pad = min(landing_pad_locations, key=lambda pad: self.__distance_between_locations(report.position, pad)) + relative_x = closest_landing_pad.location_x - report.position.location_x + relative_y = closest_landing_pad.location_y - report.position.location_y + + command = commands.Command.create_set_relative_destination_command(relative_x, relative_y) + self.started_moving_to_landing_pad = True + else: + relative_x = self.waypoint.location_x - report.position.location_x + relative_y = self.waypoint.location_y - report.position.location_y + + command = commands.Command.create_set_relative_destination_command(relative_x, relative_y) + self.started_moving_to_waypoint = True # ============ # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ # ============ return command + + def __distance_between_locations(self, location1: location.Location, location2: location.Location): + """ + Calculate the distance between two Location objects. + """ + + return math.sqrt(((location2.location_x - location1.location_x) ** 2) + ((location2.location_y - location2.location_x) ** 2)) \ No newline at end of file From fa467cd4f887067de42651a71ddc9c6147395198 Mon Sep 17 00:00:00 2001 From: Lucas Kim Date: Thu, 19 Sep 2024 18:00:02 -0400 Subject: [PATCH 06/14] Run formatters and linters --- modules/bootcamp/decision_simple_waypoint.py | 4 ++- .../decision_waypoint_landing_pads.py | 30 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/modules/bootcamp/decision_simple_waypoint.py b/modules/bootcamp/decision_simple_waypoint.py index cb378ad0..a21aa5d1 100644 --- a/modules/bootcamp/decision_simple_waypoint.py +++ b/modules/bootcamp/decision_simple_waypoint.py @@ -79,7 +79,9 @@ def run( else: relative_x = self.waypoint.location_x - report.position.location_x relative_y = self.waypoint.location_y - report.position.location_y - command = commands.Command.create_set_relative_destination_command(relative_x, relative_y) + command = commands.Command.create_set_relative_destination_command( + relative_x, relative_y + ) # ============ # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ diff --git a/modules/bootcamp/decision_waypoint_landing_pads.py b/modules/bootcamp/decision_waypoint_landing_pads.py index 5bbf9826..faae7cf5 100644 --- a/modules/bootcamp/decision_waypoint_landing_pads.py +++ b/modules/bootcamp/decision_waypoint_landing_pads.py @@ -4,6 +4,8 @@ Travel to designated waypoint and then land at a nearby landing pad. """ +import math + from .. import commands from .. import drone_report @@ -13,8 +15,6 @@ from .. import location from ..private.decision import base_decision -import math - # Disable for bootcamp use # No enable # pylint: disable=duplicate-code,unused-argument @@ -76,17 +76,24 @@ def run( if self.started_moving_to_landing_pad: command = commands.Command.create_land_command() elif self.started_moving_to_waypoint: - closest_landing_pad = min(landing_pad_locations, key=lambda pad: self.__distance_between_locations(report.position, pad)) + closest_landing_pad = min( + landing_pad_locations, + key=lambda pad: self.__distance_between_locations(report.position, pad), + ) relative_x = closest_landing_pad.location_x - report.position.location_x relative_y = closest_landing_pad.location_y - report.position.location_y - - command = commands.Command.create_set_relative_destination_command(relative_x, relative_y) + + command = commands.Command.create_set_relative_destination_command( + relative_x, relative_y + ) self.started_moving_to_landing_pad = True else: relative_x = self.waypoint.location_x - report.position.location_x relative_y = self.waypoint.location_y - report.position.location_y - - command = commands.Command.create_set_relative_destination_command(relative_x, relative_y) + + command = commands.Command.create_set_relative_destination_command( + relative_x, relative_y + ) self.started_moving_to_waypoint = True # ============ @@ -95,9 +102,14 @@ def run( return command - def __distance_between_locations(self, location1: location.Location, location2: location.Location): + def __distance_between_locations( + self, location1: location.Location, location2: location.Location + ) -> float: """ Calculate the distance between two Location objects. """ - return math.sqrt(((location2.location_x - location1.location_x) ** 2) + ((location2.location_y - location2.location_x) ** 2)) \ No newline at end of file + return math.sqrt( + ((location2.location_x - location1.location_x) ** 2) + + ((location2.location_y - location2.location_x) ** 2) + ) From 9eadad138b9f02cf3b69b5c6a4b8afe770afa0d0 Mon Sep 17 00:00:00 2001 From: Lucas Kim Date: Thu, 19 Sep 2024 18:03:41 -0400 Subject: [PATCH 07/14] Fix comments --- modules/bootcamp/decision_simple_waypoint.py | 2 +- modules/bootcamp/decision_waypoint_landing_pads.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/bootcamp/decision_simple_waypoint.py b/modules/bootcamp/decision_simple_waypoint.py index a21aa5d1..dcc0f677 100644 --- a/modules/bootcamp/decision_simple_waypoint.py +++ b/modules/bootcamp/decision_simple_waypoint.py @@ -68,8 +68,8 @@ def run( allowed_error = 0.1 - # Calculate relative x and y distance required to reach waypoint if report.status == drone_status.DroneStatus.HALTED: + # Calculate relative x and y distance required to reach waypoint relative_x = self.waypoint.location_x - report.position.location_x relative_y = self.waypoint.location_y - report.position.location_y diff --git a/modules/bootcamp/decision_waypoint_landing_pads.py b/modules/bootcamp/decision_waypoint_landing_pads.py index faae7cf5..e6abe488 100644 --- a/modules/bootcamp/decision_waypoint_landing_pads.py +++ b/modules/bootcamp/decision_waypoint_landing_pads.py @@ -70,7 +70,6 @@ def run( # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ # ============ - # Calculate relative x and y distance required to reach waypoint if report.status == drone_status.DroneStatus.HALTED: # Check if the waypoint has already been reached if self.started_moving_to_landing_pad: @@ -80,6 +79,8 @@ def run( landing_pad_locations, key=lambda pad: self.__distance_between_locations(report.position, pad), ) + + # Calculate relative x and y distance required to reach landing pad relative_x = closest_landing_pad.location_x - report.position.location_x relative_y = closest_landing_pad.location_y - report.position.location_y @@ -88,6 +89,7 @@ def run( ) self.started_moving_to_landing_pad = True else: + # Calculate relative x and y distance required to reach waypoint relative_x = self.waypoint.location_x - report.position.location_x relative_y = self.waypoint.location_y - report.position.location_y From 2d19edc39b8025e1679d6532d01dc2e97e8a227e Mon Sep 17 00:00:00 2001 From: Lucas Kim Date: Fri, 20 Sep 2024 08:51:44 -0400 Subject: [PATCH 08/14] Find closest landing pad without using sqrt --- modules/bootcamp/decision_waypoint_landing_pads.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/modules/bootcamp/decision_waypoint_landing_pads.py b/modules/bootcamp/decision_waypoint_landing_pads.py index e6abe488..77016974 100644 --- a/modules/bootcamp/decision_waypoint_landing_pads.py +++ b/modules/bootcamp/decision_waypoint_landing_pads.py @@ -4,8 +4,6 @@ Travel to designated waypoint and then land at a nearby landing pad. """ -import math - from .. import commands from .. import drone_report @@ -77,7 +75,7 @@ def run( elif self.started_moving_to_waypoint: closest_landing_pad = min( landing_pad_locations, - key=lambda pad: self.__distance_between_locations(report.position, pad), + key=lambda pad: self.__squared_distance(report.position, pad), ) # Calculate relative x and y distance required to reach landing pad @@ -104,14 +102,13 @@ def run( return command - def __distance_between_locations( + def __squared_distance( self, location1: location.Location, location2: location.Location ) -> float: """ Calculate the distance between two Location objects. """ - return math.sqrt( - ((location2.location_x - location1.location_x) ** 2) - + ((location2.location_y - location2.location_x) ** 2) + return ((location2.location_x - location1.location_x) ** 2) + ( + (location2.location_y - location2.location_x) ** 2 ) From bf526d3bd77c0c30befba9cc0cbd8119deedc60b Mon Sep 17 00:00:00 2001 From: Lucas Kim Date: Fri, 20 Sep 2024 08:55:52 -0400 Subject: [PATCH 09/14] Switch to using Euclidean distance --- modules/bootcamp/decision_simple_waypoint.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/bootcamp/decision_simple_waypoint.py b/modules/bootcamp/decision_simple_waypoint.py index dcc0f677..0aafa226 100644 --- a/modules/bootcamp/decision_simple_waypoint.py +++ b/modules/bootcamp/decision_simple_waypoint.py @@ -66,15 +66,11 @@ def run( # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ # ============ - allowed_error = 0.1 + allowed_error = 0.01 if report.status == drone_status.DroneStatus.HALTED: - # Calculate relative x and y distance required to reach waypoint - relative_x = self.waypoint.location_x - report.position.location_x - relative_y = self.waypoint.location_y - report.position.location_y - # Check if the waypoint has already been reached - if abs(relative_x) < allowed_error and abs(relative_y) < allowed_error: + if self.__squared_distance(self.waypoint, report.position) < allowed_error: command = commands.Command.create_land_command() else: relative_x = self.waypoint.location_x - report.position.location_x @@ -88,3 +84,14 @@ def run( # ============ return command + + def __squared_distance( + self, location1: location.Location, location2: location.Location + ) -> float: + """ + Calculate the distance between two Location objects. + """ + + return ((location2.location_x - location1.location_x) ** 2) + ( + (location2.location_y - location2.location_x) ** 2 + ) From 37ba7972b81a5278adc17e279c286d93deae0025 Mon Sep 17 00:00:00 2001 From: Lucas Kim Date: Fri, 20 Sep 2024 08:59:21 -0400 Subject: [PATCH 10/14] Use success indicator from BoundingBox.create --- modules/bootcamp/detect_landing_pad.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/bootcamp/detect_landing_pad.py b/modules/bootcamp/detect_landing_pad.py index 9ca8d816..60e84589 100644 --- a/modules/bootcamp/detect_landing_pad.py +++ b/modules/bootcamp/detect_landing_pad.py @@ -118,12 +118,11 @@ def run(self, image: np.ndarray) -> "tuple[list[bounding_box.BoundingBox], np.nd # Loop over the boxes list and create a list of bounding boxes bounding_boxes = [] - # Hint: .shape gets the dimensions of the numpy array for xyxy_box in boxes_cpu: # Create BoundingBox object and append to list - _, box = bounding_box.BoundingBox.create(xyxy_box) + success, box = bounding_box.BoundingBox.create(xyxy_box) - if box is None: + if not success: continue bounding_boxes.append(box) From 49ec15faa1a1b9a78953f070b9666c63252dd540 Mon Sep 17 00:00:00 2001 From: Lucas Kim Date: Fri, 20 Sep 2024 09:10:57 -0400 Subject: [PATCH 11/14] Check if within acceptance radius of waypoint and fix squared distance --- modules/bootcamp/decision_simple_waypoint.py | 2 +- .../decision_waypoint_landing_pads.py | 30 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/modules/bootcamp/decision_simple_waypoint.py b/modules/bootcamp/decision_simple_waypoint.py index 0aafa226..72e972bc 100644 --- a/modules/bootcamp/decision_simple_waypoint.py +++ b/modules/bootcamp/decision_simple_waypoint.py @@ -93,5 +93,5 @@ def __squared_distance( """ return ((location2.location_x - location1.location_x) ** 2) + ( - (location2.location_y - location2.location_x) ** 2 + (location2.location_y - location1.location_y) ** 2 ) diff --git a/modules/bootcamp/decision_waypoint_landing_pads.py b/modules/bootcamp/decision_waypoint_landing_pads.py index 77016974..fcb94be7 100644 --- a/modules/bootcamp/decision_waypoint_landing_pads.py +++ b/modules/bootcamp/decision_waypoint_landing_pads.py @@ -36,8 +36,7 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ # ============ - self.started_moving_to_waypoint = False - self.started_moving_to_landing_pad = False + self.has_reached_waypoint = False # ============ # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ @@ -68,16 +67,21 @@ def run( # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ # ============ + allowed_error = 0.01 + if report.status == drone_status.DroneStatus.HALTED: - # Check if the waypoint has already been reached - if self.started_moving_to_landing_pad: + closest_landing_pad = min( + landing_pad_locations, + key=lambda pad: self.__squared_distance(report.position, pad), + ) + + # Check if the landing pad or waypoint has already been reached + if ( + self.__squared_distance(report.position, closest_landing_pad) < allowed_error + and self.has_reached_waypoint + ): command = commands.Command.create_land_command() - elif self.started_moving_to_waypoint: - closest_landing_pad = min( - landing_pad_locations, - key=lambda pad: self.__squared_distance(report.position, pad), - ) - + elif self.__squared_distance(report.position, self.waypoint) < allowed_error: # Calculate relative x and y distance required to reach landing pad relative_x = closest_landing_pad.location_x - report.position.location_x relative_y = closest_landing_pad.location_y - report.position.location_y @@ -85,7 +89,8 @@ def run( command = commands.Command.create_set_relative_destination_command( relative_x, relative_y ) - self.started_moving_to_landing_pad = True + + self.has_reached_waypoint = True else: # Calculate relative x and y distance required to reach waypoint relative_x = self.waypoint.location_x - report.position.location_x @@ -94,7 +99,6 @@ def run( command = commands.Command.create_set_relative_destination_command( relative_x, relative_y ) - self.started_moving_to_waypoint = True # ============ # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ @@ -110,5 +114,5 @@ def __squared_distance( """ return ((location2.location_x - location1.location_x) ** 2) + ( - (location2.location_y - location2.location_x) ** 2 + (location2.location_y - location1.location_y) ** 2 ) From 49ac6e7f9dc32a5f3439286c848653d823a364f1 Mon Sep 17 00:00:00 2001 From: Lucas Kim Date: Sat, 21 Sep 2024 11:27:32 -0400 Subject: [PATCH 12/14] Use acceptance_radius --- modules/bootcamp/decision_simple_waypoint.py | 4 ++-- modules/bootcamp/decision_waypoint_landing_pads.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/bootcamp/decision_simple_waypoint.py b/modules/bootcamp/decision_simple_waypoint.py index 72e972bc..1f8e4292 100644 --- a/modules/bootcamp/decision_simple_waypoint.py +++ b/modules/bootcamp/decision_simple_waypoint.py @@ -66,9 +66,9 @@ def run( # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ # ============ - allowed_error = 0.01 - if report.status == drone_status.DroneStatus.HALTED: + allowed_error = self.acceptance_radius ** 2 + # Check if the waypoint has already been reached if self.__squared_distance(self.waypoint, report.position) < allowed_error: command = commands.Command.create_land_command() diff --git a/modules/bootcamp/decision_waypoint_landing_pads.py b/modules/bootcamp/decision_waypoint_landing_pads.py index fcb94be7..56906e0e 100644 --- a/modules/bootcamp/decision_waypoint_landing_pads.py +++ b/modules/bootcamp/decision_waypoint_landing_pads.py @@ -67,9 +67,9 @@ def run( # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ # ============ - allowed_error = 0.01 - if report.status == drone_status.DroneStatus.HALTED: + allowed_error = self.acceptance_radius ** 2 + closest_landing_pad = min( landing_pad_locations, key=lambda pad: self.__squared_distance(report.position, pad), From 09557ecfb831677d83de4450b599fecb948699cb Mon Sep 17 00:00:00 2001 From: Lucas Kim Date: Sat, 21 Sep 2024 11:44:00 -0400 Subject: [PATCH 13/14] Move landing pad calculation back in conditions and fix acceptance radius check --- .../decision_waypoint_landing_pads.py | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/modules/bootcamp/decision_waypoint_landing_pads.py b/modules/bootcamp/decision_waypoint_landing_pads.py index 56906e0e..5189fabe 100644 --- a/modules/bootcamp/decision_waypoint_landing_pads.py +++ b/modules/bootcamp/decision_waypoint_landing_pads.py @@ -37,6 +37,7 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non # ============ self.has_reached_waypoint = False + self.closest_landing_pad = None # ============ # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ @@ -70,21 +71,27 @@ def run( if report.status == drone_status.DroneStatus.HALTED: allowed_error = self.acceptance_radius ** 2 - closest_landing_pad = min( - landing_pad_locations, - key=lambda pad: self.__squared_distance(report.position, pad), - ) - # Check if the landing pad or waypoint has already been reached - if ( - self.__squared_distance(report.position, closest_landing_pad) < allowed_error - and self.has_reached_waypoint - ): - command = commands.Command.create_land_command() + if self.has_reached_waypoint: + # Make sure the landing pad has actually been reached; otherwise send another set relative destination command + if self.__squared_distance(report.position, self.closest_landing_pad) < allowed_error: + command = commands.Command.create_land_command() + else: + relative_x = self.closest_landing_pad.location_x - report.position.location_x + relative_y = self.closest_landing_pad.location_y - report.position.location_y + + command = commands.Command.create_set_relative_destination_command( + relative_x, relative_y + ) elif self.__squared_distance(report.position, self.waypoint) < allowed_error: + self.closest_landing_pad = min( + landing_pad_locations, + key=lambda pad: self.__squared_distance(report.position, pad), + ) + # Calculate relative x and y distance required to reach landing pad - relative_x = closest_landing_pad.location_x - report.position.location_x - relative_y = closest_landing_pad.location_y - report.position.location_y + relative_x = self.closest_landing_pad.location_x - report.position.location_x + relative_y = self.closest_landing_pad.location_y - report.position.location_y command = commands.Command.create_set_relative_destination_command( relative_x, relative_y From d30b4bc0ab9cc7fa419eb51b8ce49b3f11412ef9 Mon Sep 17 00:00:00 2001 From: Lucas Kim Date: Sat, 21 Sep 2024 11:44:46 -0400 Subject: [PATCH 14/14] Run linters and formatters --- modules/bootcamp/decision_simple_waypoint.py | 2 +- modules/bootcamp/decision_waypoint_landing_pads.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/bootcamp/decision_simple_waypoint.py b/modules/bootcamp/decision_simple_waypoint.py index 1f8e4292..045f56d8 100644 --- a/modules/bootcamp/decision_simple_waypoint.py +++ b/modules/bootcamp/decision_simple_waypoint.py @@ -67,7 +67,7 @@ def run( # ============ if report.status == drone_status.DroneStatus.HALTED: - allowed_error = self.acceptance_radius ** 2 + allowed_error = self.acceptance_radius**2 # Check if the waypoint has already been reached if self.__squared_distance(self.waypoint, report.position) < allowed_error: diff --git a/modules/bootcamp/decision_waypoint_landing_pads.py b/modules/bootcamp/decision_waypoint_landing_pads.py index 5189fabe..9142aed9 100644 --- a/modules/bootcamp/decision_waypoint_landing_pads.py +++ b/modules/bootcamp/decision_waypoint_landing_pads.py @@ -69,12 +69,15 @@ def run( # ============ if report.status == drone_status.DroneStatus.HALTED: - allowed_error = self.acceptance_radius ** 2 + allowed_error = self.acceptance_radius**2 # Check if the landing pad or waypoint has already been reached if self.has_reached_waypoint: # Make sure the landing pad has actually been reached; otherwise send another set relative destination command - if self.__squared_distance(report.position, self.closest_landing_pad) < allowed_error: + if ( + self.__squared_distance(report.position, self.closest_landing_pad) + < allowed_error + ): command = commands.Command.create_land_command() else: relative_x = self.closest_landing_pad.location_x - report.position.location_x