@@ -36,9 +36,9 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
3636 # ============
3737 # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
3838 # ============
39-
39+ self . has_landed = False
4040 # Add your own
41-
41+ self . target_pad = None
4242 # ============
4343 # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
4444 # ============
@@ -67,8 +67,55 @@ def run(
6767 # ============
6868 # ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
6969 # ============
70-
71- # Do something based on the report and the state of this class...
70+ # Calculate distance to waypoint
71+ pos = report .position # drone current position
72+
73+ if self .has_landed :
74+ return command # Already done
75+
76+ # Helper logic inline: squared distance (avoid sqrt)
77+ def dist2 (a : location .Location , b : location .Location ) -> float :
78+ dx = a .location_x - b .location_x
79+ dy = a .location_y - b .location_y
80+ return dx * dx + dy * dy
81+
82+ # If we haven't picked a pad yet, go to waypoint first
83+ if self .target_pad is None :
84+ if dist2 (pos , self .waypoint ) > self .acceptance_radius ** 2 :
85+ # Still need to fly to waypoint
86+ if report .status .name == "HALTED" :
87+ dx = self .waypoint .location_x - pos .location_x
88+ dy = self .waypoint .location_y - pos .location_y
89+ command = commands .Command .create_set_relative_destination_command (dx , dy )
90+ else :
91+ # Reached waypoint: choose closest landing pad
92+ if landing_pad_locations :
93+ closest = None
94+ min_dist = float ("inf" )
95+ for pad in landing_pad_locations :
96+ d = dist2 (pos , pad )
97+ if d < min_dist :
98+ min_dist = d
99+ closest = pad
100+ self .target_pad = closest
101+ print (f"Target pad selected: { self .target_pad } " )
102+ else :
103+ # No pads found, just land here
104+ if report .status .name == "HALTED" :
105+ self .has_landed = True
106+ command = commands .Command .create_land_command ()
107+ return command
108+
109+ # Now fly to the chosen landing pad
110+ if dist2 (pos , self .target_pad ) > self .acceptance_radius ** 2 :
111+ if report .status .name == "HALTED" :
112+ dx = self .target_pad .location_x - pos .location_x
113+ dy = self .target_pad .location_y - pos .location_y
114+ command = commands .Command .create_set_relative_destination_command (dx , dy )
115+ else :
116+ if report .status .name == "HALTED" :
117+ self .has_landed = True
118+ command = commands .Command .create_land_command ()
72119
73120 # ============
74121 # ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
0 commit comments