fix(leg_pattern): rescue a real taped leg's edge-ramp bright run from the bloom-spread gate

This commit is contained in:
2026-10-30 09:43:41 +07:00
parent 347896e252
commit 588ed58b6d
8 changed files with 387 additions and 18 deletions

View File

@@ -868,6 +868,68 @@ TEST(LegProfile, TapeBloomAndRangeBiasRequireTapeAndValidRanges)
EXPECT_TRUE(p.validate(error)) << error;
}
TEST(LegProfile, TapePlateauRequiresValidFractionAndBloom)
{
std::string error;
LegProfile p = reflectiveTrolley();
for (double value : { -0.01, 1.0, std::numeric_limits<double>::quiet_NaN() })
{
p.tape_plateau_min_fraction = value;
EXPECT_FALSE(p.validate(error)) << value;
EXPECT_NE(error.find("tape_plateau_min_fraction"), std::string::npos);
}
p = tciTrolley();
p.tape_plateau_min_fraction = 0.65;
EXPECT_FALSE(p.validate(error));
p = reflectiveTrolley();
p.tape_bloom_max_angle = 0.0;
p.tape_plateau_min_fraction = 0.65;
EXPECT_FALSE(p.validate(error));
p.tape_plateau_min_fraction = 0.0;
EXPECT_TRUE(p.validate(error)) << error;
p = tciTrolley();
EXPECT_TRUE(p.validate(error)) << error;
p = reflectiveTrolley();
p.tape_plateau_min_fraction = 0.65;
EXPECT_TRUE(p.validate(error)) << error;
}
TEST(LegPatternMatcher, PlateauRescuesEdgeRampButRejectsSlopeAndShortPlateau)
{
LegProfile p = reflectiveTrolley();
p.tape_legs = TapeLegs::kAll;
p.tape_plateau_min_fraction = 0.65;
p.leg_width_tolerance = 0.02;
p.shadow_min_angle = 0.0;
robot_line_extraction::ScanGeometry geometry;
geometry.angle_min = -0.1;
geometry.angle_increment = 0.004;
geometry.size = 50;
const auto run = [&](const std::vector<double>& values, std::size_t min_points, double fraction) {
LegProfile profile = p;
profile.tape_min_points = min_points;
profile.tape_plateau_min_fraction = fraction;
leg_scan_sim::Scan scan;
scan.ranges.assign(geometry.size, std::numeric_limits<double>::infinity());
scan.intensities.assign(geometry.size, 0.0f);
for (std::size_t i = 0; i < values.size(); ++i)
{
scan.ranges[10 + i] = values[i];
scan.intensities[10 + i] = 2000.0f;
}
return matchScan(profile, geometry, scan);
};
const LegDetection rescued = run({1.060, 1.035, 1.010, 1.005, 1.000, 1.004, 1.006, 1.008, 1.010, 1.009}, 2, 0.65);
EXPECT_EQ(rescued.leg_candidates, 1u) << rescued.reason;
EXPECT_NE(rescued.reason.find("1 bright core(s) kept by their plateau"), std::string::npos);
const LegDetection sloped = run({1.000, 1.015, 1.030, 1.045, 1.060}, 2, 0.65);
EXPECT_EQ(sloped.leg_candidates, 0u) << sloped.reason;
EXPECT_NE(sloped.reason.find("1 bright core(s) spread"), std::string::npos);
const LegDetection short_plateau = run({1.000, 1.004, 1.030, 1.055}, 3, 0.4);
EXPECT_EQ(short_plateau.leg_candidates, 0u) << short_plateau.reason;
EXPECT_NE(short_plateau.reason.find("1 bright core(s) spread"), std::string::npos);
}
TEST(LegPatternMatcher, MatchBeforeConfigureSaysSo)
{
LegPatternMatcher matcher;