-
Notifications
You must be signed in to change notification settings - Fork 37
Using message_encode_decode to send MAVlink messages #247
Changes from 10 commits
fb4418d
4524414
882eb86
b37f535
04d0767
1f99de0
dbb6446
313c324
42e91c7
e08f5d3
34ab226
dc6f1f3
7c809a7
f056b62
7070a1e
485b1fe
f709292
b6bd57c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,3 +77,4 @@ cluster_estimation: | |
|
|
||
| communications: | ||
| timeout: 30.0 # seconds | ||
| worker_period: 0.5 # seconds | ||
| +1 −2 | modules/data_encoding/message_encoding_decoding.py | |
| +1 −2 | modules/data_encoding/metadata_encoding_decoding.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |
| from ..common.modules import position_global | ||
| from ..common.modules import position_local | ||
| from ..common.modules.logger import logger | ||
| from ..common.modules.data_encoding import message_encoding_decoding | ||
| from ..common.modules.data_encoding import worker_enum | ||
| from ..common.modules.mavlink import local_global_conversion | ||
|
|
||
|
|
||
|
|
@@ -23,6 +25,7 @@ def create( | |
| cls, | ||
| home_position: position_global.PositionGlobal, | ||
| local_logger: logger.Logger, | ||
| worker_id: worker_enum.WorkerEnum, | ||
|
||
| ) -> "tuple[True, Communications] | tuple[False, None]": | ||
| """ | ||
| Logs data and forwards it. | ||
|
|
@@ -32,13 +35,14 @@ def create( | |
| Returns: Success, class object. | ||
| """ | ||
|
|
||
| return True, Communications(cls.__create_key, home_position, local_logger) | ||
| return True, Communications(cls.__create_key, home_position, local_logger, worker_id) | ||
|
|
||
| def __init__( | ||
| self, | ||
| class_private_create_key: object, | ||
| home_position: position_global.PositionGlobal, | ||
| local_logger: logger.Logger, | ||
| worker_id: worker_enum.WorkerEnum, | ||
| ) -> None: | ||
| """ | ||
| Private constructor, use create() method. | ||
|
|
@@ -47,11 +51,12 @@ def __init__( | |
|
|
||
| self.__home_position = home_position | ||
| self.__logger = local_logger | ||
| self.__worker_id = worker_id | ||
|
|
||
| def run( | ||
| self, | ||
| objects_in_world: list[object_in_world.ObjectInWorld], | ||
| ) -> tuple[True, list[object_in_world.ObjectInWorld]] | tuple[False, None]: | ||
| ) -> tuple[True, list[bytes]] | tuple[False, None]: | ||
|
|
||
| objects_in_world_global = [] | ||
| for object_in_world in objects_in_world: | ||
|
|
@@ -87,4 +92,16 @@ def run( | |
|
|
||
| self.__logger.info(f"{time.time()}: {objects_in_world_global}") | ||
|
|
||
| return True, objects_in_world | ||
| encoded_position_global_objects = [] | ||
| for object in object_in_world_global: | ||
|
|
||
| result, message = message_encoding_decoding.encode_position_global( | ||
| self.__worker_id, object | ||
| ) | ||
| if not result: | ||
| self.__logger.warning("Conversion from PositionGlobal to bytes failed", True) | ||
| return False, None | ||
|
|
||
| encoded_position_global_objects.append(message) | ||
|
|
||
| return True, encoded_position_global_objects | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,7 +73,7 @@ def get_home_position(self) -> position_global.PositionGlobal: | |
| """ | ||
| return self.__home_position | ||
|
|
||
| def run(self) -> "tuple[bool, odometry_and_time.OdometryAndTime | None]": | ||
| def run(self, message: bytes) -> "tuple[bool, odometry_and_time.OdometryAndTime | None]": | ||
|
||
| """ | ||
| Returns a possible OdometryAndTime with current timestamp. | ||
| """ | ||
|
|
@@ -103,6 +103,10 @@ def run(self) -> "tuple[bool, odometry_and_time.OdometryAndTime | None]": | |
|
|
||
| self.__logger.info(str(odometry_and_time_object), True) | ||
|
|
||
| result = self.controller.send_statustext_msg(message) | ||
| if not result: | ||
| self.__logger.error("Failed to send statustext message", True) | ||
|
|
||
|
||
| return True, odometry_and_time_object | ||
|
|
||
| def apply_decision(self, cmd: decision_command.DecisionCommand) -> bool: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| import os | ||
| import pathlib | ||
| import queue | ||
maxlou05 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import time | ||
|
|
||
| from utilities.workers import queue_proxy_wrapper | ||
|
|
@@ -20,6 +21,7 @@ def flight_interface_worker( | |
| input_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
| output_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
| communications_output_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
| coordinates_input_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
|
||
| controller: worker_controller.WorkerController, | ||
| ) -> None: | ||
| """ | ||
|
|
@@ -62,7 +64,17 @@ def flight_interface_worker( | |
|
|
||
| time.sleep(period) | ||
|
|
||
| result, value = interface.run() | ||
| try: | ||
| coordinate = coordinates_input_queue.queue.get_nowait() | ||
| except queue.Empty: | ||
| local_logger.warning("No more coordinates to process") | ||
|
||
| coordinate = None | ||
|
|
||
| if not isinstance(coordinate, bytes): | ||
| local_logger.warning(f"Skipping unexpected input: {coordinate}") | ||
| continue | ||
|
||
|
|
||
| result, value = interface.run(coordinate) | ||
| if not result: | ||
| continue | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,11 +11,34 @@ | |
| from modules import decision_command | ||
| from utilities.workers import queue_proxy_wrapper | ||
| from utilities.workers import worker_controller | ||
| from modules.common.modules import position_global | ||
| from modules.common.modules.data_encoding import message_encoding_decoding | ||
| from modules.common.modules.data_encoding import worker_enum | ||
|
|
||
| MAVLINK_CONNECTION_ADDRESS = "tcp:localhost:14550" | ||
| FLIGHT_INTERFACE_TIMEOUT = 10.0 # seconds | ||
| FLIGHT_INTERFACE_BAUD_RATE = 57600 # symbol rate | ||
| FLIGHT_INTERFACE_WORKER_PERIOD = 0.1 # seconds | ||
| WORK_COUNT = 4 | ||
| COMMUNICATIONS_WORKER_ID = worker_enum.WorkerEnum.COMMUNICATIONS_WORKER | ||
|
|
||
|
|
||
| def simulate_communications_worker( | ||
|
||
| in_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
| data_point: position_global.PositionGlobal, | ||
| ) -> None: | ||
| """ | ||
| Encode coordinates and place into queue. | ||
| """ | ||
| result, message = message_encoding_decoding.encode_position_global( | ||
| COMMUNICATIONS_WORKER_ID, data_point | ||
| ) | ||
| assert result | ||
| assert message is not None | ||
|
|
||
| in_queue.queue.put(message) | ||
|
|
||
| return | ||
|
|
||
|
|
||
| def apply_decision_test( | ||
|
|
@@ -105,6 +128,8 @@ def main() -> int: | |
| out_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) | ||
| home_position_out_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) | ||
| in_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) | ||
| communications_in_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) | ||
| communications_out_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) | ||
|
|
||
| worker = mp.Process( | ||
| target=flight_interface_worker.flight_interface_worker, | ||
|
|
@@ -116,6 +141,7 @@ def main() -> int: | |
| in_queue, # Added input_queue | ||
| out_queue, | ||
| home_position_out_queue, | ||
| communications_in_queue, | ||
| controller, | ||
| ), | ||
| ) | ||
|
|
@@ -129,6 +155,28 @@ def main() -> int: | |
| home_position = home_position_out_queue.queue.get() | ||
| assert home_position is not None | ||
|
|
||
| data_points = [ | ||
| position_global.PositionGlobal.create(43.471468, -80.544205, 335), | ||
| position_global.PositionGlobal.create(43.6629, -79.3957, 105), | ||
| position_global.PositionGlobal.create(43.2609, -79.9192, 100), | ||
| position_global.PositionGlobal.create(43.7735, -79.5019, 170), | ||
| ] | ||
|
|
||
| # Simulate communications worker | ||
| for i in range(0, WORK_COUNT): | ||
| simulate_communications_worker(communications_in_queue, home_position, data_points[i]) | ||
|
|
||
| # Test flight interface worker sending statustext messages | ||
| for i in range(0, WORK_COUNT): | ||
| try: | ||
| input_data: bytes = communications_out_queue.queue.get_nowait() | ||
| assert input_data is not None | ||
| except queue.Empty: | ||
| print("Output queue has no more messages to process, exiting") | ||
| break | ||
|
|
||
| assert communications_out_queue.queue.empty() | ||
|
|
||
| # Run the apply_decision tests | ||
| test_result = apply_decision_test(in_queue, out_queue) | ||
| if not test_result: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this change? Can you make this a PR in common or something?