4
4
Travel to designated waypoint and then land at a nearby landing pad.
5
5
"""
6
6
7
- from math import sqrt
8
7
from .. import commands
9
8
from .. import drone_report
10
9
@@ -40,11 +39,12 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
40
39
41
40
# Add your own
42
41
self .target = None
42
+ self .tol = 0.0001
43
43
44
44
# ============
45
45
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
46
46
# ============
47
-
47
+
48
48
def run (
49
49
self , report : drone_report .DroneReport , landing_pad_locations : "list[location.Location]"
50
50
) -> commands .Command :
@@ -100,8 +100,9 @@ def run(
100
100
101
101
return command
102
102
103
+ @staticmethod
103
104
def distance (
104
- self , current_location : location .Location , destination_list : "list[location.Location]"
105
+ current_location : location .Location , destination_list : "list[location.Location]"
105
106
) -> location .Location :
106
107
"""
107
108
Takes the current location and a list of possible destinations and calculates the
@@ -114,15 +115,15 @@ def distance(
114
115
Returns:
115
116
location.Location: class implementation of a location defined by x and y
116
117
"""
117
- destination = location .Location (1000000000 , 1000000000 )
118
- for landing_pad in destination_list :
119
- if sqrt (
120
- (landing_pad .location_x - current_location .location_x ) ** 2
121
- + (landing_pad .location_y - current_location .location_y ) ** 2
122
- ) < sqrt (
123
- (destination .location_x - current_location .location_x ) ** 2
124
- + (destination .location_y - current_location .location_y ) ** 2
125
- ):
126
- destination = landing_pad
127
-
118
+ if len (destination_list ) > 0 :
119
+ destination = location .Location (float ('inf' ), float ('inf' ))
120
+ for landing_pad in destination_list :
121
+ landing_pad_distance = (landing_pad .location_x - current_location .location_x ) ** 2 + (landing_pad .location_y - current_location .location_y ) ** 2
122
+ destination_distance = (destination .location_x - current_location .location_x ) ** 2 + (destination .location_y - current_location .location_y ) ** 2
123
+ if landing_pad_distance < destination_distance :
124
+ destination = landing_pad
125
+ else :
126
+ destination = location .Location (0 , 0 )
128
127
return destination
128
+
129
+
0 commit comments