fix(leg_pattern): rescue a real taped leg's edge-ramp bright run from the bloom-spread gate

This commit is contained in:
2026-10-30 09:43:41 +07:00
parent 347896e252
commit 588ed58b6d
8 changed files with 387 additions and 18 deletions

View File

@@ -181,12 +181,36 @@ theo tia xa hơn bề rộng biểu kiến của chính nó. Giới hạn này c
lõi chân. Trên lidar KIT, ở ngưỡng 8000 có 5501 lõi thật với độ trải tối đa khoảng 0.041 m; ở 4000
lõi thật đã trải tới 0.068 m, nên KIT cần ngưỡng 8000.
`tape_plateau_min_fraction` [-] mặc định 0 giữ nguyên cổng loại cũ. Khi > 0 (cần bật tape và
bloom), run bị loại vì trải cự ly được cứu nếu đoạn liên tiếp dài nhất có range không vượt minimum
cộng nửa bề rộng biểu kiến chiếm đủ tỷ lệ và đủ tia. Chỉ đoạn này vào fit; toàn bộ run và bloom
vẫn bị lọc. KIT dán băng gương dùng 0.65; giảm ngưỡng có thể nhận lõi bloom méo và làm sai pose,
tăng ngưỡng có thể bỏ chân thật. Phải nhỏ hơn 1 và kiểm chứng bằng scan của lidar.
`tape_range_bias_sigma` [m] bật ước lượng thêm một bias cự ly chung cho các điểm sáng trong fit 4-DoF
(x, y, yaw, b). Fit chỉ dùng đường này khi có ít nhất một góc chứa điểm sáng và ít nhất một góc có
toàn bộ điểm không sáng (chân trần); điểm sáng được hiệu chỉnh dọc theo tia, còn prior Gaussian giữ
bias gần 0. `0` tắt ước lượng và dùng fit 3-DoF cũ. Fit từ chối kết quả nếu `|b| > 0.1 m` để tránh
đưa hiệu chỉnh bất thường vào pose.
**Lỗi đã biết, chưa sửa (30/10): dán băng gương cả 4 chân thì bias không được hiệu chỉnh.** Lidar KIT
đọc điểm băng gương ngắn hơn thật khoảng b ≈ 0.028–0.032 m (tia gần bão hoà), mỗi chân dán bị kéo
về phía lidar dọc theo tia của chính nó. Khi `tape_legs: all` không còn chân trần làm mốc, nên fit
4-DoF ở trên không chạy và b giữ nguyên trong pose:
- Đứng gần (lidar sát đường cạnh vào, hai chân trước lệch nhau ~88° nhìn từ lidar): hai chân bị kéo
gần như ngược chiều, cặp cạnh vào co 1.4·b ≈ 4–6 cm. Bag 29/10 13:35 (run6): 3 lần detect fail ở
225/225 scan với `two legs 0.701–0.719 m apart where the cart has 0.762 (tolerance 0.042)`.
- 0.8–1.5 m: còn qua nhưng sát ngưỡng (30/10: opening 0.752 ở 1.5 m, 0.734 ở 0.78 m).
- Đứng xa: khoảng cách cặp gần đúng, nhưng cả xe bị kéo gần lidar thêm ~2.5 cm mà không báo lỗi
(thiếu chiều sâu khi dock).
Cặp chân nằm dọc theo tia nhìn bị kéo cùng chiều nên vẫn đúng (depth 0.478–0.484). Hướng sửa đã thử
offline trên run6: fit pose cộng một b chung trên các chân đều dán cho b = 0.028–0.032 ổn định, RMS chân
giảm từ 1.7–2.0 cm xuống 0.3–0.5 cm, tâm xe dịch 2.4–2.7 cm. Sai số ước lượng σ_b tăng theo khoảng cách
(≈ 0.009 ở 0.65 m, 0.013 ở 1.0 m, 0.023 ở 2.0 m), nên chỉ nên dùng b khi σ_b đủ nhỏ và phải gắn sau
`tape_enabled` cộng khoá riêng để detect không dán gương giữ nguyên.
**Điểm tin** = ½ · (số chân thấy / 4) + ½ · clamp(2 − RMS chuẩn hoá, 0, 1). RMS chuẩn hoá chia phần dư
cho `sqrt(σ_điểm² + (cart_dim_tolerance / 2)²)`: σ_điểm là nhiễu lidar (`range_sigma`), còn
`cart_dim_tolerance / 2` là σ của mô hình, cho sai số gia công giữa các xe cùng loại. Phần σ mô hình

