14
14
from ..private .decision import base_decision
15
15
16
16
17
-
18
-
19
17
class DecisionWaypointLandingPads (base_decision .BaseDecision ):
20
18
"""
21
19
Travel to the designed waypoint and then land at the nearest landing pad.
@@ -47,21 +45,21 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
47
45
def location_in_bounds (self , loc : location .Location ) -> bool :
48
46
"""
49
47
Check to see if the waypoint is within flight bounds
50
-
48
+
51
49
"""
52
- return (loc .location_x <= self .upper_flight_bound
53
- and loc .location_x >= self .lower_flight_bound
54
- and loc .location_y <= self .upper_flight_bound
55
- and loc .location_y >= self .lower_flight_bound )
50
+ return (
51
+ loc .location_x <= self .upper_flight_bound
52
+ and loc .location_x >= self .lower_flight_bound
53
+ and loc .location_y <= self .upper_flight_bound
54
+ and loc .location_y >= self .lower_flight_bound
55
+ )
56
56
57
57
def dist_sqr (self , drone : location .Location , obj : location .Location ) -> float :
58
58
"""
59
59
Find the square of the distance between drone and another object
60
-
61
- """
62
- return ((drone .location_x - obj .location_x ) ** 2
63
- + (drone .location_y - obj .location_y ) ** 2 )
64
60
61
+ """
62
+ return (drone .location_x - obj .location_x ) ** 2 + (drone .location_y - obj .location_y ) ** 2
65
63
66
64
def run (
67
65
self , report : drone_report .DroneReport , landing_pad_locations : "list[location.Location]"
@@ -96,13 +94,15 @@ def run(
96
94
y_dist_to_waypoint = self .waypoint .location_y - report .position .location_y
97
95
98
96
# Distance between drone and waypoint squared (square root is costly)
99
- dist_to_waypoint_sqr = x_dist_to_waypoint ** 2 + y_dist_to_waypoint ** 2
97
+ dist_to_waypoint_sqr = x_dist_to_waypoint ** 2 + y_dist_to_waypoint ** 2
100
98
101
99
if report .status == drone_status .DroneStatus .HALTED :
102
100
103
101
# Case for when drone is halted but not at the waypoint (eg. start of simulation)
104
- if dist_to_waypoint_sqr > self .acceptance_radius ** 2 :
105
- command = commands .Command .create_set_relative_destination_command (x_dist_to_waypoint , y_dist_to_waypoint )
102
+ if dist_to_waypoint_sqr > self .acceptance_radius ** 2 :
103
+ command = commands .Command .create_set_relative_destination_command (
104
+ x_dist_to_waypoint , y_dist_to_waypoint
105
+ )
106
106
107
107
# When drone reaches the waypoint
108
108
else :
@@ -111,7 +111,7 @@ def run(
111
111
else :
112
112
# When closest landing pad hasn't been found yet
113
113
if self .landing_location is None :
114
- shortest_distance = float (' inf' )
114
+ shortest_distance = float (" inf" )
115
115
116
116
# Finding the closest landing pad
117
117
for landing_pad in landing_pad_locations :
@@ -123,7 +123,10 @@ def run(
123
123
self .landing_location = landing_pad
124
124
125
125
# If landing pad is on the waypoint
126
- if self .dist_sqr (report .position , self .landing_location ) < self .acceptance_radius ** 2 and report .status != drone_status .DroneStatus .HALTED :
126
+ if (
127
+ self .dist_sqr (report .position , self .landing_location ) < self .acceptance_radius ** 2
128
+ and report .status != drone_status .DroneStatus .HALTED
129
+ ):
127
130
128
131
return commands .Command .create_halt_command ()
129
132
@@ -132,17 +135,25 @@ def run(
132
135
133
136
if report .status == drone_status .DroneStatus .HALTED :
134
137
135
- if self .dist_sqr (report .position , self .landing_location ) > self .acceptance_radius ** 2 :
138
+ if (
139
+ self .dist_sqr (report .position , self .landing_location )
140
+ > self .acceptance_radius ** 2
141
+ ):
136
142
137
- x_dist_to_landing = self .landing_location .location_x - report .position .location_x
138
- y_dist_to_landing = self .landing_location .location_y - report .position .location_y
143
+ x_dist_to_landing = (
144
+ self .landing_location .location_x - report .position .location_x
145
+ )
146
+ y_dist_to_landing = (
147
+ self .landing_location .location_y - report .position .location_y
148
+ )
139
149
140
- command = commands .Command .create_set_relative_destination_command (x_dist_to_landing , y_dist_to_landing )
150
+ command = commands .Command .create_set_relative_destination_command (
151
+ x_dist_to_landing , y_dist_to_landing
152
+ )
141
153
142
154
else :
143
155
command = commands .Command .create_land_command ()
144
156
145
-
146
157
# ============
147
158
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
148
159
# ============
0 commit comments