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

@@ -63,6 +63,42 @@ bool patternFromString(const std::string& name, PatternType& out, std::string& e
return false;
}
const char* toString(VShape shape)
{
switch (shape)
{
case VShape::kAny:
return "any";
case VShape::kConcave:
return "concave";
case VShape::kConvex:
return "convex";
}
return "unknown";
}
bool vShapeFromString(const std::string& name, VShape& out, std::string& error)
{
if (name == "any")
{
out = VShape::kAny;
return true;
}
if (name == "concave")
{
out = VShape::kConcave;
return true;
}
if (name == "convex")
{
out = VShape::kConvex;
return true;
}
error = "unknown v_shape '" + name + "'; known values are: any, concave, convex";
return false;
}
bool DockProfile::validate(std::string& error) const
{
if (!std::isfinite(vertex_angle) || vertex_angle <= 0.0 || vertex_angle >= M_PI)
@@ -101,6 +137,13 @@ bool DockProfile::validate(std::string& error) const
error = "vertex_gap must be < wing_length, otherwise any two crossing walls pass as a V";
return false;
}
if (v_shape != VShape::kAny && pattern != PatternType::kV)
{
// Nói thẳng thay vì nhận config rồi không bao giờ có hiệu lực: cổng lõm/lồi chỉ VPatternMatcher
// đọc, một profile `pattern: arc` mang khoá này là đang khai một thứ sẽ bị lờ đi im lặng.
error = "v_shape is only meaningful when pattern is 'v'";
return false;
}
if (has_prior)
{
if (!std::isfinite(prior_x) || !std::isfinite(prior_y))

View File

@@ -247,6 +247,7 @@ Detection VPatternMatcher::match(const std::vector<Line>& lines,
std::size_t rejected_vertex_gap = 0;
std::size_t rejected_angle = 0;
std::size_t rejected_length = 0;
std::size_t rejected_shape = 0;
std::size_t rejected_support = 0;
std::size_t rejected_prior = 0;
std::size_t rejected_tape = 0;
@@ -400,7 +401,21 @@ Detection VPatternMatcher::match(const std::vector<Line>& lines,
by /= bn;
// Gốc cảm biến là (0, 0) trong frame của scan, nên vector từ đỉnh về phía cảm biến là -apex.
if (bx * (-apex.x) + by * (-apex.y) < 0.0)
// TRƯỚC khi lật: b đang chỉ vào LÒNG chữ V (xem class doc). Lòng V đã hướng VỀ cảm biến
// (dot >= 0) là V LÕM — tấm ôm lấy robot; lòng V hướng RA XA cảm biến (dot < 0) là V LỒI —
// góc ngoài của một vật khác (tủ, pallet). Phải đọc dấu NGAY ĐÂY, trước khi bước lật dưới
// xoá mất nó bằng cách luôn quay b về phía cảm biến.
const double dot_to_sensor = bx * (-apex.x) + by * (-apex.y);
const bool opens_to_sensor = dot_to_sensor >= 0.0; // true = lõm, false = lồi
if ((profile_.v_shape == VShape::kConcave && !opens_to_sensor) ||
(profile_.v_shape == VShape::kConvex && opens_to_sensor))
{
++rejected_shape;
continue;
}
if (dot_to_sensor < 0.0)
{
bx = -bx;
by = -by;
@@ -599,6 +614,16 @@ Detection VPatternMatcher::match(const std::vector<Line>& lines,
best.reason = std::to_string(rejected_confidence) +
" candidate(s) matched but scored below min_confidence";
}
else if (rejected_shape > 0)
{
// Nói rõ profile đang đòi hướng nào — "đúng hình nhưng sai hướng" đòi xử trí khác hẳn "sai
// góc/chiều dài": đây không phải lỗi dung sai, mà là một vật khác hình chữ V thật (góc tủ,
// góc pallet lồi ra phía cảm biến thay vì lõm vào).
best.reason = std::to_string(rejected_shape) +
" candidate(s) had the right vertex angle and wing length but the wrong "
"concave/convex orientation (profile requires v_shape=" +
toString(profile_.v_shape) + ")";
}
else if (rejected_length > 0 || rejected_angle > 0)
{
// Số ĐO ĐƯỢC của ứng viên trượt sát nhất. Không có nó thì "cánh 0.22 m vì bị che" và