Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions protocols/velocity_setpoint_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(
current_pos: LocalPositionNED,
waypoints: list[Waypoint],
boot_time_ms: int,
log_func=lambda msg: print(msg),
mission_phase: str = "cruise",
target_system: int = 1,
target_component: int = 0,
Expand All @@ -35,6 +36,7 @@ def __init__(
self.mission_phase = mission_phase
self.target_system = target_system
self.target_component = target_component
self.log_func = log_func

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

# Slow down when close to/approaching waypoint
if distance < 45.0:
if distance < 15.0:
velocity /= 3.0

return velocity
Expand Down Expand Up @@ -121,9 +123,9 @@ def run(self, sender, receiver):
for i in range(len(self.waypoints)):
waypoint = self.waypoints[i]
waypoint_coords = np.array([waypoint.x, waypoint.y, waypoint.z])
optimal_speed = self.get_optimal_speed_for_waypoint(i)
optimal_speed = waypoint.speed

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

Expand All @@ -134,7 +136,7 @@ def run(self, sender, receiver):
)

if distance_to_waypoint <= waypoint.radius:
print(f"[VelocityControl] Reached waypoint {i + 1}")
self.log_func(f"[VelocityControl] Reached waypoint {i + 1}")
self.velocity_msg.load(np.array([0.0, 0.0, 0.0]))
sender.send_msg(self.velocity_msg)
break
Expand Down
2 changes: 2 additions & 0 deletions types/waypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Waypoint:
y: float
z: float
radius: float
speed: float

def __hash__(self):
# hash floats in a stable way
Expand All @@ -16,5 +17,6 @@ def __hash__(self):
round(self.y, 10),
round(self.z, 10),
round(self.radius, 10),
round(self.speed, 10),
)
)