Skip to content

Commit 8d2e0d5

Browse files
Aiden/speed waypoint (#16)
* added speed to waypoint * better * ruff --------- Co-authored-by: Lab PC <uavforge.uci.sdp@gmail.com>
1 parent 0687b9f commit 8d2e0d5

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

protocols/velocity_setpoint_protocol.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __init__(
2424
current_pos: LocalPositionNED,
2525
waypoints: list[Waypoint],
2626
boot_time_ms: int,
27+
log_func=lambda msg: print(msg),
2728
mission_phase: str = "cruise",
2829
target_system: int = 1,
2930
target_component: int = 0,
@@ -35,6 +36,7 @@ def __init__(
3536
self.mission_phase = mission_phase
3637
self.target_system = target_system
3738
self.target_component = target_component
39+
self.log_func = log_func
3840

3941
# Base speed for mission phase
4042
self.base_speed = self.SPEED_PROFILES.get(mission_phase, 10.0)
@@ -68,7 +70,7 @@ def calculate_velocity_vector(
6870
velocity = unit_direction * target_speed
6971

7072
# Slow down when close to/approaching waypoint
71-
if distance < 45.0:
73+
if distance < 15.0:
7274
velocity /= 3.0
7375

7476
return velocity
@@ -121,9 +123,9 @@ def run(self, sender, receiver):
121123
for i in range(len(self.waypoints)):
122124
waypoint = self.waypoints[i]
123125
waypoint_coords = np.array([waypoint.x, waypoint.y, waypoint.z])
124-
optimal_speed = self.get_optimal_speed_for_waypoint(i)
126+
optimal_speed = waypoint.speed
125127

126-
print(
128+
self.log_func(
127129
f"[VelocityControl] Waypoint {i + 1}/{len(self.waypoints)} @ {optimal_speed:.1f} m/s"
128130
)
129131

@@ -134,7 +136,7 @@ def run(self, sender, receiver):
134136
)
135137

136138
if distance_to_waypoint <= waypoint.radius:
137-
print(f"[VelocityControl] Reached waypoint {i + 1}")
139+
self.log_func(f"[VelocityControl] Reached waypoint {i + 1}")
138140
self.velocity_msg.load(np.array([0.0, 0.0, 0.0]))
139141
sender.send_msg(self.velocity_msg)
140142
break

types/waypoint.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Waypoint:
77
y: float
88
z: float
99
radius: float
10+
speed: float
1011

1112
def __hash__(self):
1213
# hash floats in a stable way
@@ -16,5 +17,6 @@ def __hash__(self):
1617
round(self.y, 10),
1718
round(self.z, 10),
1819
round(self.radius, 10),
20+
round(self.speed, 10),
1921
)
2022
)

0 commit comments

Comments
 (0)