View File

@@ -251,6 +251,7 @@ private:
std::vector<Ray> rays_;
std::vector<std::size_t> cluster_;
std::vector<std::size_t> tape_run_;
std::vector<std::size_t> tape_plateau_;
std::vector<std::size_t> left_skirt_;
std::vector<std::size_t> right_skirt_;
std::vector<LegCandidate> legs_;
@@ -265,6 +266,7 @@ private:
std::size_t rejected_points_ = 0;
std::size_t rejected_tape_ = 0;
std::size_t rejected_bloom_spread_ = 0;
std::size_t rescued_tape_plateau_ = 0;
double width_miss_ = 0.0; // [m] bề rộng của cụm trượt cổng bề rộng sát nhất
bool truncated_ = false;
};

View File

@@ -159,6 +159,12 @@ struct LegProfile
*/
double tape_bloom_max_angle = 0.0;
/**
* [-] Tỷ lệ tối thiểu của plateau liên tiếp gần nhất trong run sáng bị trải cự ly;
* 0 = tắt, giữ nguyên cách loại cũ. Cần bật tape và bộ lọc bloom.
*/
double tape_plateau_min_fraction = 0.0;
/**
* [m] Độ lệch chuẩn tiên nghiệm của sai lệch cự ly chung cho các tia sáng; 0 = không ước lượng.
*/

View File

