Skip to content
This repository was archived by the owner on Sep 21, 2025. It is now read-only.

Commit 3125b18

Browse files
committed
created working waypoint file and function landing system
1 parent c063877 commit 3125b18

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed

modules/bootcamp/decision_simple_waypoint.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
3737
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
3838
# ============
3939

40-
# Add your own
40+
self.has_landed = False
4141

4242
# ============
4343
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
@@ -67,9 +67,22 @@ def run(
6767
# ============
6868
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
6969
# ============
70+
# Calculate distance to waypoint
71+
dx = self.waypoint.location_x - report.position.location_x
72+
dy = self.waypoint.location_y - report.position.location_y
73+
dist_squared = dx**2 + dy**2
74+
75+
if self.has_landed:
76+
return command
7077

7178
# Do something based on the report and the state of this class...
7279

80+
if dist_squared > self.acceptance_radius**2:
81+
if report.status.name == "HALTED":
82+
command = commands.Command.create_set_relative_destination_command(dx, dy)
83+
else:
84+
if report.status.name == "HALTED":
85+
command = commands.Command.create_land_command()
7386
# ============
7487
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
7588
# ============

modules/bootcamp/decision_waypoint_landing_pads.py

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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 ↑

python

Whitespace-only changes.

0 commit comments

Comments
 (0)