From c517762ec8078b014d73ba535f8286ff85595fcc Mon Sep 17 00:00:00 2001 From: cyuber Date: Thu, 26 Sep 2024 11:17:48 -0400 Subject: [PATCH 01/42] implemented string field for ObjectInWorld class to specify which type of real world object it is. --- modules/cluster_estimation/cluster_estimation.py | 8 +++++--- modules/object_in_world.py | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 31675f47..78d4ca3f 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -124,7 +124,7 @@ def __init__( def run( self, detections: "list[detection_in_world.DetectionInWorld]", run_override: bool - ) -> "tuple[bool, list[object_in_world.ObjectInWorld] | None]": + ) -> "tuple[bool, object_in_world.ObjectInWorld | None]": """ Take in list of landing pad detections and return list of estimated landing pad locations if number of detections is sufficient, or if manually forced to run. @@ -193,14 +193,16 @@ def run( # Create output list of remaining valid clusters detections_in_world = [] for cluster in model_output: - result, landing_pad = object_in_world.ObjectInWorld.create( + + result, object = object_in_world.ObjectInWorld.create( cluster[0][0], cluster[0][1], cluster[2], + "object" ) if result: - detections_in_world.append(landing_pad) + detections_in_world.append([object]) return True, detections_in_world diff --git a/modules/object_in_world.py b/modules/object_in_world.py index 1ce9f65e..bb51b391 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -12,7 +12,7 @@ class ObjectInWorld: @classmethod def create( - cls, location_x: float, location_y: float, spherical_variance: float + cls, location_x: float, location_y: float, spherical_variance: float, object_type: str ) -> "tuple[bool, ObjectInWorld | None]": """ location_x, location_y: Location of the object. @@ -21,7 +21,7 @@ def create( if spherical_variance < 0.0: return False, None - return True, ObjectInWorld(cls.__create_key, location_x, location_y, spherical_variance) + return True, ObjectInWorld(cls.__create_key, location_x, location_y, spherical_variance, object_type) def __init__( self, @@ -29,6 +29,7 @@ def __init__( location_x: float, location_y: float, spherical_variance: float, + object_type: str ) -> None: """ Private constructor, use create() method. @@ -38,3 +39,5 @@ def __init__( self.location_x = location_x self.location_y = location_y self.spherical_variance = spherical_variance + self.object_type = object_type + From 3aad8c705c21b440bafa067c4123d0444e9821a5 Mon Sep 17 00:00:00 2001 From: cyuber Date: Thu, 26 Sep 2024 11:40:54 -0400 Subject: [PATCH 02/42] fixed mistakenly changed annotation in ClusterElimination.run --- modules/cluster_estimation/cluster_estimation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 78d4ca3f..3f7caf3c 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -124,7 +124,7 @@ def __init__( def run( self, detections: "list[detection_in_world.DetectionInWorld]", run_override: bool - ) -> "tuple[bool, object_in_world.ObjectInWorld | None]": + ) -> "tuple[bool, list[object_in_world.ObjectInWorld] | None]": """ Take in list of landing pad detections and return list of estimated landing pad locations if number of detections is sufficient, or if manually forced to run. From 2dfe21bd7b3373d7457dbfbdaa2743c684e131ae Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 27 Sep 2024 03:51:38 -0400 Subject: [PATCH 03/42] fixed linters --- modules/object_in_world.py | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/object_in_world.py b/modules/object_in_world.py index bb51b391..4e9fdef0 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -40,4 +40,3 @@ def __init__( self.location_y = location_y self.spherical_variance = spherical_variance self.object_type = object_type - From b9043b0f0dedf524149da3e82740a18b0cf4c529 Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 27 Sep 2024 11:04:16 -0400 Subject: [PATCH 04/42] fixed black --check issues --- modules/cluster_estimation/cluster_estimation.py | 2 +- modules/object_in_world.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 3f7caf3c..4cfa5c6b 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -198,7 +198,7 @@ def run( cluster[0][0], cluster[0][1], cluster[2], - "object" + "object", ) if result: diff --git a/modules/object_in_world.py b/modules/object_in_world.py index 4e9fdef0..6b783949 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -17,11 +17,14 @@ def create( """ location_x, location_y: Location of the object. spherical_variance: Uncertainty of the location. + object_type: type of object in real world. """ if spherical_variance < 0.0: return False, None - return True, ObjectInWorld(cls.__create_key, location_x, location_y, spherical_variance, object_type) + return True, ObjectInWorld( + cls.__create_key, location_x, location_y, spherical_variance, object_type + ) def __init__( self, @@ -29,7 +32,7 @@ def __init__( location_x: float, location_y: float, spherical_variance: float, - object_type: str + object_type: str, ) -> None: """ Private constructor, use create() method. From 257710409ec88d9619685eab6c05429213737e9e Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 27 Sep 2024 11:22:06 -0400 Subject: [PATCH 05/42] fixed pylint issues --- modules/cluster_estimation/cluster_estimation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 4cfa5c6b..41cfcd5c 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -194,7 +194,7 @@ def run( detections_in_world = [] for cluster in model_output: - result, object = object_in_world.ObjectInWorld.create( + result, temp_object = object_in_world.ObjectInWorld.create( cluster[0][0], cluster[0][1], cluster[2], @@ -202,7 +202,7 @@ def run( ) if result: - detections_in_world.append([object]) + detections_in_world.append([temp_object]) return True, detections_in_world From 209d37243a14a1870abb55d3d57f51d662f981d0 Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 27 Sep 2024 11:29:20 -0400 Subject: [PATCH 06/42] fixed linters in test_landing_pad_tracking.py --- tests/unit/test_landing_pad_tracking.py | 72 ++++++++++++------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/unit/test_landing_pad_tracking.py b/tests/unit/test_landing_pad_tracking.py index 51bfc3f7..df257660 100644 --- a/tests/unit/test_landing_pad_tracking.py +++ b/tests/unit/test_landing_pad_tracking.py @@ -30,23 +30,23 @@ def detections_1() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 4) + result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 4, "object") assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2) + result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2, "object") assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10) + result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10, "object") assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6) + result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6, "object") assert result assert obj_5 is not None @@ -59,23 +59,23 @@ def detections_2() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0.5, 0.5, 1) + result, obj_1 = object_in_world.ObjectInWorld.create(0.5, 0.5, 1, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(1.5, 1.5, 3) + result, obj_2 = object_in_world.ObjectInWorld.create(1.5, 1.5, 3, "object") assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(4, 4, 7) + result, obj_3 = object_in_world.ObjectInWorld.create(4, 4, 7, "object") assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(-4, -4, 5) + result, obj_4 = object_in_world.ObjectInWorld.create(-4, -4, 5, "object") assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(5, 5, 9) + result, obj_5 = object_in_world.ObjectInWorld.create(5, 5, 9, "object") assert result assert obj_5 is not None @@ -88,23 +88,23 @@ def detections_3() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 4) + result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 4, "object") assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2) + result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2, "object") assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10) + result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10, "object") assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6) + result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6, "object") assert result assert obj_5 is not None @@ -123,11 +123,11 @@ def test_is_similar_positive_equal_to_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is equal to the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(1, 1, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(1, 1, 0, "object") assert result assert obj_2 is not None @@ -145,11 +145,11 @@ def test_is_similar_negative_equal_to_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is equal to the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-1, -1, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(-1, -1, 0, "object") assert result assert obj_2 is not None @@ -168,11 +168,11 @@ def test_is_similar_positive_less_than_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is less than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 0, "object") assert result assert obj_2 is not None @@ -191,11 +191,11 @@ def test_is_similar_negative_less_than_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is less than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-0.5, -0.5, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(-0.5, -0.5, 0, "object") assert result assert obj_2 is not None @@ -214,11 +214,11 @@ def test_is_similar_positive_more_than_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is more than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 0, "object") assert result assert obj_2 is not None @@ -237,11 +237,11 @@ def test_is_similar_negative_more_than_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is more than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-2, -2, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(-2, -2, 0, "object") assert result assert obj_2 is not None @@ -269,7 +269,7 @@ def test_mark_false_positive_no_similar( """ Test if marking false positive adds detection to list of false positives. """ - _, false_positive = object_in_world.ObjectInWorld.create(20, 20, 20) + _, false_positive = object_in_world.ObjectInWorld.create(20, 20, 20, "object") assert false_positive is not None tracker._LandingPadTracking__unconfirmed_positives = detections_1 # type: ignore @@ -296,7 +296,7 @@ def test_mark_false_positive_with_similar( Test if marking false positive adds detection to list of false positives and removes. similar landing pads """ - _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") assert false_positive is not None tracker._LandingPadTracking__unconfirmed_positives = detections_2 # type: ignore @@ -316,10 +316,10 @@ def test_mark_multiple_false_positive( """ Test if marking false positive adds detection to list of false positives. """ - _, false_positive_1 = object_in_world.ObjectInWorld.create(0, 0, 1) + _, false_positive_1 = object_in_world.ObjectInWorld.create(0, 0, 1, "object") assert false_positive_1 is not None - _, false_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1) + _, false_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1, "object") assert false_positive_2 is not None tracker._LandingPadTracking__unconfirmed_positives = detections_1 # type: ignore @@ -344,7 +344,7 @@ def test_mark_confirmed_positive( """ Test if marking confirmed positive adds detection to list of confirmed positives. """ - _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") assert confirmed_positive is not None expected = [confirmed_positive] @@ -359,10 +359,10 @@ def test_mark_multiple_confirmed_positives( """ Test if marking confirmed positive adds detection to list of confirmed positives. """ - _, confirmed_positive_1 = object_in_world.ObjectInWorld.create(1, 1, 1) + _, confirmed_positive_1 = object_in_world.ObjectInWorld.create(1, 1, 1, "object") assert confirmed_positive_1 is not None - _, confirmed_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1) + _, confirmed_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1, "object") assert confirmed_positive_2 is not None expected = [confirmed_positive_1, confirmed_positive_2] @@ -469,7 +469,7 @@ def test_run_with_confirmed_positive( """ Test run when there is a confirmed positive. """ - _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") assert confirmed_positive is not None tracker._LandingPadTracking__confirmed_positives.append(confirmed_positive) # type: ignore @@ -488,7 +488,7 @@ def test_run_with_false_positive( """ Test to see if run function doesn't add landing pads that are similar to false positives. """ - _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") assert false_positive is not None tracker._LandingPadTracking__false_positives.append(false_positive) # type: ignore From c40ddbd62390d0c3117e1229da83f9357b790aae Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 27 Sep 2024 11:34:41 -0400 Subject: [PATCH 07/42] fixed linter issues in test_decision.py --- tests/unit/test_decision.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit/test_decision.py b/tests/unit/test_decision.py index 9b24211b..6c694be8 100644 --- a/tests/unit/test_decision.py +++ b/tests/unit/test_decision.py @@ -41,7 +41,7 @@ def best_pad_within_tolerance() -> object_in_world.ObjectInWorld: # type: ignor location_x = BEST_PAD_LOCATION_X location_y = BEST_PAD_LOCATION_Y spherical_variance = 1.0 - result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance) + result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance, "object") assert result assert pad is not None @@ -56,7 +56,7 @@ def best_pad_outside_tolerance() -> object_in_world.ObjectInWorld: # type: igno location_x = 100.0 location_y = 200.0 spherical_variance = 5.0 # variance outside tolerance - result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance) + result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance, "object") assert result assert pad is not None @@ -68,15 +68,15 @@ def pads() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Create a list of ObjectInWorld instances for the landing pads. """ - result, pad_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0) + result, pad_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0, "object") assert result assert pad_1 is not None - result, pad_2 = object_in_world.ObjectInWorld.create(50.0, 60.0, 3.0) + result, pad_2 = object_in_world.ObjectInWorld.create(50.0, 60.0, 3.0, "object") assert result assert pad_2 is not None - result, pad_3 = object_in_world.ObjectInWorld.create(70.0, 80.0, 4.0) + result, pad_3 = object_in_world.ObjectInWorld.create(70.0, 80.0, 4.0, "object") assert result assert pad_3 is not None From 99140d90587d27245cb714abb6fd0b1b2f5d3212 Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 27 Sep 2024 11:45:28 -0400 Subject: [PATCH 08/42] fixed black --check issue with test_decision.py --- tests/unit/test_decision.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_decision.py b/tests/unit/test_decision.py index 6c694be8..a18ce95a 100644 --- a/tests/unit/test_decision.py +++ b/tests/unit/test_decision.py @@ -41,7 +41,9 @@ def best_pad_within_tolerance() -> object_in_world.ObjectInWorld: # type: ignor location_x = BEST_PAD_LOCATION_X location_y = BEST_PAD_LOCATION_Y spherical_variance = 1.0 - result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance, "object") + result, pad = object_in_world.ObjectInWorld.create( + location_x, location_y, spherical_variance, "object" + ) assert result assert pad is not None @@ -56,7 +58,9 @@ def best_pad_outside_tolerance() -> object_in_world.ObjectInWorld: # type: igno location_x = 100.0 location_y = 200.0 spherical_variance = 5.0 # variance outside tolerance - result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance, "object") + result, pad = object_in_world.ObjectInWorld.create( + location_x, location_y, spherical_variance, "object" + ) assert result assert pad is not None From 4b1424d0eced9c1289ce7b906861f2410e2736dc Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 27 Sep 2024 12:22:36 -0400 Subject: [PATCH 09/42] fixed test_cluster_detection failed test case --- modules/cluster_estimation/cluster_estimation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 41cfcd5c..22fa8629 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -124,7 +124,7 @@ def __init__( def run( self, detections: "list[detection_in_world.DetectionInWorld]", run_override: bool - ) -> "tuple[bool, list[object_in_world.ObjectInWorld] | None]": + ) -> "tuple[bool, object_in_world.ObjectInWorld | None]": """ Take in list of landing pad detections and return list of estimated landing pad locations if number of detections is sufficient, or if manually forced to run. @@ -202,7 +202,7 @@ def run( ) if result: - detections_in_world.append([temp_object]) + detections_in_world.append(temp_object) return True, detections_in_world From 676bcd1ee1b5b52379f6f10410be7cc8b5eade49 Mon Sep 17 00:00:00 2001 From: cyuber Date: Mon, 30 Sep 2024 17:31:57 -0400 Subject: [PATCH 10/42] changed object_type: string to label: int, also made it keyword parameter with default 0 --- .../cluster_estimation/cluster_estimation.py | 1 - modules/object_in_world.py | 10 +-- tests/unit/test_decision.py | 14 ++-- tests/unit/test_landing_pad_tracking.py | 72 +++++++++---------- 4 files changed, 46 insertions(+), 51 deletions(-) diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 22fa8629..1e8c8d89 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -198,7 +198,6 @@ def run( cluster[0][0], cluster[0][1], cluster[2], - "object", ) if result: diff --git a/modules/object_in_world.py b/modules/object_in_world.py index 6b783949..a8310b11 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -12,18 +12,18 @@ class ObjectInWorld: @classmethod def create( - cls, location_x: float, location_y: float, spherical_variance: float, object_type: str + cls, location_x: float, location_y: float, spherical_variance: float, label=0 ) -> "tuple[bool, ObjectInWorld | None]": """ location_x, location_y: Location of the object. spherical_variance: Uncertainty of the location. - object_type: type of object in real world. + label: type of object in real world. """ if spherical_variance < 0.0: return False, None return True, ObjectInWorld( - cls.__create_key, location_x, location_y, spherical_variance, object_type + cls.__create_key, location_x, location_y, spherical_variance, label ) def __init__( @@ -32,7 +32,7 @@ def __init__( location_x: float, location_y: float, spherical_variance: float, - object_type: str, + label=0, ) -> None: """ Private constructor, use create() method. @@ -42,4 +42,4 @@ def __init__( self.location_x = location_x self.location_y = location_y self.spherical_variance = spherical_variance - self.object_type = object_type + self.label = label diff --git a/tests/unit/test_decision.py b/tests/unit/test_decision.py index a18ce95a..9b24211b 100644 --- a/tests/unit/test_decision.py +++ b/tests/unit/test_decision.py @@ -41,9 +41,7 @@ def best_pad_within_tolerance() -> object_in_world.ObjectInWorld: # type: ignor location_x = BEST_PAD_LOCATION_X location_y = BEST_PAD_LOCATION_Y spherical_variance = 1.0 - result, pad = object_in_world.ObjectInWorld.create( - location_x, location_y, spherical_variance, "object" - ) + result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance) assert result assert pad is not None @@ -58,9 +56,7 @@ def best_pad_outside_tolerance() -> object_in_world.ObjectInWorld: # type: igno location_x = 100.0 location_y = 200.0 spherical_variance = 5.0 # variance outside tolerance - result, pad = object_in_world.ObjectInWorld.create( - location_x, location_y, spherical_variance, "object" - ) + result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance) assert result assert pad is not None @@ -72,15 +68,15 @@ def pads() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Create a list of ObjectInWorld instances for the landing pads. """ - result, pad_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0, "object") + result, pad_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0) assert result assert pad_1 is not None - result, pad_2 = object_in_world.ObjectInWorld.create(50.0, 60.0, 3.0, "object") + result, pad_2 = object_in_world.ObjectInWorld.create(50.0, 60.0, 3.0) assert result assert pad_2 is not None - result, pad_3 = object_in_world.ObjectInWorld.create(70.0, 80.0, 4.0, "object") + result, pad_3 = object_in_world.ObjectInWorld.create(70.0, 80.0, 4.0) assert result assert pad_3 is not None diff --git a/tests/unit/test_landing_pad_tracking.py b/tests/unit/test_landing_pad_tracking.py index df257660..51bfc3f7 100644 --- a/tests/unit/test_landing_pad_tracking.py +++ b/tests/unit/test_landing_pad_tracking.py @@ -30,23 +30,23 @@ def detections_1() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 4, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 4) assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2, "object") + result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2) assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10, "object") + result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10) assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6, "object") + result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6) assert result assert obj_5 is not None @@ -59,23 +59,23 @@ def detections_2() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0.5, 0.5, 1, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0.5, 0.5, 1) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(1.5, 1.5, 3, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(1.5, 1.5, 3) assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(4, 4, 7, "object") + result, obj_3 = object_in_world.ObjectInWorld.create(4, 4, 7) assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(-4, -4, 5, "object") + result, obj_4 = object_in_world.ObjectInWorld.create(-4, -4, 5) assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(5, 5, 9, "object") + result, obj_5 = object_in_world.ObjectInWorld.create(5, 5, 9) assert result assert obj_5 is not None @@ -88,23 +88,23 @@ def detections_3() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 4, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 4) assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2, "object") + result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2) assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10, "object") + result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10) assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6, "object") + result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6) assert result assert obj_5 is not None @@ -123,11 +123,11 @@ def test_is_similar_positive_equal_to_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is equal to the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(1, 1, 0, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(1, 1, 0) assert result assert obj_2 is not None @@ -145,11 +145,11 @@ def test_is_similar_negative_equal_to_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is equal to the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-1, -1, 0, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(-1, -1, 0) assert result assert obj_2 is not None @@ -168,11 +168,11 @@ def test_is_similar_positive_less_than_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is less than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 0, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 0) assert result assert obj_2 is not None @@ -191,11 +191,11 @@ def test_is_similar_negative_less_than_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is less than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-0.5, -0.5, 0, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(-0.5, -0.5, 0) assert result assert obj_2 is not None @@ -214,11 +214,11 @@ def test_is_similar_positive_more_than_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is more than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 0, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 0) assert result assert obj_2 is not None @@ -237,11 +237,11 @@ def test_is_similar_negative_more_than_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is more than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-2, -2, 0, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(-2, -2, 0) assert result assert obj_2 is not None @@ -269,7 +269,7 @@ def test_mark_false_positive_no_similar( """ Test if marking false positive adds detection to list of false positives. """ - _, false_positive = object_in_world.ObjectInWorld.create(20, 20, 20, "object") + _, false_positive = object_in_world.ObjectInWorld.create(20, 20, 20) assert false_positive is not None tracker._LandingPadTracking__unconfirmed_positives = detections_1 # type: ignore @@ -296,7 +296,7 @@ def test_mark_false_positive_with_similar( Test if marking false positive adds detection to list of false positives and removes. similar landing pads """ - _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") + _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1) assert false_positive is not None tracker._LandingPadTracking__unconfirmed_positives = detections_2 # type: ignore @@ -316,10 +316,10 @@ def test_mark_multiple_false_positive( """ Test if marking false positive adds detection to list of false positives. """ - _, false_positive_1 = object_in_world.ObjectInWorld.create(0, 0, 1, "object") + _, false_positive_1 = object_in_world.ObjectInWorld.create(0, 0, 1) assert false_positive_1 is not None - _, false_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1, "object") + _, false_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1) assert false_positive_2 is not None tracker._LandingPadTracking__unconfirmed_positives = detections_1 # type: ignore @@ -344,7 +344,7 @@ def test_mark_confirmed_positive( """ Test if marking confirmed positive adds detection to list of confirmed positives. """ - _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") + _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1) assert confirmed_positive is not None expected = [confirmed_positive] @@ -359,10 +359,10 @@ def test_mark_multiple_confirmed_positives( """ Test if marking confirmed positive adds detection to list of confirmed positives. """ - _, confirmed_positive_1 = object_in_world.ObjectInWorld.create(1, 1, 1, "object") + _, confirmed_positive_1 = object_in_world.ObjectInWorld.create(1, 1, 1) assert confirmed_positive_1 is not None - _, confirmed_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1, "object") + _, confirmed_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1) assert confirmed_positive_2 is not None expected = [confirmed_positive_1, confirmed_positive_2] @@ -469,7 +469,7 @@ def test_run_with_confirmed_positive( """ Test run when there is a confirmed positive. """ - _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") + _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1) assert confirmed_positive is not None tracker._LandingPadTracking__confirmed_positives.append(confirmed_positive) # type: ignore @@ -488,7 +488,7 @@ def test_run_with_false_positive( """ Test to see if run function doesn't add landing pads that are similar to false positives. """ - _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") + _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1) assert false_positive is not None tracker._LandingPadTracking__false_positives.append(false_positive) # type: ignore From 647f73a52180bdf01a8276446ccb31e8c8b5d5a2 Mon Sep 17 00:00:00 2001 From: cyuber Date: Mon, 30 Sep 2024 17:51:53 -0400 Subject: [PATCH 11/42] went back to old version of main --- main_2024.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main_2024.py b/main_2024.py index fe76a1da..f7382369 100644 --- a/main_2024.py +++ b/main_2024.py @@ -137,6 +137,10 @@ def main() -> int: mp_manager, QUEUE_MAX_SIZE, ) + flight_interface_decision_queue = queue_proxy_wrapper.QueueProxyWrapper( + mp_manager, + QUEUE_MAX_SIZE, + ) result, camera_intrinsics = camera_properties.CameraIntrinsics.create( GEOLOCATION_RESOLUTION_X, @@ -216,7 +220,7 @@ def main() -> int: FLIGHT_INTERFACE_BAUD_RATE, FLIGHT_INTERFACE_WORKER_PERIOD, ), - input_queues=[], + input_queues=[flight_interface_decision_queue], output_queues=[flight_interface_to_data_merge_queue], controller=controller, local_logger=main_logger, @@ -376,6 +380,7 @@ def main() -> int: flight_interface_to_data_merge_queue.fill_and_drain_queue() data_merge_to_geolocation_queue.fill_and_drain_queue() geolocation_to_main_queue.fill_and_drain_queue() + flight_interface_decision_queue.fill_and_drain_queue() for manager in worker_managers: manager.join_workers() From 360a6cebb572bf8b0e2ab0590693062812df9b3a Mon Sep 17 00:00:00 2001 From: cyuber Date: Tue, 1 Oct 2024 21:50:24 -0400 Subject: [PATCH 12/42] initial commit for branch, work in progress --- config.yaml | 6 ++++++ main_2024.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/config.yaml b/config.yaml index c941f53a..7d5b7050 100644 --- a/config.yaml +++ b/config.yaml @@ -33,3 +33,9 @@ geolocation: camera_orientation_yaw: 0.0 camera_orientation_pitch: -1.57079632679 camera_orientation_roll: 0.0 + +# default values set +cluster_merge: + min_activation_threshold: 0 + min_new_points_to_run: 0 + random_state: 0 diff --git a/main_2024.py b/main_2024.py index f7382369..7265d1e8 100644 --- a/main_2024.py +++ b/main_2024.py @@ -18,6 +18,7 @@ from modules.data_merge import data_merge_worker from modules.geolocation import geolocation_worker from modules.geolocation import camera_properties +from modules.cluster_estimation import cluster_estimation_worker from modules.common.logger.modules import logger from modules.common.logger.modules import logger_setup_main from modules.common.logger.read_yaml.modules import read_yaml @@ -108,6 +109,10 @@ def main() -> int: GEOLOCATION_CAMERA_ORIENTATION_YAW = config["geolocation"]["camera_orientation_yaw"] GEOLOCATION_CAMERA_ORIENTATION_PITCH = config["geolocation"]["camera_orientation_pitch"] GEOLOCATION_CAMERA_ORIENTATION_ROLL = config["geolocation"]["camera_orientation_roll"] + + MIN_ACTIVATION_THRESHOLD = config + MIN_NEW_POINTS_TO_RUN = config + RANDOM_STATE = config # pylint: enable=invalid-name except KeyError as exception: main_logger.error(f"ERROR: Config key(s) not found: {exception}", True) @@ -133,11 +138,15 @@ def main() -> int: mp_manager, QUEUE_MAX_SIZE, ) - geolocation_to_main_queue = queue_proxy_wrapper.QueueProxyWrapper( + flight_interface_decision_queue = queue_proxy_wrapper.QueueProxyWrapper( mp_manager, QUEUE_MAX_SIZE, ) - flight_interface_decision_queue = queue_proxy_wrapper.QueueProxyWrapper( + geolocation_to_cluster_estimation_queue = queue_proxy_wrapper.QueueProxyWrapper( + mp_manager, + QUEUE_MAX_SIZE, + ) + cluster_estimation_to_main_queue = queue_proxy_wrapper.QueueProxyWrapper( mp_manager, QUEUE_MAX_SIZE, ) @@ -259,7 +268,7 @@ def main() -> int: camera_extrinsics, ), input_queues=[data_merge_to_geolocation_queue], - output_queues=[geolocation_to_main_queue], + output_queues=[geolocation_to_cluster_estimation_queue], controller=controller, local_logger=main_logger, ) @@ -270,6 +279,22 @@ def main() -> int: # Get Pylance to stop complaining assert geolocation_worker_properties is not None + result, cluster_estimation_worker_properties = worker_manager.WorkerProperties.create( + count=1, + target=cluster_estimation_worker.cluster_estimation_worker, + work_arguments=(MIN_ACTIVATION_THRESHOLD, MIN_NEW_POINTS_TO_RUN, RANDOM_STATE), + input_queues=[geolocation_to_cluster_estimation_queue], + output_queues=[cluster_estimation_to_main_queue], + controller=controller, + local_logger=main_logger, + ) + if not result: + main_logger.error("Failed to create arguments for Video Input", True) + return -1 + + # Get Pylance to stop complaining + assert cluster_estimation_worker_properties is not None + # Create managers worker_managers = [] @@ -338,6 +363,19 @@ def main() -> int: worker_managers.append(geolocation_manager) + result, cluster_estimation_manager = worker_manager.WorkerManager.create( + worker_properties=cluster_estimation_worker_properties, + local_logger=main_logger, + ) + if not result: + main_logger.error("Failed to create manager for Flight Interface", True) + return -1 + + # Get Pylance to stop complaining + assert cluster_estimation_manager is not None + + worker_managers.append(cluster_estimation_manager) + # Run for manager in worker_managers: manager.start_workers() @@ -350,7 +388,7 @@ def main() -> int: return -1 try: - geolocation_data = geolocation_to_main_queue.queue.get_nowait() + geolocation_data = geolocation_to_cluster_estimation_queue.queue.get_nowait() except queue.Empty: geolocation_data = None @@ -368,6 +406,16 @@ def main() -> int: "geolocation confidence: " + str(detection_world.confidence), True ) + try: + cluster_estimations = cluster_estimation_to_main_queue.queue.get_nowait() + except queue.Empty: + cluster_estimations = None + if cluster_estimations is not None: + for cluster in cluster_estimations: + main_logger.debug("Cluser in world: ", True) + main_logger.debug("Cluster location x: " + str(cluster.location_x)) + main_logger.debug("Cluster location y: "+str(cluster.location_y)) + main_logger.debug("Cluster spherical variance: "+str(cluster.spherical_variance)) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True) break @@ -379,7 +427,7 @@ def main() -> int: detect_target_to_data_merge_queue.fill_and_drain_queue() flight_interface_to_data_merge_queue.fill_and_drain_queue() data_merge_to_geolocation_queue.fill_and_drain_queue() - geolocation_to_main_queue.fill_and_drain_queue() + geolocation_to_cluster_estimation_queue.fill_and_drain_queue() flight_interface_decision_queue.fill_and_drain_queue() for manager in worker_managers: From eff583134501bfcb0c86a89b7769d1aa02d8482f Mon Sep 17 00:00:00 2001 From: cyuber Date: Thu, 26 Sep 2024 11:17:48 -0400 Subject: [PATCH 13/42] implemented string field for ObjectInWorld class to specify which type of real world object it is. --- modules/cluster_estimation/cluster_estimation.py | 8 +++++--- modules/object_in_world.py | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 31675f47..78d4ca3f 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -124,7 +124,7 @@ def __init__( def run( self, detections: "list[detection_in_world.DetectionInWorld]", run_override: bool - ) -> "tuple[bool, list[object_in_world.ObjectInWorld] | None]": + ) -> "tuple[bool, object_in_world.ObjectInWorld | None]": """ Take in list of landing pad detections and return list of estimated landing pad locations if number of detections is sufficient, or if manually forced to run. @@ -193,14 +193,16 @@ def run( # Create output list of remaining valid clusters detections_in_world = [] for cluster in model_output: - result, landing_pad = object_in_world.ObjectInWorld.create( + + result, object = object_in_world.ObjectInWorld.create( cluster[0][0], cluster[0][1], cluster[2], + "object" ) if result: - detections_in_world.append(landing_pad) + detections_in_world.append([object]) return True, detections_in_world diff --git a/modules/object_in_world.py b/modules/object_in_world.py index 1ce9f65e..bb51b391 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -12,7 +12,7 @@ class ObjectInWorld: @classmethod def create( - cls, location_x: float, location_y: float, spherical_variance: float + cls, location_x: float, location_y: float, spherical_variance: float, object_type: str ) -> "tuple[bool, ObjectInWorld | None]": """ location_x, location_y: Location of the object. @@ -21,7 +21,7 @@ def create( if spherical_variance < 0.0: return False, None - return True, ObjectInWorld(cls.__create_key, location_x, location_y, spherical_variance) + return True, ObjectInWorld(cls.__create_key, location_x, location_y, spherical_variance, object_type) def __init__( self, @@ -29,6 +29,7 @@ def __init__( location_x: float, location_y: float, spherical_variance: float, + object_type: str ) -> None: """ Private constructor, use create() method. @@ -38,3 +39,5 @@ def __init__( self.location_x = location_x self.location_y = location_y self.spherical_variance = spherical_variance + self.object_type = object_type + From 451e0e5ff072d3bd2d73c7bea517bc1176cbfe19 Mon Sep 17 00:00:00 2001 From: cyuber Date: Thu, 26 Sep 2024 11:40:54 -0400 Subject: [PATCH 14/42] fixed mistakenly changed annotation in ClusterElimination.run --- modules/cluster_estimation/cluster_estimation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 78d4ca3f..3f7caf3c 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -124,7 +124,7 @@ def __init__( def run( self, detections: "list[detection_in_world.DetectionInWorld]", run_override: bool - ) -> "tuple[bool, object_in_world.ObjectInWorld | None]": + ) -> "tuple[bool, list[object_in_world.ObjectInWorld] | None]": """ Take in list of landing pad detections and return list of estimated landing pad locations if number of detections is sufficient, or if manually forced to run. From c4f3cb9fc4b75e3a0a7fccb10600622f33e0b51b Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 27 Sep 2024 03:51:38 -0400 Subject: [PATCH 15/42] fixed linters --- modules/object_in_world.py | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/object_in_world.py b/modules/object_in_world.py index bb51b391..4e9fdef0 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -40,4 +40,3 @@ def __init__( self.location_y = location_y self.spherical_variance = spherical_variance self.object_type = object_type - From bc2c6f643ad998b7bbd45740276bb910f99acfae Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 27 Sep 2024 11:04:16 -0400 Subject: [PATCH 16/42] fixed black --check issues --- modules/cluster_estimation/cluster_estimation.py | 2 +- modules/object_in_world.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 3f7caf3c..4cfa5c6b 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -198,7 +198,7 @@ def run( cluster[0][0], cluster[0][1], cluster[2], - "object" + "object", ) if result: diff --git a/modules/object_in_world.py b/modules/object_in_world.py index 4e9fdef0..6b783949 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -17,11 +17,14 @@ def create( """ location_x, location_y: Location of the object. spherical_variance: Uncertainty of the location. + object_type: type of object in real world. """ if spherical_variance < 0.0: return False, None - return True, ObjectInWorld(cls.__create_key, location_x, location_y, spherical_variance, object_type) + return True, ObjectInWorld( + cls.__create_key, location_x, location_y, spherical_variance, object_type + ) def __init__( self, @@ -29,7 +32,7 @@ def __init__( location_x: float, location_y: float, spherical_variance: float, - object_type: str + object_type: str, ) -> None: """ Private constructor, use create() method. From cf55400b8c30f66417a8b84c92c04d5b00bec4ca Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 27 Sep 2024 11:22:06 -0400 Subject: [PATCH 17/42] fixed pylint issues --- modules/cluster_estimation/cluster_estimation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 4cfa5c6b..41cfcd5c 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -194,7 +194,7 @@ def run( detections_in_world = [] for cluster in model_output: - result, object = object_in_world.ObjectInWorld.create( + result, temp_object = object_in_world.ObjectInWorld.create( cluster[0][0], cluster[0][1], cluster[2], @@ -202,7 +202,7 @@ def run( ) if result: - detections_in_world.append([object]) + detections_in_world.append([temp_object]) return True, detections_in_world From 7dd1e9f269595c79457492d64f4e723c858f2ce1 Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 27 Sep 2024 11:29:20 -0400 Subject: [PATCH 18/42] fixed linters in test_landing_pad_tracking.py --- tests/unit/test_landing_pad_tracking.py | 72 ++++++++++++------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/unit/test_landing_pad_tracking.py b/tests/unit/test_landing_pad_tracking.py index 51bfc3f7..df257660 100644 --- a/tests/unit/test_landing_pad_tracking.py +++ b/tests/unit/test_landing_pad_tracking.py @@ -30,23 +30,23 @@ def detections_1() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 4) + result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 4, "object") assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2) + result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2, "object") assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10) + result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10, "object") assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6) + result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6, "object") assert result assert obj_5 is not None @@ -59,23 +59,23 @@ def detections_2() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0.5, 0.5, 1) + result, obj_1 = object_in_world.ObjectInWorld.create(0.5, 0.5, 1, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(1.5, 1.5, 3) + result, obj_2 = object_in_world.ObjectInWorld.create(1.5, 1.5, 3, "object") assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(4, 4, 7) + result, obj_3 = object_in_world.ObjectInWorld.create(4, 4, 7, "object") assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(-4, -4, 5) + result, obj_4 = object_in_world.ObjectInWorld.create(-4, -4, 5, "object") assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(5, 5, 9) + result, obj_5 = object_in_world.ObjectInWorld.create(5, 5, 9, "object") assert result assert obj_5 is not None @@ -88,23 +88,23 @@ def detections_3() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 4) + result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 4, "object") assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2) + result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2, "object") assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10) + result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10, "object") assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6) + result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6, "object") assert result assert obj_5 is not None @@ -123,11 +123,11 @@ def test_is_similar_positive_equal_to_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is equal to the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(1, 1, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(1, 1, 0, "object") assert result assert obj_2 is not None @@ -145,11 +145,11 @@ def test_is_similar_negative_equal_to_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is equal to the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-1, -1, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(-1, -1, 0, "object") assert result assert obj_2 is not None @@ -168,11 +168,11 @@ def test_is_similar_positive_less_than_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is less than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 0, "object") assert result assert obj_2 is not None @@ -191,11 +191,11 @@ def test_is_similar_negative_less_than_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is less than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-0.5, -0.5, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(-0.5, -0.5, 0, "object") assert result assert obj_2 is not None @@ -214,11 +214,11 @@ def test_is_similar_positive_more_than_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is more than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 0, "object") assert result assert obj_2 is not None @@ -237,11 +237,11 @@ def test_is_similar_negative_more_than_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is more than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-2, -2, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(-2, -2, 0, "object") assert result assert obj_2 is not None @@ -269,7 +269,7 @@ def test_mark_false_positive_no_similar( """ Test if marking false positive adds detection to list of false positives. """ - _, false_positive = object_in_world.ObjectInWorld.create(20, 20, 20) + _, false_positive = object_in_world.ObjectInWorld.create(20, 20, 20, "object") assert false_positive is not None tracker._LandingPadTracking__unconfirmed_positives = detections_1 # type: ignore @@ -296,7 +296,7 @@ def test_mark_false_positive_with_similar( Test if marking false positive adds detection to list of false positives and removes. similar landing pads """ - _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") assert false_positive is not None tracker._LandingPadTracking__unconfirmed_positives = detections_2 # type: ignore @@ -316,10 +316,10 @@ def test_mark_multiple_false_positive( """ Test if marking false positive adds detection to list of false positives. """ - _, false_positive_1 = object_in_world.ObjectInWorld.create(0, 0, 1) + _, false_positive_1 = object_in_world.ObjectInWorld.create(0, 0, 1, "object") assert false_positive_1 is not None - _, false_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1) + _, false_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1, "object") assert false_positive_2 is not None tracker._LandingPadTracking__unconfirmed_positives = detections_1 # type: ignore @@ -344,7 +344,7 @@ def test_mark_confirmed_positive( """ Test if marking confirmed positive adds detection to list of confirmed positives. """ - _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") assert confirmed_positive is not None expected = [confirmed_positive] @@ -359,10 +359,10 @@ def test_mark_multiple_confirmed_positives( """ Test if marking confirmed positive adds detection to list of confirmed positives. """ - _, confirmed_positive_1 = object_in_world.ObjectInWorld.create(1, 1, 1) + _, confirmed_positive_1 = object_in_world.ObjectInWorld.create(1, 1, 1, "object") assert confirmed_positive_1 is not None - _, confirmed_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1) + _, confirmed_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1, "object") assert confirmed_positive_2 is not None expected = [confirmed_positive_1, confirmed_positive_2] @@ -469,7 +469,7 @@ def test_run_with_confirmed_positive( """ Test run when there is a confirmed positive. """ - _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") assert confirmed_positive is not None tracker._LandingPadTracking__confirmed_positives.append(confirmed_positive) # type: ignore @@ -488,7 +488,7 @@ def test_run_with_false_positive( """ Test to see if run function doesn't add landing pads that are similar to false positives. """ - _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") assert false_positive is not None tracker._LandingPadTracking__false_positives.append(false_positive) # type: ignore From a5da749ee2c34a1b150fe7ec5ab407e77358fbad Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 27 Sep 2024 11:34:41 -0400 Subject: [PATCH 19/42] fixed linter issues in test_decision.py --- tests/unit/test_decision.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit/test_decision.py b/tests/unit/test_decision.py index 9b24211b..6c694be8 100644 --- a/tests/unit/test_decision.py +++ b/tests/unit/test_decision.py @@ -41,7 +41,7 @@ def best_pad_within_tolerance() -> object_in_world.ObjectInWorld: # type: ignor location_x = BEST_PAD_LOCATION_X location_y = BEST_PAD_LOCATION_Y spherical_variance = 1.0 - result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance) + result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance, "object") assert result assert pad is not None @@ -56,7 +56,7 @@ def best_pad_outside_tolerance() -> object_in_world.ObjectInWorld: # type: igno location_x = 100.0 location_y = 200.0 spherical_variance = 5.0 # variance outside tolerance - result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance) + result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance, "object") assert result assert pad is not None @@ -68,15 +68,15 @@ def pads() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Create a list of ObjectInWorld instances for the landing pads. """ - result, pad_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0) + result, pad_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0, "object") assert result assert pad_1 is not None - result, pad_2 = object_in_world.ObjectInWorld.create(50.0, 60.0, 3.0) + result, pad_2 = object_in_world.ObjectInWorld.create(50.0, 60.0, 3.0, "object") assert result assert pad_2 is not None - result, pad_3 = object_in_world.ObjectInWorld.create(70.0, 80.0, 4.0) + result, pad_3 = object_in_world.ObjectInWorld.create(70.0, 80.0, 4.0, "object") assert result assert pad_3 is not None From 96618fbc1a25c28b8984cfd7e183ba9f2273ab08 Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 27 Sep 2024 11:45:28 -0400 Subject: [PATCH 20/42] fixed black --check issue with test_decision.py --- tests/unit/test_decision.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_decision.py b/tests/unit/test_decision.py index 6c694be8..a18ce95a 100644 --- a/tests/unit/test_decision.py +++ b/tests/unit/test_decision.py @@ -41,7 +41,9 @@ def best_pad_within_tolerance() -> object_in_world.ObjectInWorld: # type: ignor location_x = BEST_PAD_LOCATION_X location_y = BEST_PAD_LOCATION_Y spherical_variance = 1.0 - result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance, "object") + result, pad = object_in_world.ObjectInWorld.create( + location_x, location_y, spherical_variance, "object" + ) assert result assert pad is not None @@ -56,7 +58,9 @@ def best_pad_outside_tolerance() -> object_in_world.ObjectInWorld: # type: igno location_x = 100.0 location_y = 200.0 spherical_variance = 5.0 # variance outside tolerance - result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance, "object") + result, pad = object_in_world.ObjectInWorld.create( + location_x, location_y, spherical_variance, "object" + ) assert result assert pad is not None From b3f068d00aaf6331f4750f6ed0de25cc61a81f91 Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 27 Sep 2024 12:22:36 -0400 Subject: [PATCH 21/42] fixed test_cluster_detection failed test case --- modules/cluster_estimation/cluster_estimation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 41cfcd5c..22fa8629 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -124,7 +124,7 @@ def __init__( def run( self, detections: "list[detection_in_world.DetectionInWorld]", run_override: bool - ) -> "tuple[bool, list[object_in_world.ObjectInWorld] | None]": + ) -> "tuple[bool, object_in_world.ObjectInWorld | None]": """ Take in list of landing pad detections and return list of estimated landing pad locations if number of detections is sufficient, or if manually forced to run. @@ -202,7 +202,7 @@ def run( ) if result: - detections_in_world.append([temp_object]) + detections_in_world.append(temp_object) return True, detections_in_world From 0916b10a633ef507304a4151d7527b283b560552 Mon Sep 17 00:00:00 2001 From: cyuber Date: Mon, 30 Sep 2024 17:31:57 -0400 Subject: [PATCH 22/42] changed object_type: string to label: int, also made it keyword parameter with default 0 --- .../cluster_estimation/cluster_estimation.py | 1 - modules/object_in_world.py | 10 +-- tests/unit/test_decision.py | 14 ++-- tests/unit/test_landing_pad_tracking.py | 72 +++++++++---------- 4 files changed, 46 insertions(+), 51 deletions(-) diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 22fa8629..1e8c8d89 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -198,7 +198,6 @@ def run( cluster[0][0], cluster[0][1], cluster[2], - "object", ) if result: diff --git a/modules/object_in_world.py b/modules/object_in_world.py index 6b783949..a8310b11 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -12,18 +12,18 @@ class ObjectInWorld: @classmethod def create( - cls, location_x: float, location_y: float, spherical_variance: float, object_type: str + cls, location_x: float, location_y: float, spherical_variance: float, label=0 ) -> "tuple[bool, ObjectInWorld | None]": """ location_x, location_y: Location of the object. spherical_variance: Uncertainty of the location. - object_type: type of object in real world. + label: type of object in real world. """ if spherical_variance < 0.0: return False, None return True, ObjectInWorld( - cls.__create_key, location_x, location_y, spherical_variance, object_type + cls.__create_key, location_x, location_y, spherical_variance, label ) def __init__( @@ -32,7 +32,7 @@ def __init__( location_x: float, location_y: float, spherical_variance: float, - object_type: str, + label=0, ) -> None: """ Private constructor, use create() method. @@ -42,4 +42,4 @@ def __init__( self.location_x = location_x self.location_y = location_y self.spherical_variance = spherical_variance - self.object_type = object_type + self.label = label diff --git a/tests/unit/test_decision.py b/tests/unit/test_decision.py index a18ce95a..9b24211b 100644 --- a/tests/unit/test_decision.py +++ b/tests/unit/test_decision.py @@ -41,9 +41,7 @@ def best_pad_within_tolerance() -> object_in_world.ObjectInWorld: # type: ignor location_x = BEST_PAD_LOCATION_X location_y = BEST_PAD_LOCATION_Y spherical_variance = 1.0 - result, pad = object_in_world.ObjectInWorld.create( - location_x, location_y, spherical_variance, "object" - ) + result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance) assert result assert pad is not None @@ -58,9 +56,7 @@ def best_pad_outside_tolerance() -> object_in_world.ObjectInWorld: # type: igno location_x = 100.0 location_y = 200.0 spherical_variance = 5.0 # variance outside tolerance - result, pad = object_in_world.ObjectInWorld.create( - location_x, location_y, spherical_variance, "object" - ) + result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance) assert result assert pad is not None @@ -72,15 +68,15 @@ def pads() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Create a list of ObjectInWorld instances for the landing pads. """ - result, pad_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0, "object") + result, pad_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0) assert result assert pad_1 is not None - result, pad_2 = object_in_world.ObjectInWorld.create(50.0, 60.0, 3.0, "object") + result, pad_2 = object_in_world.ObjectInWorld.create(50.0, 60.0, 3.0) assert result assert pad_2 is not None - result, pad_3 = object_in_world.ObjectInWorld.create(70.0, 80.0, 4.0, "object") + result, pad_3 = object_in_world.ObjectInWorld.create(70.0, 80.0, 4.0) assert result assert pad_3 is not None diff --git a/tests/unit/test_landing_pad_tracking.py b/tests/unit/test_landing_pad_tracking.py index df257660..51bfc3f7 100644 --- a/tests/unit/test_landing_pad_tracking.py +++ b/tests/unit/test_landing_pad_tracking.py @@ -30,23 +30,23 @@ def detections_1() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 4, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 4) assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2, "object") + result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2) assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10, "object") + result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10) assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6, "object") + result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6) assert result assert obj_5 is not None @@ -59,23 +59,23 @@ def detections_2() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0.5, 0.5, 1, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0.5, 0.5, 1) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(1.5, 1.5, 3, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(1.5, 1.5, 3) assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(4, 4, 7, "object") + result, obj_3 = object_in_world.ObjectInWorld.create(4, 4, 7) assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(-4, -4, 5, "object") + result, obj_4 = object_in_world.ObjectInWorld.create(-4, -4, 5) assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(5, 5, 9, "object") + result, obj_5 = object_in_world.ObjectInWorld.create(5, 5, 9) assert result assert obj_5 is not None @@ -88,23 +88,23 @@ def detections_3() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 4, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 4) assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2, "object") + result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2) assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10, "object") + result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10) assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6, "object") + result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6) assert result assert obj_5 is not None @@ -123,11 +123,11 @@ def test_is_similar_positive_equal_to_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is equal to the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(1, 1, 0, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(1, 1, 0) assert result assert obj_2 is not None @@ -145,11 +145,11 @@ def test_is_similar_negative_equal_to_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is equal to the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-1, -1, 0, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(-1, -1, 0) assert result assert obj_2 is not None @@ -168,11 +168,11 @@ def test_is_similar_positive_less_than_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is less than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 0, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 0) assert result assert obj_2 is not None @@ -191,11 +191,11 @@ def test_is_similar_negative_less_than_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is less than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-0.5, -0.5, 0, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(-0.5, -0.5, 0) assert result assert obj_2 is not None @@ -214,11 +214,11 @@ def test_is_similar_positive_more_than_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is more than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 0, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 0) assert result assert obj_2 is not None @@ -237,11 +237,11 @@ def test_is_similar_negative_more_than_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is more than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, "object") + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-2, -2, 0, "object") + result, obj_2 = object_in_world.ObjectInWorld.create(-2, -2, 0) assert result assert obj_2 is not None @@ -269,7 +269,7 @@ def test_mark_false_positive_no_similar( """ Test if marking false positive adds detection to list of false positives. """ - _, false_positive = object_in_world.ObjectInWorld.create(20, 20, 20, "object") + _, false_positive = object_in_world.ObjectInWorld.create(20, 20, 20) assert false_positive is not None tracker._LandingPadTracking__unconfirmed_positives = detections_1 # type: ignore @@ -296,7 +296,7 @@ def test_mark_false_positive_with_similar( Test if marking false positive adds detection to list of false positives and removes. similar landing pads """ - _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") + _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1) assert false_positive is not None tracker._LandingPadTracking__unconfirmed_positives = detections_2 # type: ignore @@ -316,10 +316,10 @@ def test_mark_multiple_false_positive( """ Test if marking false positive adds detection to list of false positives. """ - _, false_positive_1 = object_in_world.ObjectInWorld.create(0, 0, 1, "object") + _, false_positive_1 = object_in_world.ObjectInWorld.create(0, 0, 1) assert false_positive_1 is not None - _, false_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1, "object") + _, false_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1) assert false_positive_2 is not None tracker._LandingPadTracking__unconfirmed_positives = detections_1 # type: ignore @@ -344,7 +344,7 @@ def test_mark_confirmed_positive( """ Test if marking confirmed positive adds detection to list of confirmed positives. """ - _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") + _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1) assert confirmed_positive is not None expected = [confirmed_positive] @@ -359,10 +359,10 @@ def test_mark_multiple_confirmed_positives( """ Test if marking confirmed positive adds detection to list of confirmed positives. """ - _, confirmed_positive_1 = object_in_world.ObjectInWorld.create(1, 1, 1, "object") + _, confirmed_positive_1 = object_in_world.ObjectInWorld.create(1, 1, 1) assert confirmed_positive_1 is not None - _, confirmed_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1, "object") + _, confirmed_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1) assert confirmed_positive_2 is not None expected = [confirmed_positive_1, confirmed_positive_2] @@ -469,7 +469,7 @@ def test_run_with_confirmed_positive( """ Test run when there is a confirmed positive. """ - _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") + _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1) assert confirmed_positive is not None tracker._LandingPadTracking__confirmed_positives.append(confirmed_positive) # type: ignore @@ -488,7 +488,7 @@ def test_run_with_false_positive( """ Test to see if run function doesn't add landing pads that are similar to false positives. """ - _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1, "object") + _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1) assert false_positive is not None tracker._LandingPadTracking__false_positives.append(false_positive) # type: ignore From 652e1dacce9944509a636b0a029abb02c6a9d664 Mon Sep 17 00:00:00 2001 From: cyuber Date: Tue, 1 Oct 2024 21:50:24 -0400 Subject: [PATCH 23/42] initial commit for branch, work in progress --- config.yaml | 6 ++++++ main_2024.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/config.yaml b/config.yaml index b0dd9811..e9ee958b 100644 --- a/config.yaml +++ b/config.yaml @@ -34,3 +34,9 @@ geolocation: camera_orientation_yaw: 0.0 camera_orientation_pitch: -1.57079632679 camera_orientation_roll: 0.0 + +# default values set +cluster_merge: + min_activation_threshold: 0 + min_new_points_to_run: 0 + random_state: 0 diff --git a/main_2024.py b/main_2024.py index 66ad913d..5756b870 100644 --- a/main_2024.py +++ b/main_2024.py @@ -19,6 +19,7 @@ from modules.data_merge import data_merge_worker from modules.geolocation import geolocation_worker from modules.geolocation import camera_properties +from modules.cluster_estimation import cluster_estimation_worker from modules.common.logger.modules import logger from modules.common.logger.modules import logger_setup_main from modules.common.logger.read_yaml.modules import read_yaml @@ -111,6 +112,10 @@ def main() -> int: GEOLOCATION_CAMERA_ORIENTATION_YAW = config["geolocation"]["camera_orientation_yaw"] GEOLOCATION_CAMERA_ORIENTATION_PITCH = config["geolocation"]["camera_orientation_pitch"] GEOLOCATION_CAMERA_ORIENTATION_ROLL = config["geolocation"]["camera_orientation_roll"] + + MIN_ACTIVATION_THRESHOLD = config + MIN_NEW_POINTS_TO_RUN = config + RANDOM_STATE = config # pylint: enable=invalid-name except KeyError as exception: main_logger.error(f"Config key(s) not found: {exception}", True) @@ -139,11 +144,15 @@ def main() -> int: mp_manager, QUEUE_MAX_SIZE, ) - geolocation_to_main_queue = queue_proxy_wrapper.QueueProxyWrapper( + flight_interface_decision_queue = queue_proxy_wrapper.QueueProxyWrapper( mp_manager, QUEUE_MAX_SIZE, ) - flight_interface_decision_queue = queue_proxy_wrapper.QueueProxyWrapper( + geolocation_to_cluster_estimation_queue = queue_proxy_wrapper.QueueProxyWrapper( + mp_manager, + QUEUE_MAX_SIZE, + ) + cluster_estimation_to_main_queue = queue_proxy_wrapper.QueueProxyWrapper( mp_manager, QUEUE_MAX_SIZE, ) @@ -266,7 +275,7 @@ def main() -> int: camera_extrinsics, ), input_queues=[data_merge_to_geolocation_queue], - output_queues=[geolocation_to_main_queue], + output_queues=[geolocation_to_cluster_estimation_queue], controller=controller, local_logger=main_logger, ) @@ -277,6 +286,22 @@ def main() -> int: # Get Pylance to stop complaining assert geolocation_worker_properties is not None + result, cluster_estimation_worker_properties = worker_manager.WorkerProperties.create( + count=1, + target=cluster_estimation_worker.cluster_estimation_worker, + work_arguments=(MIN_ACTIVATION_THRESHOLD, MIN_NEW_POINTS_TO_RUN, RANDOM_STATE), + input_queues=[geolocation_to_cluster_estimation_queue], + output_queues=[cluster_estimation_to_main_queue], + controller=controller, + local_logger=main_logger, + ) + if not result: + main_logger.error("Failed to create arguments for Video Input", True) + return -1 + + # Get Pylance to stop complaining + assert cluster_estimation_worker_properties is not None + # Create managers worker_managers = [] @@ -345,6 +370,19 @@ def main() -> int: worker_managers.append(geolocation_manager) + result, cluster_estimation_manager = worker_manager.WorkerManager.create( + worker_properties=cluster_estimation_worker_properties, + local_logger=main_logger, + ) + if not result: + main_logger.error("Failed to create manager for Flight Interface", True) + return -1 + + # Get Pylance to stop complaining + assert cluster_estimation_manager is not None + + worker_managers.append(cluster_estimation_manager) + # Run for manager in worker_managers: manager.start_workers() @@ -357,7 +395,7 @@ def main() -> int: return -1 try: - geolocation_data = geolocation_to_main_queue.queue.get_nowait() + geolocation_data = geolocation_to_cluster_estimation_queue.queue.get_nowait() except queue.Empty: geolocation_data = None @@ -375,6 +413,16 @@ def main() -> int: "geolocation confidence: " + str(detection_world.confidence), True ) + try: + cluster_estimations = cluster_estimation_to_main_queue.queue.get_nowait() + except queue.Empty: + cluster_estimations = None + if cluster_estimations is not None: + for cluster in cluster_estimations: + main_logger.debug("Cluser in world: ", True) + main_logger.debug("Cluster location x: " + str(cluster.location_x)) + main_logger.debug("Cluster location y: "+str(cluster.location_y)) + main_logger.debug("Cluster spherical variance: "+str(cluster.spherical_variance)) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True) break @@ -386,7 +434,7 @@ def main() -> int: detect_target_to_data_merge_queue.fill_and_drain_queue() flight_interface_to_data_merge_queue.fill_and_drain_queue() data_merge_to_geolocation_queue.fill_and_drain_queue() - geolocation_to_main_queue.fill_and_drain_queue() + geolocation_to_cluster_estimation_queue.fill_and_drain_queue() flight_interface_decision_queue.fill_and_drain_queue() for manager in worker_managers: From 7476ddbdf239a7cd5abc744b691aebc884ab31a8 Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 4 Oct 2024 15:48:30 -0400 Subject: [PATCH 24/42] used black --preview to reformat the code --- main_2024.py | 16 ++++++++-------- modules/cluster_estimation/cluster_estimation.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/main_2024.py b/main_2024.py index 5756b870..85aae8ab 100644 --- a/main_2024.py +++ b/main_2024.py @@ -86,8 +86,8 @@ def main() -> int: VIDEO_INPUT_SAVE_PREFIX = str(pathlib.Path(logging_path, VIDEO_INPUT_SAVE_NAME_PREFIX)) DETECT_TARGET_WORKER_COUNT = config["detect_target"]["worker_count"] - detect_target_option_int = config["detect_target"]["option"] - DETECT_TARGET_OPTION = detect_target_factory.DetectTargetOption(detect_target_option_int) + DETECT_TARGET_OPTION_INT = config["detect_target"]["option"] + DETECT_TARGET_OPTION = detect_target_factory.DetectTargetOption(DETECT_TARGET_OPTION_INT) DETECT_TARGET_DEVICE = "cpu" if args.cpu else config["detect_target"]["device"] DETECT_TARGET_MODEL_PATH = config["detect_target"]["model_path"] DETECT_TARGET_OVERRIDE_FULL_PRECISION = args.full @@ -113,9 +113,9 @@ def main() -> int: GEOLOCATION_CAMERA_ORIENTATION_PITCH = config["geolocation"]["camera_orientation_pitch"] GEOLOCATION_CAMERA_ORIENTATION_ROLL = config["geolocation"]["camera_orientation_roll"] - MIN_ACTIVATION_THRESHOLD = config - MIN_NEW_POINTS_TO_RUN = config - RANDOM_STATE = config + MIN_ACTIVATION_THRESHOLD = config["cluster_merge"]["min_activation_threshold"] + MIN_NEW_POINTS_TO_RUN = config["cluster_merge"]["min_new_points_to_run"] + RANDOM_STATE = config["cluster_merge"]["random_state"] # pylint: enable=invalid-name except KeyError as exception: main_logger.error(f"Config key(s) not found: {exception}", True) @@ -419,10 +419,10 @@ def main() -> int: cluster_estimations = None if cluster_estimations is not None: for cluster in cluster_estimations: - main_logger.debug("Cluser in world: ", True) + main_logger.debug("Cluser in world: True") main_logger.debug("Cluster location x: " + str(cluster.location_x)) - main_logger.debug("Cluster location y: "+str(cluster.location_y)) - main_logger.debug("Cluster spherical variance: "+str(cluster.spherical_variance)) + main_logger.debug("Cluster location y: " + str(cluster.location_y)) + main_logger.debug("Cluster spherical variance: " + str(cluster.spherical_variance)) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True) break diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 1e8c8d89..e8039f8d 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -1,6 +1,6 @@ """ Take in bounding box coordinates from Geolocation and use to estimate landing pad locations. -Returns an array of classes, each containing the x coordinate, y coordinate, and spherical +Returns an array of classes, each containing the x coordinate, y coordinate, and spherical covariance of each landing pad estimation. """ From bc65465528598b6bc383f46fc85dd119070450da Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 4 Oct 2024 16:01:08 -0400 Subject: [PATCH 25/42] ran black . to reformat --- main_2024.py | 1 - 1 file changed, 1 deletion(-) diff --git a/main_2024.py b/main_2024.py index 298d1908..5580fcae 100644 --- a/main_2024.py +++ b/main_2024.py @@ -153,7 +153,6 @@ def main() -> int: mp_manager, QUEUE_MAX_SIZE, ) - cluster_estimation_to_main_queue = queue_proxy_wrapper.QueueProxyWrapper( flight_interface_decision_queue = queue_proxy_wrapper.QueueProxyWrapper( mp_manager, QUEUE_MAX_SIZE, From 4b6abb68149a3edb5fd88ca722dc5ece0807c406 Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 4 Oct 2024 16:05:22 -0400 Subject: [PATCH 26/42] changed label annotation --- modules/object_in_world.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/object_in_world.py b/modules/object_in_world.py index a8310b11..2b6f7ef0 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -12,7 +12,7 @@ class ObjectInWorld: @classmethod def create( - cls, location_x: float, location_y: float, spherical_variance: float, label=0 + cls, location_x: float, location_y: float, spherical_variance: float, label: int ) -> "tuple[bool, ObjectInWorld | None]": """ location_x, location_y: Location of the object. @@ -23,7 +23,7 @@ def create( return False, None return True, ObjectInWorld( - cls.__create_key, location_x, location_y, spherical_variance, label + cls.__create_key, location_x, location_y, spherical_variance, label: int ) def __init__( @@ -32,7 +32,7 @@ def __init__( location_x: float, location_y: float, spherical_variance: float, - label=0, + label: int, ) -> None: """ Private constructor, use create() method. From 808c4a2f2cff00aabd0ef0e354d983d07d068c3d Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 4 Oct 2024 16:07:37 -0400 Subject: [PATCH 27/42] syntax error --- modules/object_in_world.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/object_in_world.py b/modules/object_in_world.py index 2b6f7ef0..0dc413c6 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -23,7 +23,7 @@ def create( return False, None return True, ObjectInWorld( - cls.__create_key, location_x, location_y, spherical_variance, label: int + cls.__create_key, location_x, location_y, spherical_variance, label ) def __init__( From a58c56a66f4858f6ae30a2ce4fb9a4e70a2d6ef9 Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 4 Oct 2024 18:54:31 -0400 Subject: [PATCH 28/42] added values back for label --- main_2024.py | 1 - .../cluster_estimation/cluster_estimation.py | 1 + tests/unit/test_decision.py | 10 +-- tests/unit/test_landing_pad_tracking.py | 72 +++++++++---------- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/main_2024.py b/main_2024.py index 5580fcae..6756232c 100644 --- a/main_2024.py +++ b/main_2024.py @@ -20,7 +20,6 @@ from modules.geolocation import geolocation_worker from modules.geolocation import camera_properties from modules.cluster_estimation import cluster_estimation_worker -from modules.cluster_estimation import cluster_estimation_worker from modules.common.logger.modules import logger from modules.common.logger.modules import logger_setup_main from modules.common.logger.read_yaml.modules import read_yaml diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index e8039f8d..2bc5d58f 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -198,6 +198,7 @@ def run( cluster[0][0], cluster[0][1], cluster[2], + 0, ) if result: diff --git a/tests/unit/test_decision.py b/tests/unit/test_decision.py index 9b24211b..e073d6ee 100644 --- a/tests/unit/test_decision.py +++ b/tests/unit/test_decision.py @@ -41,7 +41,7 @@ def best_pad_within_tolerance() -> object_in_world.ObjectInWorld: # type: ignor location_x = BEST_PAD_LOCATION_X location_y = BEST_PAD_LOCATION_Y spherical_variance = 1.0 - result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance) + result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance, 0) assert result assert pad is not None @@ -56,7 +56,7 @@ def best_pad_outside_tolerance() -> object_in_world.ObjectInWorld: # type: igno location_x = 100.0 location_y = 200.0 spherical_variance = 5.0 # variance outside tolerance - result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance) + result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance, 0) assert result assert pad is not None @@ -68,15 +68,15 @@ def pads() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Create a list of ObjectInWorld instances for the landing pads. """ - result, pad_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0) + result, pad_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0, 0) assert result assert pad_1 is not None - result, pad_2 = object_in_world.ObjectInWorld.create(50.0, 60.0, 3.0) + result, pad_2 = object_in_world.ObjectInWorld.create(50.0, 60.0, 3.0, 0) assert result assert pad_2 is not None - result, pad_3 = object_in_world.ObjectInWorld.create(70.0, 80.0, 4.0) + result, pad_3 = object_in_world.ObjectInWorld.create(70.0, 80.0, 4.0, 0) assert result assert pad_3 is not None diff --git a/tests/unit/test_landing_pad_tracking.py b/tests/unit/test_landing_pad_tracking.py index 51bfc3f7..2105c84a 100644 --- a/tests/unit/test_landing_pad_tracking.py +++ b/tests/unit/test_landing_pad_tracking.py @@ -30,23 +30,23 @@ def detections_1() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 4) + result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 4, 0) assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2) + result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2, 0) assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10) + result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10, 0) assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6) + result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6, 0) assert result assert obj_5 is not None @@ -59,23 +59,23 @@ def detections_2() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0.5, 0.5, 1) + result, obj_1 = object_in_world.ObjectInWorld.create(0.5, 0.5, 1, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(1.5, 1.5, 3) + result, obj_2 = object_in_world.ObjectInWorld.create(1.5, 1.5, 3, 0) assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(4, 4, 7) + result, obj_3 = object_in_world.ObjectInWorld.create(4, 4, 7, 0) assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(-4, -4, 5) + result, obj_4 = object_in_world.ObjectInWorld.create(-4, -4, 5, 0) assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(5, 5, 9) + result, obj_5 = object_in_world.ObjectInWorld.create(5, 5, 9, 0) assert result assert obj_5 is not None @@ -88,23 +88,23 @@ def detections_3() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 4) + result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 4, 0) assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2) + result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2, 0) assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10) + result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10, 0) assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6) + result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6, 0) assert result assert obj_5 is not None @@ -123,11 +123,11 @@ def test_is_similar_positive_equal_to_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is equal to the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(1, 1, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(1, 1, 0, 0) assert result assert obj_2 is not None @@ -145,11 +145,11 @@ def test_is_similar_negative_equal_to_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is equal to the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-1, -1, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(-1, -1, 0, 0) assert result assert obj_2 is not None @@ -168,11 +168,11 @@ def test_is_similar_positive_less_than_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is less than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 0, 0) assert result assert obj_2 is not None @@ -191,11 +191,11 @@ def test_is_similar_negative_less_than_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is less than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-0.5, -0.5, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(-0.5, -0.5, 0, 0) assert result assert obj_2 is not None @@ -214,11 +214,11 @@ def test_is_similar_positive_more_than_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is more than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 0, 0) assert result assert obj_2 is not None @@ -237,11 +237,11 @@ def test_is_similar_negative_more_than_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is more than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-2, -2, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(-2, -2, 0, 0) assert result assert obj_2 is not None @@ -269,7 +269,7 @@ def test_mark_false_positive_no_similar( """ Test if marking false positive adds detection to list of false positives. """ - _, false_positive = object_in_world.ObjectInWorld.create(20, 20, 20) + _, false_positive = object_in_world.ObjectInWorld.create(20, 20, 20, 0) assert false_positive is not None tracker._LandingPadTracking__unconfirmed_positives = detections_1 # type: ignore @@ -296,7 +296,7 @@ def test_mark_false_positive_with_similar( Test if marking false positive adds detection to list of false positives and removes. similar landing pads """ - _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1, 0) assert false_positive is not None tracker._LandingPadTracking__unconfirmed_positives = detections_2 # type: ignore @@ -316,10 +316,10 @@ def test_mark_multiple_false_positive( """ Test if marking false positive adds detection to list of false positives. """ - _, false_positive_1 = object_in_world.ObjectInWorld.create(0, 0, 1) + _, false_positive_1 = object_in_world.ObjectInWorld.create(0, 0, 1, 0) assert false_positive_1 is not None - _, false_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1) + _, false_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1, 0) assert false_positive_2 is not None tracker._LandingPadTracking__unconfirmed_positives = detections_1 # type: ignore @@ -344,7 +344,7 @@ def test_mark_confirmed_positive( """ Test if marking confirmed positive adds detection to list of confirmed positives. """ - _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1, 0) assert confirmed_positive is not None expected = [confirmed_positive] @@ -359,10 +359,10 @@ def test_mark_multiple_confirmed_positives( """ Test if marking confirmed positive adds detection to list of confirmed positives. """ - _, confirmed_positive_1 = object_in_world.ObjectInWorld.create(1, 1, 1) + _, confirmed_positive_1 = object_in_world.ObjectInWorld.create(1, 1, 1, 0) assert confirmed_positive_1 is not None - _, confirmed_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1) + _, confirmed_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1, 0) assert confirmed_positive_2 is not None expected = [confirmed_positive_1, confirmed_positive_2] @@ -469,7 +469,7 @@ def test_run_with_confirmed_positive( """ Test run when there is a confirmed positive. """ - _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1, 0) assert confirmed_positive is not None tracker._LandingPadTracking__confirmed_positives.append(confirmed_positive) # type: ignore @@ -488,7 +488,7 @@ def test_run_with_false_positive( """ Test to see if run function doesn't add landing pads that are similar to false positives. """ - _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1, 0) assert false_positive is not None tracker._LandingPadTracking__false_positives.append(false_positive) # type: ignore From c74a1f49b1ca21926559ea61fb5a46114368df64 Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 4 Oct 2024 19:47:26 -0400 Subject: [PATCH 29/42] fixed errors that formatter made --- main_2024.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/main_2024.py b/main_2024.py index 6756232c..2aac7406 100644 --- a/main_2024.py +++ b/main_2024.py @@ -285,7 +285,6 @@ def main() -> int: ), input_queues=[data_merge_to_geolocation_queue], output_queues=[geolocation_to_cluster_estimation_queue], - output_queues=[geolocation_to_cluster_estimation_queue], controller=controller, local_logger=main_logger, ) @@ -312,22 +311,6 @@ def main() -> int: # Get Pylance to stop complaining assert cluster_estimation_worker_properties is not None - result, cluster_estimation_worker_properties = worker_manager.WorkerProperties.create( - count=1, - target=cluster_estimation_worker.cluster_estimation_worker, - work_arguments=(MIN_ACTIVATION_THRESHOLD, MIN_NEW_POINTS_TO_RUN, RANDOM_STATE), - input_queues=[geolocation_to_cluster_estimation_queue], - output_queues=[cluster_estimation_to_main_queue], - controller=controller, - local_logger=main_logger, - ) - if not result: - main_logger.error("Failed to create arguments for Video Input", True) - return -1 - - # Get Pylance to stop complaining - assert cluster_estimation_worker_properties is not None - # Create managers worker_managers = [] @@ -478,6 +461,7 @@ def main() -> int: flight_interface_decision_queue.fill_and_drain_queue() geolocation_to_cluster_estimation_queue.fill_and_drain_queue() flight_interface_decision_queue.fill_and_drain_queue() + cluster_estimation_to_main_queue.fill_and_drain_queue() for manager in worker_managers: manager.join_workers() From 4f0968abb38f7554d23dcbd1302200a0da238266 Mon Sep 17 00:00:00 2001 From: cyuber Date: Fri, 4 Oct 2024 19:51:42 -0400 Subject: [PATCH 30/42] reformated test_decisions.py --- tests/unit/test_decision.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_decision.py b/tests/unit/test_decision.py index e073d6ee..0c2d8da3 100644 --- a/tests/unit/test_decision.py +++ b/tests/unit/test_decision.py @@ -41,7 +41,9 @@ def best_pad_within_tolerance() -> object_in_world.ObjectInWorld: # type: ignor location_x = BEST_PAD_LOCATION_X location_y = BEST_PAD_LOCATION_Y spherical_variance = 1.0 - result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance, 0) + result, pad = object_in_world.ObjectInWorld.create( + location_x, location_y, spherical_variance, 0 + ) assert result assert pad is not None @@ -56,7 +58,9 @@ def best_pad_outside_tolerance() -> object_in_world.ObjectInWorld: # type: igno location_x = 100.0 location_y = 200.0 spherical_variance = 5.0 # variance outside tolerance - result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance, 0) + result, pad = object_in_world.ObjectInWorld.create( + location_x, location_y, spherical_variance, 0 + ) assert result assert pad is not None From 4df05c8637514e614e57cbffd462c8f80047e4db Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Wed, 9 Oct 2024 12:21:06 -0400 Subject: [PATCH 31/42] redo of integrating cluster estimation worker into main --- config.yaml | 5 +++++ main_2024.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/config.yaml b/config.yaml index b0dd9811..62534d32 100644 --- a/config.yaml +++ b/config.yaml @@ -34,3 +34,8 @@ geolocation: camera_orientation_yaw: 0.0 camera_orientation_pitch: -1.57079632679 camera_orientation_roll: 0.0 + +cluster_merge: + min_activation_threshold: 0 + min_new_points_to_run: 0 + random_state: 0 \ No newline at end of file diff --git a/main_2024.py b/main_2024.py index 66ad913d..fe4d3278 100644 --- a/main_2024.py +++ b/main_2024.py @@ -19,6 +19,7 @@ from modules.data_merge import data_merge_worker from modules.geolocation import geolocation_worker from modules.geolocation import camera_properties +from modules.cluster_estimation import cluster_estimation_worker from modules.common.logger.modules import logger from modules.common.logger.modules import logger_setup_main from modules.common.logger.read_yaml.modules import read_yaml @@ -85,8 +86,8 @@ def main() -> int: VIDEO_INPUT_SAVE_PREFIX = str(pathlib.Path(logging_path, VIDEO_INPUT_SAVE_NAME_PREFIX)) DETECT_TARGET_WORKER_COUNT = config["detect_target"]["worker_count"] - detect_target_option_int = config["detect_target"]["option"] - DETECT_TARGET_OPTION = detect_target_factory.DetectTargetOption(detect_target_option_int) + DETECT_TARGET_OPTION_INT = config["detect_target"]["option"] + DETECT_TARGET_OPTION = detect_target_factory.DetectTargetOption(DETECT_TARGET_OPTION_INT) DETECT_TARGET_DEVICE = "cpu" if args.cpu else config["detect_target"]["device"] DETECT_TARGET_MODEL_PATH = config["detect_target"]["model_path"] DETECT_TARGET_OVERRIDE_FULL_PRECISION = args.full @@ -111,6 +112,10 @@ def main() -> int: GEOLOCATION_CAMERA_ORIENTATION_YAW = config["geolocation"]["camera_orientation_yaw"] GEOLOCATION_CAMERA_ORIENTATION_PITCH = config["geolocation"]["camera_orientation_pitch"] GEOLOCATION_CAMERA_ORIENTATION_ROLL = config["geolocation"]["camera_orientation_roll"] + + MIN_ACTIVATION_THRESHOLD = config["cluster_merge"]["min_activation_threshold"] + MIN_NEW_POINTS_TO_RUN = config["cluster_merge"]["min_new_points_to_run"] + RANDOM_STATE = config["cluster_merge"]["random_state"] # pylint: enable=invalid-name except KeyError as exception: main_logger.error(f"Config key(s) not found: {exception}", True) @@ -139,7 +144,7 @@ def main() -> int: mp_manager, QUEUE_MAX_SIZE, ) - geolocation_to_main_queue = queue_proxy_wrapper.QueueProxyWrapper( + geolocation_to_cluster_estimation_queue = queue_proxy_wrapper.QueueProxyWrapper( mp_manager, QUEUE_MAX_SIZE, ) @@ -147,6 +152,10 @@ def main() -> int: mp_manager, QUEUE_MAX_SIZE, ) + cluster_estimation_to_main_queue = queue_proxy_wrapper.QueueProxyWrapper( + mp_manager, + QUEUE_MAX_SIZE, + ) result, camera_intrinsics = camera_properties.CameraIntrinsics.create( GEOLOCATION_RESOLUTION_X, @@ -266,7 +275,7 @@ def main() -> int: camera_extrinsics, ), input_queues=[data_merge_to_geolocation_queue], - output_queues=[geolocation_to_main_queue], + output_queues=[geolocation_to_cluster_estimation_queue], controller=controller, local_logger=main_logger, ) @@ -277,6 +286,22 @@ def main() -> int: # Get Pylance to stop complaining assert geolocation_worker_properties is not None + result, cluster_estimation_worker_properties = worker_manager.WorkerProperties.create( + count=1, + target=cluster_estimation_worker.cluster_estimation_worker, + work_arguments=(MIN_ACTIVATION_THRESHOLD, MIN_NEW_POINTS_TO_RUN, RANDOM_STATE), + input_queues=[geolocation_to_cluster_estimation_queue], + output_queues=[cluster_estimation_to_main_queue], + controller=controller, + local_logger=main_logger, + ) + if not result: + main_logger.error("Failed to create arguments for Video Input", True) + return -1 + + # Get Pylance to stop complaining + assert cluster_estimation_worker_properties is not None + # Create managers worker_managers = [] @@ -345,6 +370,19 @@ def main() -> int: worker_managers.append(geolocation_manager) + result, cluster_estimation_manager = worker_manager.WorkerManager.create( + worker_properties=cluster_estimation_worker_properties, + local_logger=main_logger, + ) + if not result: + main_logger.error("Failed to create manager for Flight Interface", True) + return -1 + + # Get Pylance to stop complaining + assert cluster_estimation_manager is not None + + worker_managers.append(cluster_estimation_manager) + # Run for manager in worker_managers: manager.start_workers() @@ -357,7 +395,7 @@ def main() -> int: return -1 try: - geolocation_data = geolocation_to_main_queue.queue.get_nowait() + geolocation_data = geolocation_to_cluster_estimation_queue.queue.get_nowait() except queue.Empty: geolocation_data = None @@ -374,7 +412,16 @@ def main() -> int: main_logger.debug( "geolocation confidence: " + str(detection_world.confidence), True ) - + try: + cluster_estimations = cluster_estimation_to_main_queue.queue.get_nowait() + except queue.Empty: + cluster_estimations = None + if cluster_estimations is not None: + for cluster in cluster_estimations: + main_logger.debug("Cluser in world: True") + main_logger.debug("Cluster location x: " + str(cluster.location_x)) + main_logger.debug("Cluster location y: " + str(cluster.location_y)) + main_logger.debug("Cluster spherical variance: " + str(cluster.spherical_variance)) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True) break @@ -386,8 +433,9 @@ def main() -> int: detect_target_to_data_merge_queue.fill_and_drain_queue() flight_interface_to_data_merge_queue.fill_and_drain_queue() data_merge_to_geolocation_queue.fill_and_drain_queue() - geolocation_to_main_queue.fill_and_drain_queue() + geolocation_to_cluster_estimation_queue.fill_and_drain_queue() flight_interface_decision_queue.fill_and_drain_queue() + cluster_estimation_to_main_queue.fill_and_drain_queue() for manager in worker_managers: manager.join_workers() From 9ec46f24a9c33987a58db1a60ae4a775a1fd2fcc Mon Sep 17 00:00:00 2001 From: Cyuber Date: Fri, 11 Oct 2024 19:06:27 -0400 Subject: [PATCH 32/42] implemented changes from review --- config.yaml | 4 ++-- main_2024.py | 37 +++++++++---------------------------- modules/object_in_world.py | 6 ++++++ 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/config.yaml b/config.yaml index 62534d32..de8fe916 100644 --- a/config.yaml +++ b/config.yaml @@ -35,7 +35,7 @@ geolocation: camera_orientation_pitch: -1.57079632679 camera_orientation_roll: 0.0 -cluster_merge: +cluster_estimation: min_activation_threshold: 0 min_new_points_to_run: 0 - random_state: 0 \ No newline at end of file + random_state: 0 diff --git a/main_2024.py b/main_2024.py index fe4d3278..c18bd0c0 100644 --- a/main_2024.py +++ b/main_2024.py @@ -296,7 +296,7 @@ def main() -> int: local_logger=main_logger, ) if not result: - main_logger.error("Failed to create arguments for Video Input", True) + main_logger.error("Failed to create arguments for Cluster Estimation", True) return -1 # Get Pylance to stop complaining @@ -375,7 +375,7 @@ def main() -> int: local_logger=main_logger, ) if not result: - main_logger.error("Failed to create manager for Flight Interface", True) + main_logger.error("Failed to create manager for Cluster Estimation", True) return -1 # Get Pylance to stop complaining @@ -395,33 +395,14 @@ def main() -> int: return -1 try: - geolocation_data = geolocation_to_cluster_estimation_queue.queue.get_nowait() - except queue.Empty: - geolocation_data = None - - if geolocation_data is not None: - for detection_world in geolocation_data: - main_logger.debug("Detection in world:", True) - main_logger.debug( - "geolocation vertices: " + str(detection_world.vertices.tolist()), True - ) - main_logger.debug( - "geolocation centre: " + str(detection_world.centre.tolist()), True - ) - main_logger.debug("geolocation label: " + str(detection_world.label), True) - main_logger.debug( - "geolocation confidence: " + str(detection_world.confidence), True - ) - try: - cluster_estimations = cluster_estimation_to_main_queue.queue.get_nowait() + cluster_estimation_data = cluster_estimation_to_main_queue.queue.get_nowait() except queue.Empty: - cluster_estimations = None - if cluster_estimations is not None: - for cluster in cluster_estimations: - main_logger.debug("Cluser in world: True") - main_logger.debug("Cluster location x: " + str(cluster.location_x)) - main_logger.debug("Cluster location y: " + str(cluster.location_y)) - main_logger.debug("Cluster spherical variance: " + str(cluster.spherical_variance)) + cluster_estimation_data = None + + if cluster_estimation_data is not None: + for object_in_world in cluster_estimation_data: + main_logger.debug("Cluster in world: ", True) + main_logger.debug(object_in_world.__str__) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True) break diff --git a/modules/object_in_world.py b/modules/object_in_world.py index 1ce9f65e..31f7ef01 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -38,3 +38,9 @@ def __init__( self.location_x = location_x self.location_y = location_y self.spherical_variance = spherical_variance + + def __str__(self) -> str: + """ + To string. + """ + return f"{self.__class__}, location x: {self.location_x}, location y: {self.location_y}, spherical variance: {self.spherical_variance}, label: {self.label}" From fb2897285348d796c109afb5ba85028c8d6d4a7e Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Thu, 31 Oct 2024 00:27:14 -0400 Subject: [PATCH 33/42] fixed formatting issue --- main_2024.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_2024.py b/main_2024.py index c18bd0c0..2f6cacd0 100644 --- a/main_2024.py +++ b/main_2024.py @@ -398,7 +398,7 @@ def main() -> int: cluster_estimation_data = cluster_estimation_to_main_queue.queue.get_nowait() except queue.Empty: cluster_estimation_data = None - + if cluster_estimation_data is not None: for object_in_world in cluster_estimation_data: main_logger.debug("Cluster in world: ", True) From 62e5b7a01c2055315f2c95cb7844254b6e7e1dff Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Fri, 1 Nov 2024 15:15:34 -0400 Subject: [PATCH 34/42] implemented reviewed changes --- main_2024.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main_2024.py b/main_2024.py index 2f6cacd0..4349ea9e 100644 --- a/main_2024.py +++ b/main_2024.py @@ -113,9 +113,9 @@ def main() -> int: GEOLOCATION_CAMERA_ORIENTATION_PITCH = config["geolocation"]["camera_orientation_pitch"] GEOLOCATION_CAMERA_ORIENTATION_ROLL = config["geolocation"]["camera_orientation_roll"] - MIN_ACTIVATION_THRESHOLD = config["cluster_merge"]["min_activation_threshold"] - MIN_NEW_POINTS_TO_RUN = config["cluster_merge"]["min_new_points_to_run"] - RANDOM_STATE = config["cluster_merge"]["random_state"] + MIN_ACTIVATION_THRESHOLD = config["cluster_estimation"]["min_activation_threshold"] + MIN_NEW_POINTS_TO_RUN = config["cluster_estimation"]["min_new_points_to_run"] + RANDOM_STATE = config["cluster_estimation"]["random_state"] # pylint: enable=invalid-name except KeyError as exception: main_logger.error(f"Config key(s) not found: {exception}", True) @@ -401,8 +401,8 @@ def main() -> int: if cluster_estimation_data is not None: for object_in_world in cluster_estimation_data: - main_logger.debug("Cluster in world: ", True) - main_logger.debug(object_in_world.__str__) + main_logger.debug("Cluster in world: ", (object_in_world is not None)) + main_logger.debug(str(object_in_world)) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True) break From d6183f0e59fcc1b2c7e6a9bba931c2d6a49925ef Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Fri, 1 Nov 2024 20:25:00 -0400 Subject: [PATCH 35/42] fixed review changes --- config.yaml | 4 ++-- main_2024.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config.yaml b/config.yaml index de8fe916..44bdd6df 100644 --- a/config.yaml +++ b/config.yaml @@ -36,6 +36,6 @@ geolocation: camera_orientation_roll: 0.0 cluster_estimation: - min_activation_threshold: 0 - min_new_points_to_run: 0 + min_activation_threshold: 25 + min_new_points_to_run: 5 random_state: 0 diff --git a/main_2024.py b/main_2024.py index 4349ea9e..0cc5e2e1 100644 --- a/main_2024.py +++ b/main_2024.py @@ -401,7 +401,7 @@ def main() -> int: if cluster_estimation_data is not None: for object_in_world in cluster_estimation_data: - main_logger.debug("Cluster in world: ", (object_in_world is not None)) + main_logger.debug("Cluster in world: ", True) main_logger.debug(str(object_in_world)) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True) From 617ae90cc0ac57f957eb7a53a4414632d52e0bdb Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Wed, 9 Oct 2024 12:21:06 -0400 Subject: [PATCH 36/42] redo of integrating cluster estimation worker into main --- modules/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/common b/modules/common index 5c3894e0..a32385ee 160000 --- a/modules/common +++ b/modules/common @@ -1 +1 @@ -Subproject commit 5c3894e043c5129a1c0579c6f6acae2cc7a52a18 +Subproject commit a32385eefab7d6a5468f5b8f2e708860a5f085d6 From 05fdf6309b973c2cbbcf46e2dad7b63c24d14588 Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Wed, 9 Oct 2024 12:21:06 -0400 Subject: [PATCH 37/42] redo of integrating cluster estimation worker into main --- config.yaml | 5 +++++ main_2024.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/config.yaml b/config.yaml index b0dd9811..62534d32 100644 --- a/config.yaml +++ b/config.yaml @@ -34,3 +34,8 @@ geolocation: camera_orientation_yaw: 0.0 camera_orientation_pitch: -1.57079632679 camera_orientation_roll: 0.0 + +cluster_merge: + min_activation_threshold: 0 + min_new_points_to_run: 0 + random_state: 0 \ No newline at end of file diff --git a/main_2024.py b/main_2024.py index f6297226..4ffc4b9a 100644 --- a/main_2024.py +++ b/main_2024.py @@ -19,6 +19,7 @@ from modules.data_merge import data_merge_worker from modules.geolocation import geolocation_worker from modules.geolocation import camera_properties +from modules.cluster_estimation import cluster_estimation_worker from modules.common.modules.logger import logger from modules.common.modules.logger import logger_main_setup from modules.common.modules.read_yaml import read_yaml @@ -85,8 +86,8 @@ def main() -> int: VIDEO_INPUT_SAVE_PREFIX = str(pathlib.Path(logging_path, VIDEO_INPUT_SAVE_NAME_PREFIX)) DETECT_TARGET_WORKER_COUNT = config["detect_target"]["worker_count"] - detect_target_option_int = config["detect_target"]["option"] - DETECT_TARGET_OPTION = detect_target_factory.DetectTargetOption(detect_target_option_int) + DETECT_TARGET_OPTION_INT = config["detect_target"]["option"] + DETECT_TARGET_OPTION = detect_target_factory.DetectTargetOption(DETECT_TARGET_OPTION_INT) DETECT_TARGET_DEVICE = "cpu" if args.cpu else config["detect_target"]["device"] DETECT_TARGET_MODEL_PATH = config["detect_target"]["model_path"] DETECT_TARGET_OVERRIDE_FULL_PRECISION = args.full @@ -111,6 +112,10 @@ def main() -> int: GEOLOCATION_CAMERA_ORIENTATION_YAW = config["geolocation"]["camera_orientation_yaw"] GEOLOCATION_CAMERA_ORIENTATION_PITCH = config["geolocation"]["camera_orientation_pitch"] GEOLOCATION_CAMERA_ORIENTATION_ROLL = config["geolocation"]["camera_orientation_roll"] + + MIN_ACTIVATION_THRESHOLD = config["cluster_merge"]["min_activation_threshold"] + MIN_NEW_POINTS_TO_RUN = config["cluster_merge"]["min_new_points_to_run"] + RANDOM_STATE = config["cluster_merge"]["random_state"] # pylint: enable=invalid-name except KeyError as exception: main_logger.error(f"Config key(s) not found: {exception}", True) @@ -139,7 +144,7 @@ def main() -> int: mp_manager, QUEUE_MAX_SIZE, ) - geolocation_to_main_queue = queue_proxy_wrapper.QueueProxyWrapper( + geolocation_to_cluster_estimation_queue = queue_proxy_wrapper.QueueProxyWrapper( mp_manager, QUEUE_MAX_SIZE, ) @@ -147,6 +152,10 @@ def main() -> int: mp_manager, QUEUE_MAX_SIZE, ) + cluster_estimation_to_main_queue = queue_proxy_wrapper.QueueProxyWrapper( + mp_manager, + QUEUE_MAX_SIZE, + ) result, camera_intrinsics = camera_properties.CameraIntrinsics.create( GEOLOCATION_RESOLUTION_X, @@ -266,7 +275,7 @@ def main() -> int: camera_extrinsics, ), input_queues=[data_merge_to_geolocation_queue], - output_queues=[geolocation_to_main_queue], + output_queues=[geolocation_to_cluster_estimation_queue], controller=controller, local_logger=main_logger, ) @@ -277,6 +286,22 @@ def main() -> int: # Get Pylance to stop complaining assert geolocation_worker_properties is not None + result, cluster_estimation_worker_properties = worker_manager.WorkerProperties.create( + count=1, + target=cluster_estimation_worker.cluster_estimation_worker, + work_arguments=(MIN_ACTIVATION_THRESHOLD, MIN_NEW_POINTS_TO_RUN, RANDOM_STATE), + input_queues=[geolocation_to_cluster_estimation_queue], + output_queues=[cluster_estimation_to_main_queue], + controller=controller, + local_logger=main_logger, + ) + if not result: + main_logger.error("Failed to create arguments for Video Input", True) + return -1 + + # Get Pylance to stop complaining + assert cluster_estimation_worker_properties is not None + # Create managers worker_managers = [] @@ -345,6 +370,19 @@ def main() -> int: worker_managers.append(geolocation_manager) + result, cluster_estimation_manager = worker_manager.WorkerManager.create( + worker_properties=cluster_estimation_worker_properties, + local_logger=main_logger, + ) + if not result: + main_logger.error("Failed to create manager for Flight Interface", True) + return -1 + + # Get Pylance to stop complaining + assert cluster_estimation_manager is not None + + worker_managers.append(cluster_estimation_manager) + # Run for manager in worker_managers: manager.start_workers() @@ -357,7 +395,7 @@ def main() -> int: return -1 try: - geolocation_data = geolocation_to_main_queue.queue.get_nowait() + geolocation_data = geolocation_to_cluster_estimation_queue.queue.get_nowait() except queue.Empty: geolocation_data = None @@ -374,7 +412,16 @@ def main() -> int: main_logger.debug( "geolocation confidence: " + str(detection_world.confidence), True ) - + try: + cluster_estimations = cluster_estimation_to_main_queue.queue.get_nowait() + except queue.Empty: + cluster_estimations = None + if cluster_estimations is not None: + for cluster in cluster_estimations: + main_logger.debug("Cluser in world: True") + main_logger.debug("Cluster location x: " + str(cluster.location_x)) + main_logger.debug("Cluster location y: " + str(cluster.location_y)) + main_logger.debug("Cluster spherical variance: " + str(cluster.spherical_variance)) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True) break @@ -386,8 +433,9 @@ def main() -> int: detect_target_to_data_merge_queue.fill_and_drain_queue() flight_interface_to_data_merge_queue.fill_and_drain_queue() data_merge_to_geolocation_queue.fill_and_drain_queue() - geolocation_to_main_queue.fill_and_drain_queue() + geolocation_to_cluster_estimation_queue.fill_and_drain_queue() flight_interface_decision_queue.fill_and_drain_queue() + cluster_estimation_to_main_queue.fill_and_drain_queue() for manager in worker_managers: manager.join_workers() From d86f7cec4ac3e9831352fe718b8e69286ec71e22 Mon Sep 17 00:00:00 2001 From: Cyuber Date: Fri, 11 Oct 2024 19:06:27 -0400 Subject: [PATCH 38/42] implemented changes from review --- config.yaml | 4 ++-- main_2024.py | 37 +++++++++---------------------------- modules/object_in_world.py | 6 ++++++ 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/config.yaml b/config.yaml index 62534d32..de8fe916 100644 --- a/config.yaml +++ b/config.yaml @@ -35,7 +35,7 @@ geolocation: camera_orientation_pitch: -1.57079632679 camera_orientation_roll: 0.0 -cluster_merge: +cluster_estimation: min_activation_threshold: 0 min_new_points_to_run: 0 - random_state: 0 \ No newline at end of file + random_state: 0 diff --git a/main_2024.py b/main_2024.py index 4ffc4b9a..6768d361 100644 --- a/main_2024.py +++ b/main_2024.py @@ -296,7 +296,7 @@ def main() -> int: local_logger=main_logger, ) if not result: - main_logger.error("Failed to create arguments for Video Input", True) + main_logger.error("Failed to create arguments for Cluster Estimation", True) return -1 # Get Pylance to stop complaining @@ -375,7 +375,7 @@ def main() -> int: local_logger=main_logger, ) if not result: - main_logger.error("Failed to create manager for Flight Interface", True) + main_logger.error("Failed to create manager for Cluster Estimation", True) return -1 # Get Pylance to stop complaining @@ -395,33 +395,14 @@ def main() -> int: return -1 try: - geolocation_data = geolocation_to_cluster_estimation_queue.queue.get_nowait() - except queue.Empty: - geolocation_data = None - - if geolocation_data is not None: - for detection_world in geolocation_data: - main_logger.debug("Detection in world:", True) - main_logger.debug( - "geolocation vertices: " + str(detection_world.vertices.tolist()), True - ) - main_logger.debug( - "geolocation centre: " + str(detection_world.centre.tolist()), True - ) - main_logger.debug("geolocation label: " + str(detection_world.label), True) - main_logger.debug( - "geolocation confidence: " + str(detection_world.confidence), True - ) - try: - cluster_estimations = cluster_estimation_to_main_queue.queue.get_nowait() + cluster_estimation_data = cluster_estimation_to_main_queue.queue.get_nowait() except queue.Empty: - cluster_estimations = None - if cluster_estimations is not None: - for cluster in cluster_estimations: - main_logger.debug("Cluser in world: True") - main_logger.debug("Cluster location x: " + str(cluster.location_x)) - main_logger.debug("Cluster location y: " + str(cluster.location_y)) - main_logger.debug("Cluster spherical variance: " + str(cluster.spherical_variance)) + cluster_estimation_data = None + + if cluster_estimation_data is not None: + for object_in_world in cluster_estimation_data: + main_logger.debug("Cluster in world: ", True) + main_logger.debug(object_in_world.__str__) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True) break diff --git a/modules/object_in_world.py b/modules/object_in_world.py index 1ce9f65e..31f7ef01 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -38,3 +38,9 @@ def __init__( self.location_x = location_x self.location_y = location_y self.spherical_variance = spherical_variance + + def __str__(self) -> str: + """ + To string. + """ + return f"{self.__class__}, location x: {self.location_x}, location y: {self.location_y}, spherical variance: {self.spherical_variance}, label: {self.label}" From a203f426fa737364acba0e283d55118cd87e164e Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Thu, 31 Oct 2024 00:27:14 -0400 Subject: [PATCH 39/42] fixed formatting issue --- main_2024.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_2024.py b/main_2024.py index 6768d361..100957ee 100644 --- a/main_2024.py +++ b/main_2024.py @@ -398,7 +398,7 @@ def main() -> int: cluster_estimation_data = cluster_estimation_to_main_queue.queue.get_nowait() except queue.Empty: cluster_estimation_data = None - + if cluster_estimation_data is not None: for object_in_world in cluster_estimation_data: main_logger.debug("Cluster in world: ", True) From 4e0602fc42e08db7f8c069c7cf5334d2df647267 Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Fri, 1 Nov 2024 15:15:34 -0400 Subject: [PATCH 40/42] implemented reviewed changes --- main_2024.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main_2024.py b/main_2024.py index 100957ee..43dcbcce 100644 --- a/main_2024.py +++ b/main_2024.py @@ -113,9 +113,9 @@ def main() -> int: GEOLOCATION_CAMERA_ORIENTATION_PITCH = config["geolocation"]["camera_orientation_pitch"] GEOLOCATION_CAMERA_ORIENTATION_ROLL = config["geolocation"]["camera_orientation_roll"] - MIN_ACTIVATION_THRESHOLD = config["cluster_merge"]["min_activation_threshold"] - MIN_NEW_POINTS_TO_RUN = config["cluster_merge"]["min_new_points_to_run"] - RANDOM_STATE = config["cluster_merge"]["random_state"] + MIN_ACTIVATION_THRESHOLD = config["cluster_estimation"]["min_activation_threshold"] + MIN_NEW_POINTS_TO_RUN = config["cluster_estimation"]["min_new_points_to_run"] + RANDOM_STATE = config["cluster_estimation"]["random_state"] # pylint: enable=invalid-name except KeyError as exception: main_logger.error(f"Config key(s) not found: {exception}", True) @@ -401,8 +401,8 @@ def main() -> int: if cluster_estimation_data is not None: for object_in_world in cluster_estimation_data: - main_logger.debug("Cluster in world: ", True) - main_logger.debug(object_in_world.__str__) + main_logger.debug("Cluster in world: ", (object_in_world is not None)) + main_logger.debug(str(object_in_world)) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True) break From c84fe868edd5c9b7aa5fde328af555550431d32a Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Fri, 1 Nov 2024 20:25:00 -0400 Subject: [PATCH 41/42] fixed review changes --- config.yaml | 4 ++-- main_2024.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config.yaml b/config.yaml index de8fe916..44bdd6df 100644 --- a/config.yaml +++ b/config.yaml @@ -36,6 +36,6 @@ geolocation: camera_orientation_roll: 0.0 cluster_estimation: - min_activation_threshold: 0 - min_new_points_to_run: 0 + min_activation_threshold: 25 + min_new_points_to_run: 5 random_state: 0 diff --git a/main_2024.py b/main_2024.py index 43dcbcce..9af33b30 100644 --- a/main_2024.py +++ b/main_2024.py @@ -401,7 +401,7 @@ def main() -> int: if cluster_estimation_data is not None: for object_in_world in cluster_estimation_data: - main_logger.debug("Cluster in world: ", (object_in_world is not None)) + main_logger.debug("Cluster in world: ", True) main_logger.debug(str(object_in_world)) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True) From f0aaaa96aca086970d5198aa13c21ea9b6d0eafe Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Thu, 7 Nov 2024 05:32:18 -0500 Subject: [PATCH 42/42] rebased --- modules/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/common b/modules/common index a32385ee..5c3894e0 160000 --- a/modules/common +++ b/modules/common @@ -1 +1 @@ -Subproject commit a32385eefab7d6a5468f5b8f2e708860a5f085d6 +Subproject commit 5c3894e043c5129a1c0579c6f6acae2cc7a52a18