test(dock_pattern_detector): taped target next to an identical untaped one

Trolley (tape_legs all and entry) and V plate: with tape on, the taped target
is picked and the untaped one is rejected by the tape gate, whichever side it
stands on. Two fully taped carts still fail as ambiguous; two taped V plates
pick the higher confidence without an ambiguity check.

Risk characterised: one stray bright ray per bare leg lets a bare cart through
with tape_min_points 1 (scene becomes ambiguous); tape_min_points 2 picks the
taped cart.
This commit is contained in:
2026-10-31 17:19:02 +07:00
parent bce0d5570e
commit 5c1688ac50
2 changed files with 199 additions and 0 deletions

View File

@@ -388,6 +388,126 @@ TEST(LegPatternMatcher, TwoCartsSideBySideWithoutAPriorAreAmbiguous)
EXPECT_NE(d.reason.find("ambiguous"), std::string::npos) << d.reason;
}
TEST(LegPatternMatcher, AllTapePicksTheTapedCartOnThePositiveSide)
{
LegProfile p = tciTrolley();
p.tape_enabled = true;
p.tape_legs = TapeLegs::kAll;
p.tape_min_intensity = 1000.0;
p.tape_min_points = 2;
const bool taped[4] = { true, true, true, true };
World w;
leg_scan_sim::addCart(w, p, kCx, 0.485, M_PI, nullptr, taped);
leg_scan_sim::addCart(w, p, kCx, -0.485, M_PI);
const LegDetection d = detect(p, w);
ASSERT_TRUE(d.valid) << d.reason;
EXPECT_NEAR(d.center_x, kCx, 0.005);
EXPECT_NEAR(d.center_y, 0.485, 0.005);
EXPECT_LT(yawError(d.center_yaw, M_PI), 0.3 * kDeg);
EXPECT_EQ(d.leg_candidates, 4u);
}
TEST(LegPatternMatcher, AllTapePicksTheTapedCartOnTheNegativeSide)
{
LegProfile p = tciTrolley();
p.tape_enabled = true;
p.tape_legs = TapeLegs::kAll;
p.tape_min_intensity = 1000.0;
p.tape_min_points = 2;
const bool taped[4] = { true, true, true, true };
World w;
leg_scan_sim::addCart(w, p, kCx, 0.485, M_PI);
leg_scan_sim::addCart(w, p, kCx, -0.485, M_PI, nullptr, taped);
const LegDetection d = detect(p, w);
ASSERT_TRUE(d.valid) << d.reason;
EXPECT_NEAR(d.center_x, kCx, 0.005);
EXPECT_NEAR(d.center_y, -0.485, 0.005);
EXPECT_LT(yawError(d.center_yaw, M_PI), 0.3 * kDeg);
EXPECT_EQ(d.leg_candidates, 4u);
}
TEST(LegPatternMatcher, EntryTapePicksTheTapedCartAndItsEntryEdge)
{
LegProfile p = tciTrolley();
p.tape_enabled = true;
p.tape_legs = TapeLegs::kEntry;
p.tape_min_intensity = 1000.0;
p.tape_min_points = 2;
const bool taped[4] = { true, true, false, false };
World w;
leg_scan_sim::addCart(w, p, kCx, 0.485, M_PI, nullptr, taped);
leg_scan_sim::addCart(w, p, kCx, -0.485, M_PI);
const LegDetection d = detect(p, w);
ASSERT_TRUE(d.valid) << d.reason;
EXPECT_NEAR(d.center_x, kCx, 0.005);
EXPECT_NEAR(d.center_y, 0.485, 0.005);
EXPECT_LT(yawError(d.center_yaw, M_PI), 0.3 * kDeg);
EXPECT_GE(d.tape_bright_rays[dock_pattern_detector::kEntryLeft], 2u);
EXPECT_GE(d.tape_bright_rays[dock_pattern_detector::kEntryRight], 2u);
EXPECT_EQ(d.tape_bright_rays[dock_pattern_detector::kFarLeft], 0u);
EXPECT_EQ(d.tape_bright_rays[dock_pattern_detector::kFarRight], 0u);
}
TEST(LegPatternMatcher, TwoFullyTapedCartsWithoutAPriorAreAmbiguous)
{
LegProfile p = tciTrolley();
p.tape_enabled = true;
p.tape_legs = TapeLegs::kAll;
p.tape_min_intensity = 1000.0;
p.tape_min_points = 2;
const bool taped[4] = { true, true, true, true };
World w;
leg_scan_sim::addCart(w, p, kCx, 0.485, M_PI, nullptr, taped);
leg_scan_sim::addCart(w, p, kCx, -0.485, M_PI, nullptr, taped);
const LegDetection d = detect(p, w);
EXPECT_FALSE(d.valid);
EXPECT_NE(d.reason.find("ambiguous: two carts"), std::string::npos) << d.reason;
}
TEST(LegPatternMatcher, OneStrayBrightRayLetsABareCartThroughWithTapeMinPointsOne)
{
LegProfile p = tciTrolley();
p.tape_enabled = true;
p.tape_legs = TapeLegs::kAll;
p.tape_min_intensity = 1000.0;
const bool taped[4] = { true, true, true, true };
World w;
leg_scan_sim::addCart(w, p, kCx, 0.485, M_PI, nullptr, taped);
const std::vector<int> bare_legs = leg_scan_sim::addCart(w, p, kCx, -0.485, M_PI);
const auto g = leg_scan_sim::s300Geometry();
leg_scan_sim::Scan scan = leg_scan_sim::rayCast(w, g);
for (int id : bare_legs)
{
std::vector<std::size_t> hits;
for (std::size_t i = 0; i < scan.hit.size(); ++i)
{
if (scan.hit[i] == id)
{
hits.push_back(i);
}
}
ASSERT_GE(hits.size(), 2u);
scan.intensities[hits[hits.size() / 2]] = 2000.0f;
}
// tape_min_points 1 được dùng trong config robot: một tia loá đã đủ qua cổng mỗi chân.
p.tape_min_points = 1;
const LegDetection one = matchScan(p, g, scan);
EXPECT_FALSE(one.valid);
EXPECT_NE(one.reason.find("ambiguous: two carts"), std::string::npos) << one.reason;
p.tape_min_points = 2;
const LegDetection two = matchScan(p, g, scan);
ASSERT_TRUE(two.valid) << two.reason;
EXPECT_NEAR(two.center_x, kCx, 0.005);
EXPECT_NEAR(two.center_y, 0.485, 0.005);
EXPECT_LT(yawError(two.center_yaw, M_PI), 0.3 * kDeg);
}
TEST(LegPatternMatcher, LegsOfTwoNeighboursDoNotMakeAPhantomCart)
{
// Hai xe sát nhau, prior đặt ĐÚNG GIỮA hai xe: bốn chân phía trong (khe 0.453 m) gần giống một xe