feat(v_pattern): add v_shape gate to tell a concave dock V from a convex corner

New profile key v_shape (any | concave | convex), default any = old behaviour. A corner of a cabinet or pallet with the same vertex_angle and wing_length passes every other gate; only the opening direction tells it from a dock that wraps the robot. v_shape is rejected on a non-v pattern. A rejection by orientation has its own reason string. Tests added.
This commit is contained in:
2026-10-27 13:09:30 +07:00
parent 00e5f3e2cb
commit edc6b30431
5 changed files with 193 additions and 6 deletions

View File

@@ -30,6 +30,7 @@ using dock_pattern_detector::Detection;
using dock_pattern_detector::DockProfile;
using dock_pattern_detector::PatternType;
using dock_pattern_detector::VPatternMatcher;
using dock_pattern_detector::VShape;
using robot_line_extraction::Line;
using robot_line_extraction::LineExtractionParams;
using robot_line_extraction::LineExtractor;
@@ -90,10 +91,15 @@ std::vector<double> rayCast(const ScanGeometry& g, const std::vector<Segment>& w
* @param half_angle [rad] độ nghiêng mỗi cánh so với trục y
* @param wing [m] chiều dài một cánh
* @param yaw [rad] xoay cả tấm quanh đỉnh
* @param concave false (mặc định) = mút cánh XA cảm biến hơn đỉnh, tức V LỒI — y hệt hình mọi
* test khác trong file này vẫn dùng. true = mút cánh GẦN cảm biến hơn đỉnh, tức
* V LÕM — lòng V mở về phía cảm biến, như trạm ôm robot.
*
* Góc TRONG tại đỉnh = pi - 2*half_angle. `half = pi/4` cho tấm mở 90 độ.
* Góc TRONG tại đỉnh = pi - 2*half_angle. `half = pi/4` cho tấm mở 90 độ. Đổi `concave` chỉ lật
* dấu offset x của mút cánh; góc đỉnh và chiều dài cánh giữ nguyên.
*/
std::vector<Segment> vPlate(double apex_x, double half_angle, double wing, double yaw = 0.0)
std::vector<Segment> vPlate(double apex_x, double half_angle, double wing, double yaw = 0.0,
bool concave = false)
{
const double c = std::cos(yaw);
const double s = std::sin(yaw);
@@ -102,7 +108,8 @@ std::vector<Segment> vPlate(double apex_x, double half_angle, double wing, doubl
oy = s * (x - apex_x) + c * y;
};
const double tip_x = apex_x + wing * std::sin(half_angle);
const double wing_dir = concave ? -1.0 : 1.0;
const double tip_x = apex_x + wing_dir * wing * std::sin(half_angle);
const double tip_y = wing * std::cos(half_angle);
Segment w1;
@@ -395,6 +402,79 @@ TEST(VPatternMatcher, APalletCornerIsNotADock)
EXPECT_NE(d.reason.find("wing length"), std::string::npos) << d.reason;
}
// ------------------------------------------------------------------------------------------------
// 2b. Hướng lõm/lồi — phân biệt trạm thật với góc lồi CÙNG kích thước (tủ, pallet)
// ------------------------------------------------------------------------------------------------
TEST(VPatternMatcher, VShapeDefaultsToAnyAndAcceptsBothOrientations)
{
// vProfile() không đặt v_shape, nên mặc định phải là kAny — không chỉnh gì thì không đổi hành vi
// cũ. Chữ V lồi (hình mọi test "dò đúng" khác đang dùng) và chữ V lõm đều phải lọt.
DockProfile p = vProfile();
ASSERT_EQ(p.v_shape, VShape::kAny);
Rig rig_convex(p);
ASSERT_TRUE(rig_convex.ok_) << rig_convex.error_;
const Detection convex = rig_convex.run(vPlate(1.20, M_PI / 4.0, 0.30, 0.0, /*concave=*/false));
EXPECT_TRUE(convex.valid) << convex.reason;
Rig rig_concave(p);
ASSERT_TRUE(rig_concave.ok_) << rig_concave.error_;
const Detection concave = rig_concave.run(vPlate(1.20, M_PI / 4.0, 0.30, 0.0, /*concave=*/true));
EXPECT_TRUE(concave.valid) << concave.reason;
}
TEST(VPatternMatcher, ConcaveProfileAcceptsAConcaveVAndRejectsAConvexOne)
{
DockProfile p = vProfile();
p.v_shape = VShape::kConcave;
// Lòng V mở VỀ cảm biến — trạm ôm robot. Cùng góc đỉnh, cùng chiều dài cánh với mọi test khác.
Rig rig_ok(p);
ASSERT_TRUE(rig_ok.ok_) << rig_ok.error_;
const Detection ok = rig_ok.run(vPlate(1.20, M_PI / 4.0, 0.30, 0.0, /*concave=*/true));
EXPECT_TRUE(ok.valid) << ok.reason;
// Góc LỒI cùng kích thước (tủ, pallet) — đây chính là dương tính giả mà khoá này phải chặn.
Rig rig_reject(p);
ASSERT_TRUE(rig_reject.ok_) << rig_reject.error_;
const Detection rejected = rig_reject.run(vPlate(1.20, M_PI / 4.0, 0.30, 0.0, /*concave=*/false));
EXPECT_FALSE(rejected.valid);
EXPECT_NE(rejected.reason.find("orientation"), std::string::npos) << rejected.reason;
}
TEST(VPatternMatcher, ConvexProfileAcceptsAConvexVAndRejectsAConcaveOne)
{
DockProfile p = vProfile();
p.v_shape = VShape::kConvex;
// Lòng V mở RA XA cảm biến — góc lồi của vật (tủ, pallet), hoặc một trạm dock kiểu mỏ hàn.
Rig rig_ok(p);
ASSERT_TRUE(rig_ok.ok_) << rig_ok.error_;
const Detection ok = rig_ok.run(vPlate(1.20, M_PI / 4.0, 0.30, 0.0, /*concave=*/false));
EXPECT_TRUE(ok.valid) << ok.reason;
// V lõm cùng kích thước phải bị loại khi profile đòi lồi.
Rig rig_reject(p);
ASSERT_TRUE(rig_reject.ok_) << rig_reject.error_;
const Detection rejected = rig_reject.run(vPlate(1.20, M_PI / 4.0, 0.30, 0.0, /*concave=*/true));
EXPECT_FALSE(rejected.valid);
EXPECT_NE(rejected.reason.find("orientation"), std::string::npos) << rejected.reason;
}
TEST(VPatternMatcher, RefusesAVShapeProfileOnAnArcPattern)
{
// v_shape chỉ VPatternMatcher đọc; đặt nó trên profile 'arc' là khai một khoá sẽ bị lờ đi im
// lặng. validate() phải bắt lúc nạp config, không phải lúc dò.
DockProfile p;
p.pattern = PatternType::kArc;
p.v_shape = VShape::kConcave;
std::string error;
EXPECT_FALSE(p.validate(error));
EXPECT_NE(error.find("v_shape"), std::string::npos) << error;
}
TEST(VPatternMatcher, TwoWallsThatCrossFarFromTheirEndsAreNotAV)
{
Rig rig;