feat(reflector_pair): split multi-core bright runs and allow an empty gap between strips
Narrow strips (3 cm wide, 9 cm between centres) leave a 6 cm wall gap that bloom can fill, so one bright run may hold both strip cores and the middle wall group may have no dark rays at all. - Split a bright run with several cores at the darkest ray between them (middle of an equal-minimum region); each core becomes its own candidate. Ties were rejected before. - Compare the middle wall group only when it has at least wall_min_points_each_side dark rays; the outer groups are still required. - Document wall_max_gap / wall_merge_distance for the masked narrow gap. - Tests: 3/9 cm strips at 0.5-1.5 m, a gap bridged by bloom, an occluder in the masked gap, a third strip making the result ambiguous.
This commit is contained in:
@@ -367,7 +367,8 @@ TEST(ReflectorPairBloom, CoreTiesAndInseparableOrHighUncertaintyReject)
|
||||
const auto detection = detect(test_profile,world,wall_scan_sim::geometry(kFrontStep));
|
||||
EXPECT_FALSE(detection.valid);
|
||||
EXPECT_EQ(detection.reason, "edge_uncertainty");
|
||||
// Hai core dài bằng nhau trong một run: không chọn tùy ý.
|
||||
// Một dải có vết lõm giữa: run bị chia thành hai lõi hẹp. Không được nhận thành một dải đủ rộng,
|
||||
// cũng không được ghép hai nửa với nhau hay với dải kia.
|
||||
test_profile = profile();
|
||||
const auto geometry = wall_scan_sim::geometry(kFrontStep);
|
||||
auto scan = wall_scan_sim::rayCast(world,geometry);
|
||||
@@ -398,9 +399,10 @@ TEST(ReflectorPairBloom, CoreTiesAndInseparableOrHighUncertaintyReject)
|
||||
ReflectorPairMatcher matcher;
|
||||
std::string error;
|
||||
ASSERT_TRUE(matcher.configure(test_profile,error));
|
||||
const auto tied = matcher.match(geometry,scan.ranges,scan.intensities,{},{});
|
||||
EXPECT_FALSE(tied.valid);
|
||||
EXPECT_EQ(tied.reason, "insufficient_candidates_or_core");
|
||||
const auto split = matcher.match(geometry,scan.ranges,scan.intensities,{},{});
|
||||
EXPECT_FALSE(split.valid);
|
||||
EXPECT_EQ(split.valid_pairs, 0u);
|
||||
EXPECT_NE(split.reason, "ambiguous");
|
||||
}
|
||||
|
||||
TEST(ReflectorPairPairing, WrongWidthSpacingAndOcclusionReject)
|
||||
@@ -679,6 +681,162 @@ TEST(ReflectorPairWindow, WallEndBeforeEnoughSupportRejects)
|
||||
EXPECT_FALSE(result.valid);
|
||||
EXPECT_EQ(result.reason, "wall_support");
|
||||
}
|
||||
|
||||
// Hình học người dùng đang thử (12/11/2026): dải rộng ~3 cm, tâm cách 9 cm, khe tường giữa 6 cm.
|
||||
// Dung sai width/spacing = 2 × cận lượng tử một mép tại đúng cự ly/góc của ca (mỗi mép lệch tối đa
|
||||
// một nửa bước chiếu lên tường, width và spacing cộng hai mép).
|
||||
constexpr double kS300SimStep = 0.0058824;
|
||||
|
||||
ReflectorPairProfile narrowProfile(double edge_bound)
|
||||
{
|
||||
ReflectorPairProfile test_profile = profile();
|
||||
test_profile.tape_width = 0.03;
|
||||
test_profile.tape_spacing = 0.09;
|
||||
test_profile.width_tolerance = std::max(2.0 * edge_bound, 0.002);
|
||||
test_profile.spacing_tolerance = std::max(2.0 * edge_bound, 0.002);
|
||||
test_profile.wall_min_span = 0.30;
|
||||
test_profile.wall_max_gap = 0.08;
|
||||
return test_profile;
|
||||
}
|
||||
|
||||
wall_scan_sim::World narrowWorld(double distance, double angle_degrees)
|
||||
{
|
||||
wall_scan_sim::World world;
|
||||
world.x = distance;
|
||||
world.normal_yaw = kPi + angle_degrees * kPi / 180.0;
|
||||
world.tapes = {{-0.045, 0.03}, {0.045, 0.03}};
|
||||
return world;
|
||||
}
|
||||
|
||||
// Phủ khe giữa hai lõi bằng bloom phẳng (>= tape_min_intensity, < tape_core_intensity): hai dải
|
||||
// thành MỘT bright run. Trả về chỉ số tia đầu và cuối của khe đã phủ.
|
||||
std::array<std::size_t, 2> bridgeGapWithBloom(wall_scan_sim::Scan& scan, float core, float bloom)
|
||||
{
|
||||
std::size_t first_core_end = 0;
|
||||
std::size_t second_core_start = 0;
|
||||
bool in_first = false;
|
||||
bool first_done = false;
|
||||
for (std::size_t index = 0; index < scan.intensities.size(); ++index)
|
||||
{
|
||||
const bool is_core = scan.intensities[index] >= core;
|
||||
if (!first_done)
|
||||
{
|
||||
if (is_core)
|
||||
{
|
||||
in_first = true;
|
||||
first_core_end = index;
|
||||
}
|
||||
else if (in_first)
|
||||
{
|
||||
first_done = true;
|
||||
}
|
||||
}
|
||||
else if (is_core)
|
||||
{
|
||||
second_core_start = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (std::size_t index = first_core_end + 1; index < second_core_start; ++index)
|
||||
{
|
||||
scan.intensities[index] = bloom;
|
||||
}
|
||||
return {{first_core_end + 1, second_core_start - 1}};
|
||||
}
|
||||
|
||||
TEST(ReflectorPairNarrow, ThreeByNineCentimetreAcrossRangesAnglesAndPhases)
|
||||
{
|
||||
struct Case
|
||||
{
|
||||
double step;
|
||||
double distance;
|
||||
double angle_degrees;
|
||||
};
|
||||
// S300 sim ở 1.5 m nhìn xiên 30° chỉ còn ~2.9 tia trên dải (< tape_min_points 3), nên không thử.
|
||||
const std::vector<Case> cases = {
|
||||
{kFrontStep, 0.5, 0.0}, {kFrontStep, 0.5, 30.0}, {kFrontStep, 1.0, 0.0},
|
||||
{kFrontStep, 1.0, 30.0}, {kFrontStep, 1.5, 0.0}, {kFrontStep, 1.5, 30.0},
|
||||
{kS300SimStep, 0.5, 0.0}, {kS300SimStep, 0.5, 30.0}, {kS300SimStep, 1.0, 0.0},
|
||||
{kS300SimStep, 1.0, 30.0}, {kS300SimStep, 1.5, 0.0}};
|
||||
for (const Case& test_case : cases)
|
||||
{
|
||||
for (const double phase : {0.0, 0.25, 0.5, 0.75})
|
||||
{
|
||||
const auto world = narrowWorld(test_case.distance, test_case.angle_degrees);
|
||||
const double edge_bound = quantisationBound(world, test_case.step);
|
||||
const auto geometry = wall_scan_sim::geometry(test_case.step, phase * test_case.step);
|
||||
const auto result = detect(narrowProfile(edge_bound), world, geometry);
|
||||
ASSERT_TRUE(result.valid) << test_case.step << ' ' << test_case.distance << ' '
|
||||
<< test_case.angle_degrees << ' ' << phase << ' ' << result.reason;
|
||||
EXPECT_LE(std::hypot(result.marker.x - world.x, result.marker.y - world.y), edge_bound);
|
||||
EXPECT_LT(yawError(result.marker.yaw, world.normal_yaw), 1e-6);
|
||||
EXPECT_LE(std::abs(result.spacing - 0.09), 2.0 * edge_bound);
|
||||
EXPECT_LE(std::abs(result.widths[0] - 0.03), 2.0 * edge_bound);
|
||||
EXPECT_LE(std::abs(result.widths[1] - 0.03), 2.0 * edge_bound);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ReflectorPairNarrow, BloomBridgingTheGapIntoOneRunIsSplitAndDetected)
|
||||
{
|
||||
const auto world = narrowWorld(1.0, 0.0);
|
||||
const auto geometry = wall_scan_sim::geometry(kFrontStep);
|
||||
auto scan = wall_scan_sim::rayCast(world, geometry);
|
||||
const double edge_bound = quantisationBound(world, kFrontStep);
|
||||
auto test_profile = narrowProfile(edge_bound);
|
||||
bridgeGapWithBloom(scan, static_cast<float>(test_profile.tape_core_intensity), 9000.0f);
|
||||
// Khe bị mask kín: support chỉ còn hai phía ngoài, khoảng trống là cả cặp cộng hai skirt.
|
||||
test_profile.tape_bloom_max_angle = 2.0 * kFrontStep;
|
||||
test_profile.wall_max_gap = 0.20;
|
||||
// Mỗi lõi (~7.6 tia) nhận thêm nửa khe (~7.6 tia) bloom: tỉ lệ lõi/run ~0.5.
|
||||
test_profile.tape_plateau_min_fraction = 0.4;
|
||||
ReflectorPairMatcher matcher;
|
||||
std::string error;
|
||||
ASSERT_TRUE(matcher.configure(test_profile, error)) << error;
|
||||
const auto result = matcher.match(geometry, scan.ranges, scan.intensities, {}, {});
|
||||
ASSERT_TRUE(result.valid) << result.reason;
|
||||
EXPECT_EQ(result.candidate_count, 2u);
|
||||
EXPECT_LE(std::hypot(result.marker.x - world.x, result.marker.y - world.y), edge_bound);
|
||||
EXPECT_LE(std::abs(result.spacing - 0.09), 2.0 * edge_bound);
|
||||
}
|
||||
|
||||
TEST(ReflectorPairNarrow, OccluderInsideMaskedGapStillRejects)
|
||||
{
|
||||
const auto world = narrowWorld(1.0, 0.0);
|
||||
const auto geometry = wall_scan_sim::geometry(kFrontStep);
|
||||
auto scan = wall_scan_sim::rayCast(world, geometry);
|
||||
auto test_profile = narrowProfile(quantisationBound(world, kFrontStep));
|
||||
const auto gap = bridgeGapWithBloom(scan, static_cast<float>(test_profile.tape_core_intensity),
|
||||
9000.0f);
|
||||
// Ba tia giữa khe là một vật tối nằm trước tường 5 cm; skirt hai bên mask cả ba tia đó.
|
||||
const std::size_t middle = (gap[0] + gap[1]) / 2;
|
||||
for (std::size_t index = middle - 1; index <= middle + 1; ++index)
|
||||
{
|
||||
scan.intensities[index] = 1000.0f;
|
||||
scan.ranges[index] -= 0.05;
|
||||
}
|
||||
test_profile.tape_bloom_max_angle = 2.0 * kFrontStep;
|
||||
test_profile.wall_max_gap = 0.20;
|
||||
test_profile.tape_plateau_min_fraction = 0.4;
|
||||
ReflectorPairMatcher matcher;
|
||||
std::string error;
|
||||
ASSERT_TRUE(matcher.configure(test_profile, error)) << error;
|
||||
const auto result = matcher.match(geometry, scan.ranges, scan.intensities, {}, {});
|
||||
EXPECT_FALSE(result.valid);
|
||||
EXPECT_EQ(result.reason, "wall_occlusion");
|
||||
}
|
||||
|
||||
TEST(ReflectorPairNarrow, ThirdStripAtNineCentimetresIsAmbiguous)
|
||||
{
|
||||
auto world = narrowWorld(1.0, 0.0);
|
||||
world.tapes = {{-0.09, 0.03}, {0.0, 0.03}, {0.09, 0.03}};
|
||||
const auto result =
|
||||
detect(narrowProfile(quantisationBound(world, kFrontStep)), world,
|
||||
wall_scan_sim::geometry(kFrontStep));
|
||||
EXPECT_FALSE(result.valid);
|
||||
EXPECT_EQ(result.reason, "ambiguous");
|
||||
EXPECT_EQ(result.valid_pairs, 2u);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
||||
Reference in New Issue
Block a user