This repository was archived by the owner on Nov 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathflight_interface_worker.py
More file actions
100 lines (80 loc) · 2.93 KB
/
flight_interface_worker.py
File metadata and controls
100 lines (80 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""
Gets odometry information from drone.
"""
import os
import pathlib
import queue
import time
from utilities.workers import queue_proxy_wrapper
from utilities.workers import worker_controller
from . import flight_interface
from ..common.modules.logger import logger
def flight_interface_worker(
address: str,
timeout: float,
baud_rate: int,
period: float,
enable_hitl: bool,
images_path: str | None,
log_timings: bool,
input_queue: queue_proxy_wrapper.QueueProxyWrapper,
coordinates_input_queue: queue_proxy_wrapper.QueueProxyWrapper,
output_queue: queue_proxy_wrapper.QueueProxyWrapper,
communications_output_queue: queue_proxy_wrapper.QueueProxyWrapper,
controller: worker_controller.WorkerController,
) -> None:
"""
Worker process.
address, timeout is initial setting.
period is minimum period between loops.
output_queue is the data queue.
controller is how the main process communicates to this worker process.
"""
# TODO: Error handling
setup_start_time = time.time() if log_timings else None
worker_name = pathlib.Path(__file__).stem
process_id = os.getpid()
result, local_logger = logger.Logger.create(f"{worker_name}_{process_id}", True)
if not result:
print("ERROR: Worker failed to create logger")
return
# Get Pylance to stop complaining
assert local_logger is not None
local_logger.info("Logger initialized", True)
result, interface = flight_interface.FlightInterface.create(
address, timeout, baud_rate, local_logger, images_path, enable_hitl
)
if not result:
local_logger.error("Worker failed to create class object", True)
return
# Get Pylance to stop complaining
assert interface is not None
home_position = interface.get_home_position()
communications_output_queue.queue.put(home_position)
if log_timings:
setup_end_time = time.time()
local_logger.info(
f"{time.time()}: Worker setup took {setup_end_time - setup_start_time} seconds."
)
while not controller.is_exit_requested():
iteration_start_time = time.time() if log_timings else None
controller.check_pause()
time.sleep(period)
try:
coordinate = coordinates_input_queue.queue.get_nowait()
except queue.Empty:
coordinate = None
result, value = interface.run(coordinate)
if not result:
continue
output_queue.queue.put(value)
# Check for decision commands
if not input_queue.queue.empty():
command = input_queue.queue.get()
# Pass the decision command to the flight controller
interface.apply_decision(command)
if log_timings:
iteration_end_time = time.time()
local_logger.info(
f"{time.time()}: Worker iteration took {iteration_end_time - iteration_start_time} seconds."
)