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

Created download_commands function in flight_controller.py #43

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions mavlink/modules/flight_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,25 @@ def get_flight_mode(self) -> "tuple[bool, drone_odometry.FlightMode | None]":
if flight_mode == "AUTO":
return True, drone_odometry.FlightMode.MOVING
return True, drone_odometry.FlightMode.MANUAL

def download_commands(self) -> "list[dronekit.Command]":
"""
Downloads the current list of commands from the drone.

Returns
-------
list[dronekit.Command]
The list of commands currently held by the drone.
"""
try:
command_sequence = self.drone.commands
command_sequence.download()
command_sequence.wait_ready()
commands = list(command_sequence)
return commands
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should return whether the operation was successful with a bool

so the function should return tuple[bool, List[dronekit.Command]]

except dronekit.TimeoutError:
print("ERROR: Download timeout, commands are not being received.")
return []
except ConnectionResetError:
print("ERROR: Connection with drone reset. Unable to download commands.")
return []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add an empty blank line at the bottom of file (good convention)

11 changes: 10 additions & 1 deletion mavlink/test_flight_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import time

from mavlink.modules import flight_controller
from modules import flight_controller


DELAY_TIME = 0.5 # seconds
Expand Down Expand Up @@ -47,6 +47,15 @@ def main() -> int:

time.sleep(DELAY_TIME)

# Download and print commands
commands = controller.download_commands()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to change here when you change the return types!

if commands:
print("Downloaded commands:")
for command in commands:
print(command)
else:
print("No commands available.")

result, home = controller.get_home_location(TIMEOUT)
if not result:
print("Failed to get home location")
Expand Down