From 3c7b126f1e043a546c2ceba9743b204d44c8b013 Mon Sep 17 00:00:00 2001 From: duongtd Date: Thu, 12 Nov 2026 17:01:54 +0700 Subject: [PATCH] feat(reflector_pair): make tape_core_intensity and tape_plateau_min_fraction optional An unset core threshold defaults to tape_min_intensity and an unset plateau fraction to 1.0, resolved once in ReflectorPairMatcher::configure(). Every deployed profile already set the two thresholds equal (no bloom on the robot lidar), so operators now configure one threshold. Profiles that set both keys match exactly as before. --- README.md | 6 +- .../reflector_pair_profile.h | 8 +- src/reflector_pair_matcher.cpp | 4 + src/reflector_pair_profile.cpp | 6 +- test/reflector_pair_matcher_test.cpp | 96 ++++++++++++++++++- 5 files changed, 111 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0f64692..2749125 100644 --- a/README.md +++ b/README.md @@ -284,8 +284,10 @@ Cổng này không phân biệt được một vật sáng nằm trong giới h các mặt cần phân biệt. `wall_max_gap` phải bao phủ dải cộng cả hai skirt bloom tại tầm xa nhất. Kiểm kích thước, prior và quạt; hai cặp hợp lệ trở lên trả `ambiguous`, vượt giới hạn xử lý trả `capacity_*`. -`tape_core_intensity`, mask bloom và `edge_bias_bound` phải hiệu chuẩn theo cảm biến, vật liệu, góc và -cự ly. Thấy core ổn định không chứng minh đó là mép vật lý, nhất là khi saturation/bloom. Cận mép +`tape_min_intensity` là ngưỡng dải; `tape_core_intensity` tùy chọn, mặc định bằng ngưỡng này, +và `tape_plateau_min_fraction` tùy chọn, mặc định 1.0. Chỉ cần khai hai khóa riêng khi lidar có +bloom nằm giữa hai ngưỡng. Ngưỡng, mask bloom và `edge_bias_bound` phải hiệu chuẩn theo cảm biến, +vật liệu, góc và cự ly. Thấy core ổn định không chứng minh đó là mép vật lý, nhất là khi saturation/bloom. Cận mép trả về chỉ gồm lượng tử góc và bound hiệu chuẩn, chưa bao gồm sai số fit tường, TF hay localization. Không có ground truth tường thật hoặc chứng nhận độ chính xác trong package. Cách dựng và cổng kiểm được mô tả trong [kế hoạch P1](../../../../Test/docs/wall_reflector_detection_action/WALL_REFLECTOR_DETECTION_PLAN.md) diff --git a/include/dock_pattern_detector/reflector_pair_profile.h b/include/dock_pattern_detector/reflector_pair_profile.h index 7a2c84f..7ad7ed3 100644 --- a/include/dock_pattern_detector/reflector_pair_profile.h +++ b/include/dock_pattern_detector/reflector_pair_profile.h @@ -11,7 +11,7 @@ namespace dock_pattern_detector /** * @brief Cấu hình hình học và các cổng kiểm của cặp dải trên một tường phẳng. * - * Giá trị mặc định NaN là bắt buộc đo và khai; không phải cấu hình dùng được trên robot. + * Giá trị NaN mặc định là bắt buộc đo và khai, trừ hai khóa core và plateau tùy chọn bên dưới. * Dung sai lớn giúp chịu nhiễu nhưng có thể nhận nhầm một vật khác. `validate()` kiểm mọi khóa * và ràng buộc chéo trước khi matcher nhận profile. */ @@ -32,7 +32,8 @@ struct ReflectorPairProfile /// [đơn vị driver] Ngưỡng tạo run sáng. Tăng giảm bloom nhưng có thể mất tia tape. double tape_min_intensity = std::numeric_limits::quiet_NaN(); - /// [đơn vị driver] Ngưỡng core trong run. Tăng thu hẹp core, có thể bỏ mất dải ở xa. + /// [đơn vị driver] Ngưỡng core tùy chọn; NaN dùng tape_min_intensity. Chỉ cần ngưỡng riêng + /// khi lidar có bloom nằm giữa hai ngưỡng; tăng ngưỡng core có thể bỏ mất dải ở xa. double tape_core_intensity = std::numeric_limits::quiet_NaN(); /// [tia] Số tia core tối thiểu mỗi dải. Tăng chống nhiễu nhưng thu hẹp tầm hoặc góc phát hiện. @@ -41,7 +42,8 @@ struct ReflectorPairProfile /// [rad] Vùng mask mỗi phía run để tránh bloom vào fit tường. Tăng loại nhiều support hơn. double tape_bloom_max_angle = std::numeric_limits::quiet_NaN(); - /// [-] Tỉ lệ tối thiểu core/run. Tăng loại run loang nhiều hơn nhưng có thể bỏ dải thật. + /// [-] Tỉ lệ tối thiểu core/run tùy chọn; NaN dùng 1.0. Chỉ cần đặt riêng khi lidar có bloom + /// nằm giữa tape_min_intensity và tape_core_intensity; tăng có thể bỏ dải thật. double tape_plateau_min_fraction = std::numeric_limits::quiet_NaN(); /// [m] Cận bias mép đã hiệu chuẩn; tăng làm uncertainty bảo thủ hơn, không tự sửa mép. diff --git a/src/reflector_pair_matcher.cpp b/src/reflector_pair_matcher.cpp index 2f116b1..f73fa62 100644 --- a/src/reflector_pair_matcher.cpp +++ b/src/reflector_pair_matcher.cpp @@ -27,6 +27,10 @@ bool ReflectorPairMatcher::configure(const ReflectorPairProfile& profile, std::s return false; } profile_ = profile; + if (std::isnan(profile_.tape_core_intensity)) + profile_.tape_core_intensity = profile_.tape_min_intensity; + if (std::isnan(profile_.tape_plateau_min_fraction)) + profile_.tape_plateau_min_fraction = 1.0; configured_ = true; return true; } diff --git a/src/reflector_pair_profile.cpp b/src/reflector_pair_profile.cpp index 51a4f0f..febfebd 100644 --- a/src/reflector_pair_profile.cpp +++ b/src/reflector_pair_profile.cpp @@ -55,7 +55,8 @@ bool ReflectorPairProfile::validate(std::string& error) const { return false; } - if (!check("tape_core_intensity", tape_core_intensity, tape_core_intensity >= tape_min_intensity, + if (!std::isnan(tape_core_intensity) && + !check("tape_core_intensity", tape_core_intensity, tape_core_intensity >= tape_min_intensity, "finite and >= tape_min_intensity [driver units]")) { return false; @@ -71,7 +72,8 @@ bool ReflectorPairProfile::validate(std::string& error) const { return false; } - if (!check("tape_plateau_min_fraction", tape_plateau_min_fraction, + if (!std::isnan(tape_plateau_min_fraction) && + !check("tape_plateau_min_fraction", tape_plateau_min_fraction, tape_plateau_min_fraction > 0.0 && tape_plateau_min_fraction <= 1.0, "finite and in (0, 1]")) { diff --git a/test/reflector_pair_matcher_test.cpp b/test/reflector_pair_matcher_test.cpp index eb1adfd..e47d356 100644 --- a/test/reflector_pair_matcher_test.cpp +++ b/test/reflector_pair_matcher_test.cpp @@ -185,9 +185,8 @@ TEST(ReflectorPairProfile, RequiredFieldsRejectUnsetNonfiniteAndOutOfRange) const std::vector> fields = { {"tape_width", &ReflectorPairProfile::tape_width}, {"width_tolerance", &ReflectorPairProfile::width_tolerance}, {"tape_spacing", &ReflectorPairProfile::tape_spacing}, {"spacing_tolerance", &ReflectorPairProfile::spacing_tolerance}, - {"tape_min_intensity", &ReflectorPairProfile::tape_min_intensity}, {"tape_core_intensity", &ReflectorPairProfile::tape_core_intensity}, + {"tape_min_intensity", &ReflectorPairProfile::tape_min_intensity}, {"tape_bloom_max_angle", &ReflectorPairProfile::tape_bloom_max_angle}, - {"tape_plateau_min_fraction", &ReflectorPairProfile::tape_plateau_min_fraction}, {"edge_bias_bound", &ReflectorPairProfile::edge_bias_bound}, {"max_edge_uncertainty", &ReflectorPairProfile::max_edge_uncertainty}, {"wall_min_span", &ReflectorPairProfile::wall_min_span}, {"wall_max_rms", &ReflectorPairProfile::wall_max_rms}, {"wall_max_residual", &ReflectorPairProfile::wall_max_residual}, {"wall_max_gap", &ReflectorPairProfile::wall_max_gap}, @@ -209,6 +208,99 @@ TEST(ReflectorPairProfile, RequiredFieldsRejectUnsetNonfiniteAndOutOfRange) EXPECT_NE(error.find("tape_width"), std::string::npos); } +TEST(ReflectorPairProfile, OptionalThresholdsAcceptNanAndRejectInvalidValues) +{ + const double nan = std::numeric_limits::quiet_NaN(); + const double inf = std::numeric_limits::infinity(); + std::string error; + auto test_profile = profile(); + test_profile.tape_core_intensity = nan; + test_profile.tape_plateau_min_fraction = nan; + EXPECT_TRUE(test_profile.validate(error)) << error; + + for (double bad : {inf, -inf, test_profile.tape_min_intensity - 1.0}) + { + test_profile = profile(); + test_profile.tape_core_intensity = bad; + EXPECT_FALSE(test_profile.validate(error)); + EXPECT_NE(error.find("tape_core_intensity"), std::string::npos) << error; + } + for (double bad : {inf, -inf, -0.1, 0.0, 1.01}) + { + test_profile = profile(); + test_profile.tape_plateau_min_fraction = bad; + EXPECT_FALSE(test_profile.validate(error)); + EXPECT_NE(error.find("tape_plateau_min_fraction"), std::string::npos) << error; + } +} + +TEST(ReflectorPairProfile, UnsetCoreMatchesExplicitMinimum) +{ + auto explicit_profile = profile(); + explicit_profile.tape_core_intensity = explicit_profile.tape_min_intensity; + auto default_profile = explicit_profile; + default_profile.tape_core_intensity = std::numeric_limits::quiet_NaN(); + ReflectorPairMatcher matcher; + std::string error; + ASSERT_TRUE(matcher.configure(default_profile, error)) << error; + EXPECT_EQ(matcher.profile().tape_core_intensity, explicit_profile.tape_min_intensity); + + const wall_scan_sim::World world; + const auto geometry = wall_scan_sim::geometry(kFrontStep); + const auto expected = detect(explicit_profile, world, geometry); + const auto actual = detect(default_profile, world, geometry); + ASSERT_TRUE(expected.valid) << expected.reason; + ASSERT_TRUE(actual.valid) << actual.reason; + EXPECT_EQ(actual.marker.x, expected.marker.x); + EXPECT_EQ(actual.marker.y, expected.marker.y); + EXPECT_EQ(actual.marker.yaw, expected.marker.yaw); + EXPECT_EQ(actual.target.x, expected.target.x); + EXPECT_EQ(actual.target.y, expected.target.y); + EXPECT_EQ(actual.target.yaw, expected.target.yaw); + EXPECT_EQ(actual.widths, expected.widths); + EXPECT_EQ(actual.spacing, expected.spacing); + EXPECT_EQ(actual.wall_rms, expected.wall_rms); + EXPECT_EQ(actual.wall_max_residual, expected.wall_max_residual); + EXPECT_EQ(actual.wall_support, expected.wall_support); + EXPECT_EQ(actual.edge_uncertainty, expected.edge_uncertainty); + EXPECT_EQ(actual.candidate_count, expected.candidate_count); + EXPECT_EQ(actual.valid_pairs, expected.valid_pairs); + EXPECT_EQ(actual.tested_pairs, expected.tested_pairs); + EXPECT_EQ(actual.rejected_runs, expected.rejected_runs); + EXPECT_EQ(actual.reason, expected.reason); +} + +TEST(ReflectorPairProfile, UnsetPlateauUsesOneAndRejectsBloomOutsideCore) +{ + wall_scan_sim::World world; + world.x = 1.2; + world.bloom_left = 1; + world.bloom_right = 2; + auto explicit_profile = profile(); + explicit_profile.tape_bloom_max_angle = 2 * kFrontStep; + explicit_profile.tape_plateau_min_fraction = 1.0; + auto default_profile = explicit_profile; + default_profile.tape_plateau_min_fraction = std::numeric_limits::quiet_NaN(); + ReflectorPairMatcher matcher; + std::string error; + ASSERT_TRUE(matcher.configure(default_profile, error)) << error; + EXPECT_EQ(matcher.profile().tape_plateau_min_fraction, 1.0); + + const auto geometry = wall_scan_sim::geometry(kFrontStep); + const auto expected = detect(explicit_profile, world, geometry); + const auto actual = detect(default_profile, world, geometry); + EXPECT_FALSE(expected.valid); + EXPECT_FALSE(actual.valid); + EXPECT_EQ(actual.reason, expected.reason); + EXPECT_EQ(actual.candidate_count, expected.candidate_count); + EXPECT_EQ(actual.rejected_runs, expected.rejected_runs); + EXPECT_GT(actual.rejected_runs, 0u); + + explicit_profile.tape_plateau_min_fraction = 0.45; + const auto relaxed = detect(explicit_profile, world, geometry); + EXPECT_TRUE(relaxed.valid) << relaxed.reason; +} + TEST(ReflectorPairProfile, ValidationErrorIncludesValueAndRange) { auto test_profile = profile();