fix(leg_profile): ignore tuned tape keys when tape_enabled is false instead of rejecting the profile

This commit is contained in:
2026-10-30 14:21:38 +07:00
parent a6c09f2386
commit bce0d5570e
6 changed files with 127 additions and 12 deletions

View File

@@ -331,6 +331,41 @@ TEST(LegPatternMatcherKit, EveryUntapedOcclusionScanKeepsLegacyResults)
}
}
TEST(LegPatternMatcherKit, TapeOffTunedKeysMatchZeroKeysOnEveryOcclusionScan)
{
const std::vector<RecordedScan> scans = loadScans();
ASSERT_EQ(scans.size(), 6u);
LegProfile zero = kitTrolley(true);
LegProfile tuned = zero;
tuned.tape_bloom_max_angle = 0.10;
tuned.tape_range_bias_sigma = 0.05;
tuned.tape_plateau_min_fraction = 0.65;
tuned.tape_range_bias_all_max_std = 0.02;
LegPatternMatcher zero_matcher, tuned_matcher;
std::string error;
ASSERT_TRUE(zero_matcher.configure(zero, error)) << error;
ASSERT_TRUE(tuned_matcher.configure(tuned, error)) << error;
ScanLimits limits;
limits.min_range = 0.10;
limits.max_range = 3.0;
limits.range_sigma = 0.01;
limits.zero_range_is_no_echo = true;
for (const RecordedScan& scan : scans)
{
SCOPED_TRACE(scan.name);
const LegDetection a = zero_matcher.match(scan.geometry, scan.ranges, {}, limits, Pose2D());
const LegDetection b = tuned_matcher.match(scan.geometry, scan.ranges, {}, limits, Pose2D());
EXPECT_EQ(a.valid, b.valid);
EXPECT_EQ(a.legs_seen, b.legs_seen);
EXPECT_NEAR(a.x, b.x, 1e-12);
EXPECT_NEAR(a.y, b.y, 1e-12);
EXPECT_NEAR(a.yaw, b.yaw, 1e-12);
EXPECT_NEAR(a.center_x, b.center_x, 1e-12);
EXPECT_NEAR(a.center_y, b.center_y, 1e-12);
EXPECT_NEAR(a.center_yaw, b.center_yaw, 1e-12);
}
}
TEST(LegPatternMatcherKit, MirrorTapeDataFileLoadsRangesAndIntensities)
{
const std::vector<RecordedScan> scans = loadTapeScans();

View File

@@ -184,7 +184,7 @@ TEST(LegProfile, ValidatesAllBrightBiasThreshold)
EXPECT_FALSE(p.validate(error));
}
p.tape_range_bias_all_max_std = 0.02;
EXPECT_FALSE(p.validate(error));
EXPECT_TRUE(p.validate(error)) << error;
p.tape_enabled = true;
EXPECT_FALSE(p.validate(error));
p.tape_range_bias_sigma = 0.05;
@@ -869,12 +869,12 @@ TEST(LegProfile, ValidateRefusesBrokenProfiles)
EXPECT_FALSE(p.validate(error));
}
TEST(LegProfile, TapeBloomAndRangeBiasRequireTapeAndValidRanges)
TEST(LegProfile, TapeBloomAndRangeBiasRequireValidRanges)
{
std::string error;
LegProfile p = tciTrolley();
p.tape_bloom_max_angle = 0.10;
EXPECT_FALSE(p.validate(error));
EXPECT_TRUE(p.validate(error)) << error;
p = reflectiveTrolley();
p.tape_bloom_max_angle = 0.5;
@@ -902,7 +902,7 @@ TEST(LegProfile, TapePlateauRequiresValidFractionAndBloom)
}
p = tciTrolley();
p.tape_plateau_min_fraction = 0.65;
EXPECT_FALSE(p.validate(error));
EXPECT_TRUE(p.validate(error)) << error;
p = reflectiveTrolley();
p.tape_bloom_max_angle = 0.0;
p.tape_plateau_min_fraction = 0.65;
@@ -916,6 +916,55 @@ TEST(LegProfile, TapePlateauRequiresValidFractionAndBloom)
EXPECT_TRUE(p.validate(error)) << error;
}
TEST(LegProfile, TapeOffIgnoresTunedKeysButStillRejectsEntryTape)
{
LegProfile p = tciTrolley();
std::string error;
EXPECT_TRUE(p.ignoredTapeKeys().empty());
p.tape_bloom_max_angle = 0.10;
p.tape_range_bias_sigma = 0.05;
p.tape_plateau_min_fraction = 0.65;
p.tape_range_bias_all_max_std = 0.02;
ASSERT_TRUE(p.validate(error)) << error;
EXPECT_EQ(p.ignoredTapeKeys(), "tape_bloom_max_angle 0.100, tape_range_bias_sigma 0.050, "
"tape_plateau_min_fraction 0.650, tape_range_bias_all_max_std 0.020");
p.tape_enabled = true;
EXPECT_TRUE(p.validate(error)) << error;
EXPECT_TRUE(p.ignoredTapeKeys().empty());
p.tape_enabled = false;
p.tape_legs = TapeLegs::kEntry;
EXPECT_FALSE(p.validate(error));
EXPECT_EQ(error, "tape_legs 'entry' requires tape_enabled: true (forgot to turn the tape on?)");
p.tape_legs = TapeLegs::kAll;
p.tape_bloom_max_angle = 0.0;
p.tape_plateau_min_fraction = 0.0;
p.tape_range_bias_all_max_std = 0.0;
EXPECT_EQ(p.ignoredTapeKeys(), "tape_range_bias_sigma 0.050");
}
TEST(LegProfile, TapeKeyRangesAreCheckedEvenWhenTapeIsOff)
{
std::string error;
const double nan = std::numeric_limits<double>::quiet_NaN();
const double inf = std::numeric_limits<double>::infinity();
for (bool enabled : { false, true })
{
for (const auto& test : { std::pair<double LegProfile::*, double>{ &LegProfile::tape_bloom_max_angle, 0.5 },
{ &LegProfile::tape_range_bias_sigma, 0.201 },
{ &LegProfile::tape_plateau_min_fraction, 1.0 },
{ &LegProfile::tape_range_bias_all_max_std, 0.101 } })
{
for (double value : { -0.01, test.second, nan, inf })
{
LegProfile p = tciTrolley();
p.tape_enabled = enabled;
p.*test.first = value;
EXPECT_FALSE(p.validate(error)) << "tape_enabled=" << enabled << ", value=" << value;
}
}
}
}
TEST(LegPatternMatcher, PlateauRescuesEdgeRampButRejectsSlopeAndShortPlateau)
{
LegProfile p = reflectiveTrolley();