feat: route a profile to the matcher its pattern names, and add an arc dock model

The handler held one concrete VPatternMatcher, so a profile declaring
pattern: arc could not reach the arc matcher at all. It now picks by pattern at
start(), reads the arc_* keys from YAML, and calls whichever matcher the
profile named.

An explicit switch, not a virtual interface: the set of patterns is a closed
enum, each matcher weighs one DockProfile, and adding a shape is one member and
two branches - cheaper than an abstraction layer over two implementations. Each
matcher refuses a profile that is not its own, so a branch missing from that
switch shows up at BOOT with the pattern named, not at runtime as "it never
detects".

Intensities go only to the V matcher. findTape walks the ray span of a fitted
line segment and an arc produces none, so an arc profile that sets tape_enabled
is already refused when the config loads.

sim/models/dock_cradle_arc is a concave cradle, radius 0.40 m over 2.0 rad, for
testing this in Gazebo. Its origin sits ON the deepest point, unlike
dock_plate_v whose origin is 0.2121 m off the apex and has caused confusion:
the detector reports the deepest point, so here that is the same number you
spawn at, with nothing to subtract.

It is 24 flat facets rather than a mesh, because Gazebo classic has no arc
primitive and a mesh means a binary file in the repo. The approximation error
is the sagitta of one chord, 0.35 mm - an order below the 3 mm range noise, so
the circle fit cannot tell it from a real curve.

Two tests pin the routing rather than the matching rules, which have their own
tests in dock_pattern_detector: a cradle under an arc profile writes the goal
frame at the deepest point, and a V plate under the same arc profile is
rejected. Without the second one, a change that broke arc detection outright
would look exactly like the gate doing its job.
This commit is contained in:
2026-08-26 20:15:05 +07:00
parent 487396a491
commit efa8f4bb48
6 changed files with 426 additions and 8 deletions

View File

@@ -68,6 +68,18 @@ actions_dock:
tape_width_tolerance: 0.05
tape_min_intensity: 500.0
# Máng cong lõm — biên dạng thứ hai, đi qua ArcPatternMatcher chứ không phải VPatternMatcher.
cradle:
pattern: arc
arc_radius: 0.40 # [m]
arc_radius_tolerance: 0.06 # [m]
arc_span: 2.2 # [rad] góc mở toàn phần của máng
arc_min_span: 0.52 # [rad] sàn để tin phép khớp
arc_max_rms: 0.010 # [m] cổng chính chống nhầm góc tường thành cung
min_arc_points: 8
min_confidence: 0.3
offset_x: 0.60 # [m] lùi ra trước mặt máng
# scan_topic không có trong kho -> phải từ chối LÚC BOOT kèm danh sách topic có thật.
actions_dock_bad_topic:
handlers:

View File

@@ -64,6 +64,20 @@ std::vector<Segment> vPlate(double apex_x, double half_angle, double wing)
return { { apex_x, 0.0, tip_x, tip_y }, { apex_x, 0.0, tip_x, -tip_y } };
}
/// @brief Máng cong LÕM: tâm ở @p center_x trên trục x, mặt cong ở XA hơn tâm.
std::vector<Segment> concaveCradle(double center_x, double r, double span, int facets = 300)
{
std::vector<Segment> out;
for (int i = 0; i + 1 < facets; ++i)
{
const double t0 = -span / 2.0 + span * i / (facets - 1);
const double t1 = -span / 2.0 + span * (i + 1) / (facets - 1);
out.push_back({ center_x + r * std::cos(t0), r * std::sin(t0), center_x + r * std::cos(t1),
r * std::sin(t1) });
}
return out;
}
/// @brief [m] Cự ly từ điểm (@p px, @p py) tới đoạn @p s.
double distToSegment(double px, double py, const Segment& s)
{
@@ -542,6 +556,38 @@ TEST(DockPatternAction, ATapeProfileRefusesAPlateThatCarriesNoTape)
EXPECT_NE(rig.last_message.find("reflective tape"), std::string::npos) << rig.last_message;
}
TEST(DockPatternAction, DispatchesToTheArcMatcherWhenTheProfileAsksForOne)
{
// Kiểm ĐƯỜNG ĐỊNH TUYẾN, không phải luật khớp — luật đã có test riêng bên dock_pattern_detector.
// Câu hỏi ở đây: profile khai `pattern: arc` có thật sự chạy qua ArcPatternMatcher không, hay
// handler vẫn đưa nó cho bộ khớp chữ V. Nếu đưa nhầm, bộ khớp chữ V nay TỪ CHỐI ngay lúc start,
// nên test này fail ở dòng start chứ không phải im lặng không dò ra gì.
Rig rig;
ASSERT_TRUE(rig.store_ok_);
ASSERT_TRUE(rig.loaded);
ASSERT_TRUE(rig.handler->start(makeAction("cradle"), robot::Time(10.0)));
EXPECT_EQ(rig.feed(concaveCradle(1.20, 0.40, 2.0), 8), ActionStatus::kSucceeded)
<< rig.last_message;
// Tâm ở 1.20, bán kính 0.40 -> điểm sâu nhất ở 1.60; profile lùi 0.60 m ra phía robot.
const tf3::TransformStampedMsg out = rig.tf.lookupTransform(kGlobalFrame, kOutFrame, tf3::Time());
EXPECT_NEAR(out.transform.translation.x, 1.00, 0.05);
EXPECT_NEAR(out.transform.translation.y, 0.00, 0.05);
}
TEST(DockPatternAction, AnArcProfileRefusesAVPlate)
{
// Mặt kia: cùng handler, cùng profile arc, nhưng trong tầm là một tấm chữ V. Không có cặp này
// thì một lỗi làm hỏng hẳn phép dò cung cũng trông y hệt "cổng đang làm việc".
Rig rig;
ASSERT_TRUE(rig.store_ok_);
ASSERT_TRUE(rig.loaded);
ASSERT_TRUE(rig.handler->start(makeAction("cradle"), robot::Time(10.0)));
EXPECT_EQ(rig.feed(vPlate(1.20, M_PI / 4.0, 0.30), 60), ActionStatus::kFailed);
}
TEST(DockPatternAction, RefusesADefaultProfileThatDoesNotExist)
{
Rig rig("actions_dock_bad_default");