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

@@ -25,6 +25,7 @@
#include <tf3/buffer_core.h>
#include <action_core/pose_sample_filter.h>
#include <dock_pattern_detector/arc_pattern_matcher.h>
#include <dock_pattern_detector/v_pattern_matcher.h>
#include <robot_line_extraction/line_extractor.h>
#include <robot_sensor_ports/sensor_reader.h>
@@ -217,8 +218,19 @@ public:
return false;
}
// Chọn bộ khớp theo biên dạng của profile. Một switch tường minh chứ không phải interface ảo:
// tập biên dạng là một enum ĐÓNG, mỗi bộ khớp chỉ nặng bằng một DockProfile, và thêm dạng mới
// là thêm một member cộng hai nhánh — rẻ hơn một tầng ảo cho hai hiện thực.
//
// Mỗi bộ khớp tự từ chối profile không thuộc về nó, nên nếu switch này quên một nhánh thì lỗi
// hiện ra lúc BOOT kèm tên biên dạng, không phải lúc chạy dưới dạng "dò mãi không ra".
std::string error;
if (!matcher_.configure(found->second, error))
active_pattern_ = found->second.pattern;
const bool configured =
(active_pattern_ == dock_pattern_detector::PatternType::kArc)
? arc_matcher_.configure(found->second, error)
: v_matcher_.configure(found->second, error);
if (!configured)
{
robot::log_error("[dock_pattern] '%s': profile '%s' is invalid: %s", name_.c_str(),
profile_name.c_str(), error.c_str());
@@ -350,6 +362,16 @@ private:
nh_param(p_nh, "offset_yaw", profile.offset_yaw);
nh_param(p_nh, "min_confidence", profile.min_confidence);
nh_param(p_nh, "arc_radius", profile.arc_radius);
nh_param(p_nh, "arc_radius_tolerance", profile.arc_radius_tolerance);
nh_param(p_nh, "arc_span", profile.arc_span);
nh_param(p_nh, "arc_min_span", profile.arc_min_span);
nh_param(p_nh, "arc_max_rms", profile.arc_max_rms);
int min_arc_points = static_cast<int>(profile.min_arc_points);
nh_param(p_nh, "min_arc_points", min_arc_points);
profile.min_arc_points = static_cast<std::size_t>(std::max(0, min_arc_points));
nh_param(p_nh, "tape_enabled", profile.tape_enabled);
nh_param(p_nh, "tape_spacing", profile.tape_spacing);
nh_param(p_nh, "tape_width", profile.tape_width);
@@ -470,7 +492,13 @@ private:
// `intensities` đi thẳng, không đổi kiểu: message đã là std::vector<float>. Rỗng khi driver
// không gửi cường độ — matcher tự nói ra điều đó nếu profile lại đang đòi dải phản quang.
const dock_pattern_detector::Detection detection = matcher_.match(lines_, scan->intensities);
//
// Cung tròn không nhận cường độ: `findTape` quét theo chỉ số tia của một ĐOẠN THẲNG, mà cung
// không sinh ra đoạn nào. Profile `arc` bật `tape_enabled` đã bị từ chối từ lúc boot.
const dock_pattern_detector::Detection detection =
(active_pattern_ == dock_pattern_detector::PatternType::kArc)
? arc_matcher_.match(lines_)
: v_matcher_.match(lines_, scan->intensities);
if (!detection.valid)
{
noteReason(now, detection.reason);
@@ -483,16 +511,17 @@ private:
// quang đang bật. Đây là số người lắp trạm cần để đặt dung sai: dán dải lệch vài centimet vẫn
// dò ra hôm nay rồi trượt hẳn khi trời ẩm hoặc dải bẩn bớt sáng, mà không có dòng này thì
// không ai biết nó vốn đã sát mép. Chỉ in một lần vì nó là số hiệu chỉnh, không phải nhịp chạy.
if (matcher_.profile().tape_enabled && !tape_reported_)
if (active_pattern_ != dock_pattern_detector::PatternType::kArc &&
v_matcher_.profile().tape_enabled && !tape_reported_)
{
tape_reported_ = true;
robot::log_info("[dock_pattern] '%s': reflective tape: %zu + %zu bright ray(s), spacing "
"%.3f m (profile %.3f+-%.3f), widths %.3f / %.3f m (profile %.3f+-%.3f).",
name_.c_str(), detection.tape_points[0], detection.tape_points[1],
detection.measured_tape_spacing, matcher_.profile().tape_spacing,
matcher_.profile().tape_spacing_tolerance, detection.measured_tape_width[0],
detection.measured_tape_width[1], matcher_.profile().tape_width,
matcher_.profile().tape_width_tolerance);
detection.measured_tape_spacing, v_matcher_.profile().tape_spacing,
v_matcher_.profile().tape_spacing_tolerance,
detection.measured_tape_width[0], detection.measured_tape_width[1],
v_matcher_.profile().tape_width, v_matcher_.profile().tape_width_tolerance);
}
pending_ = detection;
@@ -645,7 +674,9 @@ private:
std::map<std::string, dock_pattern_detector::DockProfile> profiles_;
robot_line_extraction::LineExtractor extractor_;
dock_pattern_detector::VPatternMatcher matcher_;
dock_pattern_detector::VPatternMatcher v_matcher_;
dock_pattern_detector::ArcPatternMatcher arc_matcher_;
dock_pattern_detector::PatternType active_pattern_ = dock_pattern_detector::PatternType::kV;
PoseSampleFilter filter_;
robot::Time started_at_;