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

@@ -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à