Skip to content

Commit

Permalink
add get_current_position method to flight_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Trotyl15 committed Sep 25, 2024
1 parent 5c3894e commit 083713c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mavlink/modules/flight_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,21 @@ def insert_waypoint(
commands.insert(index, new_waypoint)

return self.upload_commands(commands)

def get_current_position(self) -> "tuple[bool, drone_odometry.DronePosition | None]":
"""
Retrieves the current position of the drone.
Returns:
tuple[bool, DronePosition | None]: A tuple containing a boolean indicating success,
and the current DronePosition or None.
"""
location = self.drone.location.global_frame
result, position = drone_odometry.DronePosition.create(
location.lat,
location.lon,
location.alt,
)
if not result or position is None:
return False, None
return True, position
12 changes: 12 additions & 0 deletions mavlink/test_flight_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ def main() -> int:
print("Failed to get home location")
return -1

# Testing get_current_position()
print("\nTesting get_current_position():")
for _ in range(5):
result, current_position = controller.get_current_position()
if result and current_position is not None:
print(f"Current Latitude: {current_position.latitude}")
print(f"Current Longitude: {current_position.longitude}")
print(f"Current Altitude: {current_position.altitude}")
else:
print("Failed to get current position")
time.sleep(DELAY_TIME)

# Create and add land command
result = controller.upload_land_command(home.latitude, home.longitude)
if not result:
Expand Down

0 comments on commit 083713c

Please sign in to comment.