Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
HermanG05 committed Aug 1, 2024
1 parent 860a0df commit 6b1c2d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
7 changes: 4 additions & 3 deletions main_2024.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
),
)
Expand Down
14 changes: 7 additions & 7 deletions modules/flight_interface/flight_interface_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
"""
Expand All @@ -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
Expand All @@ -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)
8 changes: 5 additions & 3 deletions tests/integration/test_flight_interface_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand All @@ -39,7 +41,7 @@ def main() -> int:
FLIGHT_INTERFACE_BAUD_RATE,
FLIGHT_INTERFACE_WORKER_PERIOD,
out_queue,
odometry_queue,
latest_odometry_queue,
controller,
),
)
Expand Down

0 comments on commit 6b1c2d4

Please sign in to comment.