22Test auto-landing worker process.
33"""
44
5- import datetime
65import multiprocessing as mp
76import pathlib
87import time
1716from modules .common .modules import orientation
1817from modules .common .modules import position_local
1918from modules .common .modules .mavlink import drone_odometry_local
20- from modules .common .modules .logger import logger
2119from modules .common .modules .read_yaml import read_yaml
2220from utilities .workers import queue_proxy_wrapper
2321from utilities .workers import worker_controller
2422
2523
2624# Test-specific parameters
2725WORKER_PERIOD = 0.1 # seconds
28- LOG_TIMINGS = False # Disable timing logging for the test
2926CONFIG_FILE_PATH = pathlib .Path ("config.yaml" )
3027detection_strategy = auto_landing .DetectionSelectionStrategy .FIRST_DETECTION
3128# detection_strategy = auto_landing.DetectionSelectionStrategy.HIGHEST_CONFIDENCE
3229
33- # Ensure logs directory exists and create timestamped subdirectory
34- LOG_DIR = pathlib .Path ("logs" )
35- LOG_DIR .mkdir (parents = True , exist_ok = True )
36-
37- # Create a timestamped subdirectory for this test session
38- TIMESTAMP_FORMAT = "%Y-%m-%d_%H-%M-%S"
39- test_session_dir = LOG_DIR / datetime .datetime .now ().strftime (TIMESTAMP_FORMAT )
40- test_session_dir .mkdir (parents = True , exist_ok = True )
41-
42-
4330def simulate_detection_input (
4431 input_queue : queue_proxy_wrapper .QueueProxyWrapper ,
4532 detections : list ,
@@ -114,20 +101,14 @@ def main() -> int:
114101 """
115102 Main function.
116103 """
117- # Logger
118- test_name = pathlib .Path (__file__ ).stem
119- result , local_logger = logger .Logger .create (test_name , LOG_TIMINGS )
120- assert result # Logger initialization should succeed
121- assert local_logger is not None
122-
123104 # Read config file
124105 result , config = read_yaml .open_config (CONFIG_FILE_PATH )
125106 assert result and config is not None , "Failed to read config file"
126107
127108 # Check if the feature is enabled in the config
128109 auto_landing_config = config .get ("auto_landing" , {})
129110 if not auto_landing_config .get ("enabled" , False ):
130- local_logger . info ("Auto-landing is disabled in config.yaml, skipping test." )
111+ print ("Auto-landing is disabled in config.yaml, skipping test." )
131112 return 0
132113
133114 # Extract parameters from config
@@ -137,7 +118,7 @@ def main() -> int:
137118 image_height = config ["video_input" ]["height" ]
138119 image_width = config ["video_input" ]["width" ]
139120 except KeyError as e :
140- local_logger . error (f"Config file missing required key: { e } " )
121+ print (f"ERROR: Config file missing required key: { e } " )
141122 return - 1
142123
143124 # Setup
@@ -170,7 +151,7 @@ def main() -> int:
170151 time .sleep (0.5 )
171152
172153 # Test 1: Send a single detection and verify it's processed
173- local_logger . info ("--- Test 1: Processing single detection ---" )
154+ print ("--- Test 1: Processing single detection ---" )
174155 detection1_bbox = [200 , 200 , 400 , 400 ]
175156 detection1 = create_test_detection (detection1_bbox , 1 , 0.9 )
176157 simulate_detection_input (
@@ -189,10 +170,10 @@ def main() -> int:
189170 assert hasattr (landing_info , "angle_x" )
190171 assert hasattr (landing_info , "angle_y" )
191172 assert hasattr (landing_info , "target_dist" )
192- local_logger . info ("--- Test 1 Passed ---" )
173+ print ("--- Test 1 Passed ---" )
193174
194175 # Test 2: Verify strategy with multiple detections
195- local_logger . info (f"--- Test 2: Verifying { detection_strategy .value } strategy ---" )
176+ print (f"--- Test 2: Verifying { detection_strategy .value } strategy ---" )
196177
197178 # This is the first detection in the list
198179 detection_first_bbox = [100 , 100 , 200 , 200 ]
@@ -243,7 +224,7 @@ def main() -> int:
243224 assert math .isclose (
244225 landing_info2 .angle_y , expected_angle_y , rel_tol = 1e-7
245226 ), f"Expected angle_y to be { expected_angle_y } , but got { landing_info2 .angle_y } "
246- local_logger . info ("--- Test 2 Passed ---" )
227+ print ("--- Test 2 Passed ---" )
247228
248229 # Cleanup
249230 controller .request_exit ()
@@ -253,9 +234,7 @@ def main() -> int:
253234
254235 # Wait for worker to finish
255236 worker .join (timeout = 5.0 )
256- if worker .is_alive ():
257- worker .terminate ()
258- worker .join ()
237+ worker .terminate ()
259238
260239 return 0
261240
0 commit comments