@@ -406,6 +406,7 @@ void LegPatternMatcher::buildCandidates(double dtheta)
rejected_points_ = 0;
rejected_tape_ = 0;
rejected_bloom_spread_ = 0;
rescued_tape_plateau_ = 0;
width_miss_ = std::numeric_limits<double>::infinity();
truncated_ = false;
tape_run_.clear();
@@ -426,14 +427,53 @@ void LegPatternMatcher::buildCandidates(double dtheta)
// Cổng này cần ngưỡng nằm trên lõi: KIT ở 8000 có độ trải lõi thật tối đa 0.041 m (5501 lõi),
// còn ở 4000 lõi thật đã tới 0.068 m; vì vậy cấu hình KIT cần 8000. Độ trải lớn hơn thường là
// lõi bị bloom của gương gần hơn làm méo, không phải một chân thật.
const std::vector<std::size_t>* core = &bright_run;
if (max_range - min_range > profile_.maxApparentLegWidth())
{
for (std::size_t idx : bright_run)
std::size_t best_start = 0, best_size = 0, start = 0, size = 0;
if (profile_.tape_plateau_min_fraction > 0.0)
{
rays_[idx].tape_filtered = true;
const double limit = min_range + profile_.maxApparentLegWidth() / 2.0;
for (std::size_t i = 0; i < bright_run.size(); ++i)
{
if (rays_[bright_run[i]].range <= limit)
{
if (size == 0)
{
start = i;
}
++size;
if (size > best_size)
{
best_start = start;
best_size = size;
}
}
else
{
size = 0;
}
}
}
if (profile_.tape_plateau_min_fraction > 0.0 &&
best_size >= std::max(profile_.tape_min_points, profile_.min_leg_points) &&
static_cast<double>(best_size) >=
profile_.tape_plateau_min_fraction * static_cast<double>(bright_run.size()))
{
tape_plateau_.assign(bright_run.begin() + best_start,
bright_run.begin() + best_start + best_size);
core = &tape_plateau_;
++rescued_tape_plateau_;
}
else
{
for (std::size_t idx : bright_run)
{
rays_[idx].tape_filtered = true;
}
++rejected_bloom_spread_;
return;
}
++rejected_bloom_spread_;
return;
}
if (bright_run.size() < std::max(profile_.tape_min_points, profile_.min_leg_points))
@@ -443,6 +483,7 @@ void LegPatternMatcher::buildCandidates(double dtheta)
left_skirt_.clear();
right_skirt_.clear();
// Tia dốc vẫn sáng: phải bắt đầu ngoài run, không coi chúng là mép dính của plateau.
const int left = walkTapeBloom(bright_run.front(), -1, left_skirt_);
const int right = walkTapeBloom(bright_run.back(), +1, right_skirt_);
for (std::size_t idx : bright_run)
@@ -457,7 +498,7 @@ void LegPatternMatcher::buildCandidates(double dtheta)
{
rays_[idx].tape_filtered = true;
}
processPoints(bright_run, left, right, dtheta);
processPoints(*core, left, right, dtheta);
};
for (std::size_t i = 0; i < rays_.size(); ++i)
@@ -554,6 +595,10 @@ std::string LegPatternMatcher::describeClusterRejections() const
format("%.3f", profile_.maxApparentLegWidth()) +
" m in range (bloom from a nearer mirror)";
}
if (profile_.tape_plateau_min_fraction > 0.0)
{
text += ", " + std::to_string(rescued_tape_plateau_) + " bright core(s) kept by their plateau";
}
if (rejected_width_ > 0 && std::isfinite(width_miss_))
{
text += format(" (closest width miss %.3f m; leg_width %.3f m)", width_miss_,

View File

@@ -200,6 +200,18 @@ bool LegProfile::validate(std::string& error) const
error = "tape_range_bias_sigma must be finite and in [0, 0.2] [m]";
return false;
}
if (!std::isfinite(tape_plateau_min_fraction) || tape_plateau_min_fraction < 0.0 ||
tape_plateau_min_fraction >= 1.0)
{
error = "tape_plateau_min_fraction must be finite and in [0, 1)";
return false;
}
if (tape_plateau_min_fraction > 0.0 && (!tape_enabled || tape_bloom_max_angle <= 0.0))
{
error = "non-zero tape_plateau_min_fraction requires tape_enabled: true and "
"tape_bloom_max_angle > 0";
return false;
}
if (!tape_enabled && (tape_bloom_max_angle > 0.0 || tape_range_bias_sigma > 0.0))
{
error = "non-zero tape_bloom_max_angle or tape_range_bias_sigma requires tape_enabled: true";

File diff suppressed because one or more lines are too long

View File

@@ -14,8 +14,12 @@
*********************************************************************/
#include <gtest/gtest.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
@@ -78,11 +82,10 @@ std::vector<RecordedScan> loadScans()
return scans;
}
std::vector<RecordedScan> loadTapeScans(const char* filename = "kit_f_scan_trolley_tape.txt")
std::vector<RecordedScan> loadTapeScans(const std::string& path)
{
std::vector<RecordedScan> scans;
std::ifstream in(std::string(DOCK_PATTERN_DETECTOR_TEST_DATA_DIR) +
"/" + filename);
std::ifstream in(path);
std::string line;
while (std::getline(in, line))
{
@@ -120,6 +123,11 @@ std::vector<RecordedScan> loadTapeScans(const char* filename = "kit_f_scan_troll
return scans;
}
std::vector<RecordedScan> loadTapeScans(const char* filename = "kit_f_scan_trolley_tape.txt")
{
return loadTapeScans(std::string(DOCK_PATTERN_DETECTOR_TEST_DATA_DIR) + "/" + filename);
}
const RecordedScan& scanNamed(const std::vector<RecordedScan>& scans, const std::string& name)
{
for (const RecordedScan& s : scans)
@@ -185,11 +193,13 @@ LegProfile mirrorTapeTrolley(bool enable_fixes = true,
}
LegDetection detectMirrorTape(const RecordedScan& scan, bool enable_fixes = true,
TapeLegs tape_legs = TapeLegs::kEntry)
TapeLegs tape_legs = TapeLegs::kEntry, double plateau_fraction = 0.0)
{
LegPatternMatcher matcher;
std::string error;
EXPECT_TRUE(matcher.configure(mirrorTapeTrolley(enable_fixes, tape_legs), error)) << error;
LegProfile profile = mirrorTapeTrolley(enable_fixes, tape_legs);
profile.tape_plateau_min_fraction = plateau_fraction;
EXPECT_TRUE(matcher.configure(profile, error)) << error;
ScanLimits limits;
limits.min_range = 0.10;
limits.max_range = 3.0;
@@ -376,13 +386,73 @@ TEST(LegPatternMatcherKit, BiasCorrectsMeasuredDepthOnFourLegScans)
for (const char* name : { "near_both_taped_4legs", "far_both_taped_4legs" })
{
const RecordedScan& scan = scanNamed(scans, name);
const LegDetection detection = detectMirrorTape(scan);
ASSERT_TRUE(detection.valid) << name << ": " << detection.reason;
ASSERT_EQ(detection.legs_seen, 4) << name;
EXPECT_TRUE(detection.tape_range_bias_estimated) << name;
EXPECT_GE(detection.tape_range_bias, 0.005) << name;
EXPECT_LE(detection.tape_range_bias, 0.045) << name;
EXPECT_NEAR(detection.measured_depth, 0.480, 0.015) << name;
for (double fraction : { 0.0, 0.65 })
{
const LegDetection detection = detectMirrorTape(scan, true, TapeLegs::kEntry, fraction);
ASSERT_TRUE(detection.valid) << name << ": " << detection.reason;
ASSERT_EQ(detection.legs_seen, 4) << name;
EXPECT_TRUE(detection.tape_range_bias_estimated) << name;
EXPECT_GE(detection.tape_range_bias, 0.005) << name;
EXPECT_LE(detection.tape_range_bias, 0.045) << name;
EXPECT_NEAR(detection.measured_depth, 0.480, 0.015) << name;
}
}
}
TEST(LegPatternMatcherKit, ObliquePlateauRescuesRealLegAndPreservesBloomRejection)
{
const auto scans = loadTapeScans("kit_f_scan_trolley_tape_oblique.txt");
ASSERT_EQ(scans.size(), 10u);
std::size_t failed_cases = 0, bloom_cases = 0;
for (const RecordedScan& scan : scans)
{
ASSERT_EQ(scan.ranges.size(), scan.geometry.size) << scan.name;
ASSERT_EQ(scan.intensities.size(), scan.geometry.size) << scan.name;
const LegDetection baseline = detectMirrorTape(scan, true, TapeLegs::kAll);
const LegDetection plateau = detectMirrorTape(scan, true, TapeLegs::kAll, 0.65);
if (scan.name.rfind("oblique_el_fail_", 0) == 0)
{
++failed_cases;
EXPECT_FALSE(baseline.valid) << scan.name;
EXPECT_LT(baseline.legs_seen, 3) << scan.name;
ASSERT_TRUE(plateau.valid) << scan.name << ": " << plateau.reason;
EXPECT_GE(plateau.legs_seen, 3) << scan.name;
EXPECT_LE(std::hypot(plateau.center_x - scan.ref_x, plateau.center_y - scan.ref_y), 0.04)
<< scan.name;
EXPECT_LE(yawError(plateau.center_yaw, scan.ref_yaw), 0.06) << scan.name;
EXPECT_NEAR(plateau.measured_opening, 0.762, 0.04) << scan.name;
EXPECT_NEAR(plateau.measured_depth, 0.480, 0.04) << scan.name;
}
else
{
ASSERT_EQ(scan.name.rfind("bloom_fl_ok_", 0), 0u) << scan.name;
++bloom_cases;
ASSERT_TRUE(baseline.valid) << scan.name << ": " << baseline.reason;
ASSERT_TRUE(plateau.valid) << scan.name << ": " << plateau.reason;
EXPECT_EQ(plateau.legs_seen, baseline.legs_seen) << scan.name;
EXPECT_EQ(plateau.tape_bright_rays, baseline.tape_bright_rays) << scan.name;
EXPECT_EQ(plateau.tape_bright_rays[dock_pattern_detector::kFarLeft], 0u) << scan.name;
EXPECT_NEAR(plateau.center_x, baseline.center_x, 1e-9) << scan.name;
EXPECT_NEAR(plateau.center_y, baseline.center_y, 1e-9) << scan.name;
EXPECT_NEAR(plateau.center_yaw, baseline.center_yaw, 1e-9) << scan.name;
}
}
EXPECT_EQ(failed_cases, 6u);
EXPECT_EQ(bloom_cases, 4u);
}
TEST(LegPatternMatcherKit, MirrorTapeReferencesStillHoldWithPlateau)
{
const auto scans = loadTapeScans();
ASSERT_FALSE(scans.empty());
for (const RecordedScan& scan : scans)
{
const LegDetection detection = detectMirrorTape(scan, true, TapeLegs::kEntry, 0.65);
ASSERT_TRUE(detection.valid) << scan.name << ": " << detection.reason;
EXPECT_GE(detection.legs_seen, 3) << scan.name;
EXPECT_LE(std::hypot(detection.center_x - scan.ref_x, detection.center_y - scan.ref_y), 0.03)
<< scan.name;
EXPECT_LT(yawError(detection.center_yaw, scan.ref_yaw), 2.0 * kDeg) << scan.name;
}
}
@@ -392,8 +462,14 @@ TEST(LegPatternMatcherKit, RejectsFarBrightCoreCorruptedByNearMirrorBloom)
ASSERT_EQ(scans.size(), 2u);
for (const RecordedScan& scan : scans)
{
const LegDetection detection = detectMirrorTape(scan, true, TapeLegs::kAll);
const LegDetection baseline = detectMirrorTape(scan, true, TapeLegs::kAll);
const LegDetection detection = detectMirrorTape(scan, true, TapeLegs::kAll, 0.65);
ASSERT_TRUE(baseline.valid) << scan.name << ": " << baseline.reason;
ASSERT_TRUE(detection.valid) << scan.name << ": " << detection.reason;
EXPECT_EQ(detection.tape_bright_rays, baseline.tape_bright_rays) << scan.name;
EXPECT_NEAR(detection.center_x, baseline.center_x, 1e-9) << scan.name;
EXPECT_NEAR(detection.center_y, baseline.center_y, 1e-9) << scan.name;
EXPECT_NEAR(detection.center_yaw, baseline.center_yaw, 1e-9) << scan.name;
EXPECT_EQ(detection.legs_seen, 3) << scan.name;
EXPECT_LE(std::hypot(detection.center_x - scan.ref_x, detection.center_y - scan.ref_y), 0.03)
<< scan.name;
@@ -402,6 +478,101 @@ TEST(LegPatternMatcherKit, RejectsFarBrightCoreCorruptedByNearMirrorBloom)
}
}
TEST(LegPatternMatcherKitReplay, BagReplayComparesPlateauOnAndOff)
{
const char* files_env = std::getenv("LEG_REPLAY_FILES");
if (files_env == nullptr || *files_env == '\0')
{
GTEST_SKIP() << "Set LEG_REPLAY_FILES and LEG_REPLAY_OUT to replay recorded scans.";
}
const char* output_path = std::getenv("LEG_REPLAY_OUT");
ASSERT_TRUE(output_path != nullptr && *output_path != '\0')
<< "LEG_REPLAY_OUT is required when LEG_REPLAY_FILES is set";
std::ofstream csv(output_path);
ASSERT_TRUE(csv.is_open()) << "Cannot open LEG_REPLAY_OUT: " << output_path;
csv << "label,stamp,config,valid,legs_seen,center_x,center_y,center_yaw,"
"measured_opening,measured_depth,bias_estimated,bias,reason\n";
csv << std::fixed << std::setprecision(6);
const auto csvSafe = [](std::string text) {
for (char& c : text)
{
if (c == ',' || c == '"' || c == '\n' || c == '\r')
{
c = ' ';
}
}
return text;
};
std::istringstream entries(files_env);
std::string entry;
while (std::getline(entries, entry, ','))
{
const std::size_t first = entry.find(':');
const std::size_t second = first == std::string::npos ? first : entry.find(':', first + 1);
ASSERT_TRUE(first != std::string::npos && first > 0 && second != std::string::npos &&
second + 1 < entry.size())
<< "LEG_REPLAY_FILES entry must be label:all|entry:absolute_path: " << entry;
const std::string label = entry.substr(0, first);
const std::string tape_name = entry.substr(first + 1, second - first - 1);
const std::string path = entry.substr(second + 1);
ASSERT_TRUE(tape_name == "all" || tape_name == "entry") << "Invalid tape_legs: " << tape_name;
ASSERT_EQ(path.front(), '/') << "Replay path must be absolute: " << path;
const TapeLegs tape_legs = tape_name == "all" ? TapeLegs::kAll : TapeLegs::kEntry;
std::ifstream input(path);
ASSERT_TRUE(input.is_open()) << "Cannot open replay file: " << path;
input.close();
const std::vector<RecordedScan> scans = loadTapeScans(path);
ASSERT_FALSE(scans.empty()) << "No scans loaded from " << path;
std::size_t valid_a = 0, valid_b = 0, only_b = 0, only_a = 0, changed = 0;
double max_dxy = 0.0, max_dyaw = 0.0;
for (const RecordedScan& scan : scans)
{
ASSERT_EQ(scan.ranges.size(), scan.geometry.size) << path << ": " << scan.name;
ASSERT_EQ(scan.intensities.size(), scan.geometry.size) << path << ": " << scan.name;
const std::size_t separator = scan.name.rfind('_');
ASSERT_NE(separator, std::string::npos) << "Missing timestamp in scan name: " << scan.name;
const std::string stamp_text = scan.name.substr(separator + 1);
char* stamp_end = nullptr;
const double stamp = std::strtod(stamp_text.c_str(), &stamp_end);
ASSERT_TRUE(stamp_end != stamp_text.c_str() && *stamp_end == '\0' && std::isfinite(stamp))
<< "Invalid timestamp in scan name: " << scan.name;
// detectMirrorTape configures a fresh matcher and the robot limits for each call.
const LegDetection a = detectMirrorTape(scan, true, tape_legs, 0.0);
const LegDetection b = detectMirrorTape(scan, true, tape_legs, 0.65);
const auto writeRow = [&](const char* config, const LegDetection& detection) {
csv << csvSafe(label) << ',' << stamp << ',' << config << ',' << detection.valid << ','
<< detection.legs_seen << ',' << detection.center_x << ',' << detection.center_y << ','
<< detection.center_yaw << ',' << detection.measured_opening << ','
<< detection.measured_depth << ',' << detection.tape_range_bias_estimated << ','
<< detection.tape_range_bias << ',' << csvSafe(detection.reason) << '\n';
};
writeRow("A", a);
writeRow("B", b);
valid_a += a.valid;
valid_b += b.valid;
only_a += a.valid && !b.valid;
only_b += b.valid && !a.valid;
if (a.valid && b.valid)
{
const double dxy = std::hypot(a.center_x - b.center_x, a.center_y - b.center_y);
const double dyaw = yawError(a.center_yaw, b.center_yaw);
changed += dxy > 1e-9 || dyaw > 1e-9;
max_dxy = std::max(max_dxy, dxy);
max_dyaw = std::max(max_dyaw, dyaw);
}
}
std::cout << label << ": scans=" << scans.size() << " valid A=" << valid_a
<< " valid B=" << valid_b << " only B=" << only_b << " only A=" << only_a
<< " both valid with pose changed=" << changed << std::fixed << std::setprecision(12)
<< " max |dxy|=" << max_dxy << " max |dyaw|=" << max_dyaw << std::endl;
}
csv.flush();
ASSERT_TRUE(csv.good()) << "Could not write replay CSV: " << output_path;
}
} // namespace
int main(int argc, char** argv)

View File

@@ -868,6 +868,68 @@ TEST(LegProfile, TapeBloomAndRangeBiasRequireTapeAndValidRanges)
EXPECT_TRUE(p.validate(error)) << error;
}
TEST(LegProfile, TapePlateauRequiresValidFractionAndBloom)
{
std::string error;
LegProfile p = reflectiveTrolley();
for (double value : { -0.01, 1.0, std::numeric_limits<double>::quiet_NaN() })
{
p.tape_plateau_min_fraction = value;
EXPECT_FALSE(p.validate(error)) << value;
EXPECT_NE(error.find("tape_plateau_min_fraction"), std::string::npos);
}
p = tciTrolley();
p.tape_plateau_min_fraction = 0.65;
EXPECT_FALSE(p.validate(error));
p = reflectiveTrolley();
p.tape_bloom_max_angle = 0.0;
p.tape_plateau_min_fraction = 0.65;
EXPECT_FALSE(p.validate(error));
p.tape_plateau_min_fraction = 0.0;
EXPECT_TRUE(p.validate(error)) << error;
p = tciTrolley();
EXPECT_TRUE(p.validate(error)) << error;
p = reflectiveTrolley();
p.tape_plateau_min_fraction = 0.65;
EXPECT_TRUE(p.validate(error)) << error;
}
TEST(LegPatternMatcher, PlateauRescuesEdgeRampButRejectsSlopeAndShortPlateau)
{
LegProfile p = reflectiveTrolley();
p.tape_legs = TapeLegs::kAll;
p.tape_plateau_min_fraction = 0.65;
p.leg_width_tolerance = 0.02;
p.shadow_min_angle = 0.0;
robot_line_extraction::ScanGeometry geometry;
geometry.angle_min = -0.1;
geometry.angle_increment = 0.004;
geometry.size = 50;
const auto run = [&](const std::vector<double>& values, std::size_t min_points, double fraction) {
LegProfile profile = p;
profile.tape_min_points = min_points;
profile.tape_plateau_min_fraction = fraction;
leg_scan_sim::Scan scan;
scan.ranges.assign(geometry.size, std::numeric_limits<double>::infinity());
scan.intensities.assign(geometry.size, 0.0f);
for (std::size_t i = 0; i < values.size(); ++i)
{
scan.ranges[10 + i] = values[i];
scan.intensities[10 + i] = 2000.0f;
}
return matchScan(profile, geometry, scan);
};
const LegDetection rescued = run({1.060, 1.035, 1.010, 1.005, 1.000, 1.004, 1.006, 1.008, 1.010, 1.009}, 2, 0.65);
EXPECT_EQ(rescued.leg_candidates, 1u) << rescued.reason;
EXPECT_NE(rescued.reason.find("1 bright core(s) kept by their plateau"), std::string::npos);
const LegDetection sloped = run({1.000, 1.015, 1.030, 1.045, 1.060}, 2, 0.65);
EXPECT_EQ(sloped.leg_candidates, 0u) << sloped.reason;
EXPECT_NE(sloped.reason.find("1 bright core(s) spread"), std::string::npos);
const LegDetection short_plateau = run({1.000, 1.004, 1.030, 1.055}, 3, 0.4);
EXPECT_EQ(short_plateau.leg_candidates, 0u) << short_plateau.reason;
EXPECT_NE(short_plateau.reason.find("1 bright core(s) spread"), std::string::npos);
}
TEST(LegPatternMatcher, MatchBeforeConfigureSaysSo)
{
LegPatternMatcher matcher;