-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add debug vector send capability (#118)
* Added support for debug vect * added debug_vect to send_debug_message() * final testing complete * added a better example for debug * remove unwanted file changes * fixed stale comments and warnings for PR * remooved unwanted mission report * Fixed spelling errors and error handling issues * final cleanup for send_debug.py * final testing complete * Gramatical fixes * Updated changelog and bumped project version * Fix ci pipeline Co-authored-by: Grant Phillips <[email protected]> Co-authored-by: Grant Phillips <[email protected]> Co-authored-by: Evan Palmer <[email protected]>
- Loading branch information
1 parent
090281d
commit 905a161
Showing
6 changed files
with
141 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# pymavswarm is an interface for swarm control and interaction | ||
# Copyright (C) 2022 Grant Phillips | ||
|
||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
|
||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
|
||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
from __future__ import annotations | ||
|
||
import time | ||
from argparse import ArgumentParser | ||
from concurrent.futures import Future | ||
from typing import Any | ||
|
||
from pymavswarm import MavSwarm | ||
|
||
|
||
def parse_args() -> Any: | ||
""" | ||
Parse the script arguments. | ||
:return: argument namespace | ||
:rtype: Any | ||
""" | ||
parser = ArgumentParser() | ||
parser.add_argument( | ||
"port", type=str, help="port to establish a MAVLink connection over" | ||
) | ||
parser.add_argument("baud", type=int, help="baudrate to establish a connection at") | ||
parser.add_argument("name", type=str, help="debug value name") | ||
parser.add_argument("data1", type=float, help="debug vector payload1") | ||
parser.add_argument("data2", type=float, help="debug vector payload2") | ||
parser.add_argument("data3", type=float, help="debug vector payload3") | ||
return parser.parse_args() | ||
|
||
|
||
# Define a callback to attach to a future | ||
def print_message_response_cb(future: Future) -> None: | ||
""" | ||
Print the result of the future. | ||
:param future: message execution future | ||
:type future: Future | ||
""" | ||
responses = future.result() | ||
|
||
if isinstance(responses, list): | ||
for response in responses: | ||
print( | ||
f"Result of {response.message_type} message sent to " | ||
f"({response.target_agent_id}): {response.code}" | ||
) | ||
else: | ||
print( | ||
f"Result of {responses.message_type} message sent to " | ||
f"({responses.target_agent_id}): {responses.code}" | ||
) | ||
|
||
return | ||
|
||
|
||
def main() -> None: | ||
"""Demonstrate how to send a debug vector.""" | ||
# Parse the script arguments | ||
args = parse_args() | ||
|
||
# Create a new MavSwarm instance | ||
mavswarm = MavSwarm() | ||
|
||
# Attempt to create a new MAVLink connection | ||
if not mavswarm.connect(args.port, args.baud): | ||
return | ||
|
||
# Wait for the swarm to auto-register new agents | ||
while not list(filter(lambda agent_id: agent_id[1] == 1, mavswarm.agent_ids)): | ||
print("Waiting for the system to recognize agents in the network...") | ||
time.sleep(0.5) | ||
|
||
# Send a debug message to all agents in the swarm | ||
future = mavswarm.send_debug_message( | ||
args.name, [args.data1, args.data2, args.data3] | ||
) | ||
future.add_done_callback(print_message_response_cb) | ||
|
||
# Wait for the arm command to complete | ||
while not future.done(): | ||
pass | ||
|
||
# Disconnect from the swarm | ||
mavswarm.disconnect() | ||
|
||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
[metadata] | ||
name = pymavswarm | ||
version = 1.0.0 | ||
version = 1.1.0 | ||
description = Python library used to communicate with multiple UAS simultaneously using MAVLink | ||
long_description = file: README.md | ||
long_description_content_type = text/markdown | ||
long_description = file: README.rst | ||
long_description_content_type = text/x-rst | ||
url = https://github.com/unl-nimbus-lab/pymavswarm | ||
author = Evan Palmer | ||
author_email = [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters