Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_current_position() #50

Closed
wants to merge 4 commits into from
Closed
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
14 changes: 14 additions & 0 deletions mavlink/modules/flight_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,20 @@ def set_flight_mode(self, mode: str) -> bool:
return False
return True

def get_current_position(self) -> drone_odometry.DronePosition:
"""
Retrieves the current position of the drone.
"""
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:
raise RuntimeError("Failed to get current position")
return position

def get_flight_mode(self) -> "tuple[bool, drone_odometry.FlightMode | None]":
"""
Gets the current flight mode of the drone.
Expand Down
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
7 changes: 4 additions & 3 deletions mavlink/test_mission_ended.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ def main() -> int:
return -1

while True:
result, is_drone_destination_final_waypoint = (
controller.is_drone_destination_final_waypoint()
)
(
result,
is_drone_destination_final_waypoint,
) = controller.is_drone_destination_final_waypoint()
if not result:
print("Failed to get if the drone's destination is the final waypoint.")
return -1
Expand Down