-
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 all 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 DecisionWaypointLandingPads(base_decision.BaseDecision): | ||
|
|
@@ -38,11 +35,25 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non | |
| # ============ | ||
|
|
||
| # Add your own | ||
| self.has_sent_landing_command = False | ||
| self.send_landing_command = False | ||
| self.reached_landing_pad = False | ||
| self.min_bounds = -60 | ||
| self.max_bounds = 60 | ||
|
|
||
| # ============ | ||
| # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
| # ============ | ||
|
|
||
| def distance_to_pad_squared( | ||
| self, report: drone_report.DroneReport, landing_pad: location.Location | ||
| ) -> float: | ||
| """returns distance squared""" | ||
| dist = (report.position.location_x - landing_pad.location_x) ** 2 + ( | ||
| report.position.location_y - landing_pad.location_y | ||
| ) ** 2 | ||
| return dist | ||
|
|
||
| def run( | ||
| self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]" | ||
| ) -> commands.Command: | ||
|
|
@@ -69,6 +80,59 @@ 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 | ||
| ): | ||
|
|
||
| if report.status == drone_status.DroneStatus.HALTED: | ||
|
|
||
| if self.send_landing_command: | ||
| command = commands.Command.create_land_command() | ||
| self.has_sent_landing_command = True | ||
| return command | ||
|
|
||
| # calculating location of nearest landing pad | ||
| smallest_dist_x = float("inf") | ||
| smallest_dist_y = float("inf") | ||
| smallest_dist = smallest_dist_x**2 + smallest_dist_y**2 | ||
|
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. You can just set it to infinity, as you don't really need to calculate infinity squared |
||
| for landing_pad in landing_pad_locations: | ||
| new_dist = self.distance_to_pad_squared(report, landing_pad) | ||
| if new_dist < smallest_dist: | ||
| smallest_dist = new_dist | ||
| smallest_dist_x = landing_pad.location_x | ||
| smallest_dist_y = landing_pad.location_y | ||
|
|
||
| # if drone is at the waypoint | ||
| if ( | ||
| (self.waypoint.location_x - report.position.location_x) ** 2 | ||
| + (self.waypoint.location_y - report.position.location_y) ** 2 | ||
| ) < self.acceptance_radius**2: | ||
|
|
||
| # if nearest landing pad is at the waypoint, land | ||
| if smallest_dist < self.acceptance_radius**2: | ||
| self.send_landing_command = True | ||
|
|
||
| # if not, set relative destination to nearest landing pad | ||
| else: | ||
| command = commands.Command.create_set_relative_destination_command( | ||
| smallest_dist_x - report.position.location_x, | ||
| smallest_dist_y - report.position.location_y, | ||
| ) | ||
| self.reached_landing_pad = True | ||
|
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. You don't really know that the drone has reached the landing pad here, you only know that you told the drone to go towards the landing pad. What if it doesn't get there? |
||
|
|
||
| # drone moves to nearest landing pad, then lands | ||
| elif self.reached_landing_pad: | ||
| self.send_landing_command = True | ||
|
|
||
| # if drone halts unexpectedly, neither at the waypoint or at the nearest landing pad | ||
| else: | ||
| 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 - report.position.location_x, | ||
| self.waypoint.location_y - report.position.location_y, | ||
| ) | ||
|
|
||
| # ============ | ||
| # ↑ 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.
You should probably put <= just in case that it happens to be equal.