diff --git a/main_2024.py b/main_2024.py index 2e51c553..63fd2d92 100644 --- a/main_2024.py +++ b/main_2024.py @@ -132,9 +132,10 @@ def main() -> int: mp_manager, QUEUE_MAX_SIZE, ) - odometry_to_data_merge_queue = queue_proxy_wrapper.QueueProxyWrapper( + # Queue size of latest odometry data must be 1 + flight_interface_to_decision_queue = queue_proxy_wrapper.QueueProxyWrapper( mp_manager, - QUEUE_MAX_SIZE, + 1, ) data_merge_to_geolocation_queue = queue_proxy_wrapper.QueueProxyWrapper( mp_manager, @@ -184,7 +185,7 @@ def main() -> int: FLIGHT_INTERFACE_BAUD_RATE, FLIGHT_INTERFACE_WORKER_PERIOD, flight_interface_to_data_merge_queue, - odometry_to_data_merge_queue, + flight_interface_to_decision_queue, controller, ), ) diff --git a/modules/flight_interface/flight_interface_worker.py b/modules/flight_interface/flight_interface_worker.py index e2e3f7f4..0b01782a 100644 --- a/modules/flight_interface/flight_interface_worker.py +++ b/modules/flight_interface/flight_interface_worker.py @@ -2,8 +2,8 @@ Gets odometry information from drone. """ +import queue import time -import multiprocessing as mp from utilities.workers import queue_proxy_wrapper from utilities.workers import worker_controller @@ -16,7 +16,7 @@ def flight_interface_worker( baud_rate: int, period: float, output_queue: queue_proxy_wrapper.QueueProxyWrapper, - odometry_queue: queue_proxy_wrapper.QueueProxyWrapper, + most_recent_odometry_queue: queue_proxy_wrapper.QueueProxyWrapper, controller: worker_controller.WorkerController, ) -> None: """ @@ -27,8 +27,8 @@ def flight_interface_worker( output_queue is the data queue. controller is how the main process communicates to this worker process. """ - if len(odometry_queue) > 1: - print("ERROR: Queue should have a maximum size of 1") + if most_recent_odometry_queue.maxsize != 1: + print("ERROR: most_recent_odometry_queue must have a maximum size of 1") return # TODO: Error handling @@ -53,9 +53,9 @@ def flight_interface_worker( # Replace any existing odometry data with the latest odometry data try: - odometry_queue.queue.get_nowait() - except queue_proxy_wrapper.queue.Empty: + most_recent_odometry_queue.queue.get_nowait() + except queue.Empty: pass - odometry_queue.queue.put(value) + most_recent_odometry_queue.queue.put(value) output_queue.queue.put(value) diff --git a/tests/integration/test_flight_interface_worker.py b/tests/integration/test_flight_interface_worker.py index 9039fa2e..703bc150 100644 --- a/tests/integration/test_flight_interface_worker.py +++ b/tests/integration/test_flight_interface_worker.py @@ -16,7 +16,7 @@ FLIGHT_INTERFACE_TIMEOUT = 10.0 # seconds FLIGHT_INTERFACE_BAUD_RATE = 57600 # symbol rate FLIGHT_INTERFACE_WORKER_PERIOD = 0.1 # seconds -QUEUE_MAX_SIZE = 1 # Max items allowed in odometry queue +LATEST_ODOMETRY_QUEUE_MAX_SIZE = 1 # Max items allowed in latest odometry queue def main() -> int: @@ -29,7 +29,9 @@ def main() -> int: mp_manager = mp.Manager() out_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) - odometry_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager, QUEUE_MAX_SIZE) + latest_odometry_queue = queue_proxy_wrapper.QueueProxyWrapper( + mp_manager, LATEST_ODOMETRY_QUEUE_MAX_SIZE + ) worker = mp.Process( target=flight_interface_worker.flight_interface_worker, @@ -39,7 +41,7 @@ def main() -> int: FLIGHT_INTERFACE_BAUD_RATE, FLIGHT_INTERFACE_WORKER_PERIOD, out_queue, - odometry_queue, + latest_odometry_queue, controller, ), )