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:
@@ -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
|
||||
|
||||
@@ -722,6 +722,85 @@ TEST(VPatternMatcher, TapeConfirmsAPlateThatCarriesIt)
|
||||
EXPECT_GT(d.tape_points[1], 1u);
|
||||
}
|
||||
|
||||
TEST(VPatternMatcher, TapePicksTheTapedPlateOverTheBetterUntapedShape)
|
||||
{
|
||||
std::vector<Segment> world = vPlate(1.20, kHalf, kWing);
|
||||
std::vector<Segment> other = vPlate(1.60, kHalf, kWing);
|
||||
for (Segment& s : other)
|
||||
{
|
||||
s.ay += 0.90;
|
||||
s.by += 0.90;
|
||||
}
|
||||
world.insert(world.end(), other.begin(), other.end());
|
||||
|
||||
Rig shape_rig;
|
||||
ASSERT_TRUE(shape_rig.ok_) << shape_rig.error_;
|
||||
const Detection shape = shape_rig.run(world);
|
||||
ASSERT_TRUE(shape.valid) << shape.reason;
|
||||
ASSERT_GE(shape.candidate_count, 2u);
|
||||
|
||||
// Dán tấm thua khi chỉ xét hình; tấm thắng hình giữ nguyên không dải.
|
||||
const bool near_won = shape.apex_y < 0.45;
|
||||
std::vector<Segment> tapes = vPlateTapes(near_won ? 1.60 : 1.20, kHalf, kWing, kTapeWidth);
|
||||
if (near_won)
|
||||
{
|
||||
for (Segment& s : tapes)
|
||||
{
|
||||
s.ay += 0.90;
|
||||
s.by += 0.90;
|
||||
}
|
||||
}
|
||||
|
||||
Rig tape_rig(vTapeProfile());
|
||||
ASSERT_TRUE(tape_rig.ok_) << tape_rig.error_;
|
||||
const Detection d = tape_rig.run(world, tapes);
|
||||
ASSERT_TRUE(d.valid) << d.reason;
|
||||
EXPECT_NEAR(d.apex_x, near_won ? 1.60 : 1.20, 0.02);
|
||||
EXPECT_NEAR(d.apex_y, near_won ? 0.90 : 0.0, 0.02);
|
||||
EXPECT_EQ(d.candidate_count, 1u);
|
||||
}
|
||||
|
||||
TEST(VPatternMatcher, TwoTapedPlatesChooseTheHigherConfidenceWithoutAmbiguityFailure)
|
||||
{
|
||||
std::vector<Segment> world = vPlate(1.20, kHalf, kWing);
|
||||
std::vector<Segment> other = vPlate(1.60, kHalf, kWing);
|
||||
std::vector<Segment> near_tapes = vPlateTapes(1.20, kHalf, kWing, kTapeWidth);
|
||||
std::vector<Segment> far_tapes = vPlateTapes(1.60, kHalf, kWing, kTapeWidth);
|
||||
for (Segment& s : other)
|
||||
{
|
||||
s.ay += 0.90;
|
||||
s.by += 0.90;
|
||||
}
|
||||
for (Segment& s : far_tapes)
|
||||
{
|
||||
s.ay += 0.90;
|
||||
s.by += 0.90;
|
||||
}
|
||||
world.insert(world.end(), other.begin(), other.end());
|
||||
|
||||
Rig rig(vTapeProfile());
|
||||
ASSERT_TRUE(rig.ok_) << rig.error_;
|
||||
const Detection near = rig.run(world, near_tapes);
|
||||
const Detection far = rig.run(world, far_tapes);
|
||||
ASSERT_TRUE(near.valid) << near.reason;
|
||||
ASSERT_TRUE(far.valid) << far.reason;
|
||||
ASSERT_EQ(near.candidate_count, 1u);
|
||||
ASSERT_EQ(far.candidate_count, 1u);
|
||||
|
||||
near_tapes.insert(near_tapes.end(), far_tapes.begin(), far_tapes.end());
|
||||
const Detection d = rig.run(world, near_tapes);
|
||||
ASSERT_TRUE(d.valid) << d.reason;
|
||||
// Khác bộ dò xe, bộ dò V nhận cả hai rồi chọn điểm tin cao nhất, không báo ambiguous.
|
||||
EXPECT_GE(d.candidate_count, 2u);
|
||||
EXPECT_DOUBLE_EQ(d.confidence, std::max(near.confidence, far.confidence));
|
||||
if (near.confidence != far.confidence)
|
||||
{
|
||||
const bool near_wins = near.confidence > far.confidence;
|
||||
EXPECT_NEAR(d.apex_x, near_wins ? 1.20 : 1.60, 0.02);
|
||||
EXPECT_NEAR(d.apex_y, near_wins ? 0.0 : 0.90, 0.02);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(VPatternMatcher, TapeRejectsAVOfTheRightShapeThatCarriesNoTape)
|
||||
{
|
||||
// Đây là lý do tồn tại của cả tính năng. Hình ở đây ĐÚNG hoàn hảo — cùng góc, cùng chiều dài
|
||||
|
||||
Reference in New Issue
Block a user