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
19 changes: 15 additions & 4 deletions dimos/robot/drone/connection_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,20 +308,31 @@ def move_twist(self, twist, duration: float = 0.0, lock_altitude: bool = True) -
return False

@skill()
def fly_to(self, lat: float, lon: float, alt: float) -> bool:
"""Fly drone to GPS coordinates.
def is_flying_to_target(self) -> bool:
"""Check if drone is currently flying to a GPS target.

Returns:
True if flying to target, False otherwise
"""
if self.connection and hasattr(self.connection, "is_flying_to_target"):
return self.connection.is_flying_to_target
return False

@skill()
def fly_to(self, lat: float, lon: float, alt: float) -> str:
"""Fly drone to GPS coordinates (blocking operation).

Args:
lat: Latitude in degrees
lon: Longitude in degrees
alt: Altitude in meters (relative to home)

Returns:
True if command sent successfully
String message indicating success or failure reason
"""
if self.connection:
return self.connection.fly_to(lat, lon, alt)
return False
return "Failed: No connection to drone"

@rpc
def stop(self):
Expand Down
25 changes: 17 additions & 8 deletions dimos/robot/drone/mavlink_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ def land(self) -> bool:
logger.warning("Land timeout")
return self.set_mode("LAND")

def fly_to(self, lat: float, lon: float, alt: float) -> bool:
def fly_to(self, lat: float, lon: float, alt: float) -> str:
"""Fly to GPS coordinates - sends commands continuously until reaching target.

Args:
Expand All @@ -713,23 +713,27 @@ def fly_to(self, lat: float, lon: float, alt: float) -> bool:
alt: Altitude in meters (relative to home)

Returns:
True if target reached, False if timeout or error
String message indicating success or failure reason
"""
if not self.connected:
return False
return "Failed: Not connected to drone"

# Check if already flying to a target
if self.flying_to_target:
logger.warning("Already flying to target, ignoring new fly_to command")
return False
logger.warning(
"Already flying to target, ignoring new fly_to command. Wait until completed to send new fly_to command."
)
return (
"Already flying to target - wait for completion before sending new fly_to command"
)

self.flying_to_target = True

# Ensure GUIDED mode for GPS navigation
if not self.set_mode("GUIDED"):
logger.error("Failed to set GUIDED mode for GPS navigation")
self.flying_to_target = False
return False
return "Failed: Could not set GUIDED mode for GPS navigation"

logger.info(f"Flying to GPS: lat={lat:.7f}, lon={lon:.7f}, alt={alt:.1f}m")

Expand Down Expand Up @@ -820,7 +824,7 @@ def fly_to(self, lat: float, lon: float, alt: float) -> bool:
self.set_mode("STABILIZE")
logger.info("Returned to STABILIZE mode for manual control")
self.flying_to_target = False
return True # Successfully reached target
return f"Success: Reached target location (lat={lat:.7f}, lon={lon:.7f}, alt={alt:.1f}m)"

# Only send velocity commands if we're far enough
if distance > 0.1:
Expand Down Expand Up @@ -930,7 +934,7 @@ def fly_to(self, lat: float, lon: float, alt: float) -> bool:
self.set_mode("STABILIZE")
logger.info("Returned to STABILIZE mode for manual control")

return False # Timeout - did not reach target
return "Failed: Timeout - did not reach target within 120 seconds"

def set_mode(self, mode: str) -> bool:
"""Set flight mode."""
Expand Down Expand Up @@ -1007,6 +1011,11 @@ def disconnect(self):
self.connected = False
logger.info("Disconnected")

@property
def is_flying_to_target(self) -> bool:
"""Check if drone is currently flying to a GPS target."""
return self.flying_to_target

def get_video_stream(self, fps: int = 30):
"""Get video stream (to be implemented with GStreamer)."""
# Will be implemented in camera module
Expand Down
Loading