fix(leg_pattern): segment mirror-taped legs by intensity and estimate their range bias
Mirror tape on the KIT lidar blooms: a taped leg returns a saturated core plus a skirt of dim rays whose range climbs smoothly to the background. Clustering by geometry first made taped legs attached (no depth jump at the edge) or too wide for the width gate, so the robot found the cart in 6 of 227 scans at 1.2 m. The saturated core also reads 1-3 cm short. All changes sit behind tape_enabled plus their own key; with the keys at 0 or tape off the detector runs exactly as before. - tape_bloom_max_angle [rad]: bright runs become leg candidates before geometric clustering. The bloom skirt is walked and masked, and the edge class comes from the walk. A bright core spread over more than the leg's apparent width in range is rejected: it is a leg corrupted by a nearer mirror's bloom. - tape_range_bias_sigma [m]: the pose fit estimates one common range bias for bright points (x, y, yaw, b) with a Gaussian prior. This only happens when at least one bare leg anchors the range; otherwise the 3-DoF fit is unchanged. |b| > 0.1 m invalidates the fit. Pair spacing and measured dimensions use bias-corrected leg centres. - Real KIT scans with intensities: 9 from the 2-leg-taped run (11:06) and 2 with all four legs taped (12:12).
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <dock_pattern_detector/leg_pattern_matcher.h>
|
||||
@@ -30,6 +31,7 @@ using dock_pattern_detector::LegProfile;
|
||||
using dock_pattern_detector::LegShape;
|
||||
using dock_pattern_detector::Pose2D;
|
||||
using dock_pattern_detector::ScanLimits;
|
||||
using dock_pattern_detector::TapeLegs;
|
||||
|
||||
constexpr double kDeg = M_PI / 180.0;
|
||||
|
||||
@@ -38,6 +40,7 @@ struct RecordedScan
|
||||
std::string name;
|
||||
robot_line_extraction::ScanGeometry geometry;
|
||||
std::vector<double> ranges;
|
||||
std::vector<float> intensities;
|
||||
double ref_x = 0.0; // [m]
|
||||
double ref_y = 0.0; // [m]
|
||||
double ref_yaw = 0.0; // [rad]
|
||||
@@ -75,6 +78,48 @@ std::vector<RecordedScan> loadScans()
|
||||
return scans;
|
||||
}
|
||||
|
||||
std::vector<RecordedScan> loadTapeScans(const char* filename = "kit_f_scan_trolley_tape.txt")
|
||||
{
|
||||
std::vector<RecordedScan> scans;
|
||||
std::ifstream in(std::string(DOCK_PATTERN_DETECTOR_TEST_DATA_DIR) +
|
||||
"/" + filename);
|
||||
std::string line;
|
||||
while (std::getline(in, line))
|
||||
{
|
||||
if (line.empty() || line[0] == '#')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
std::istringstream header(line);
|
||||
std::string tag;
|
||||
RecordedScan scan;
|
||||
header >> tag >> scan.name >> scan.geometry.angle_min >> scan.geometry.angle_increment >>
|
||||
scan.geometry.size >> scan.ref_x >> scan.ref_y >> scan.ref_yaw;
|
||||
if (tag != "scan" || !std::getline(in, line))
|
||||
{
|
||||
break;
|
||||
}
|
||||
std::istringstream range_values(line);
|
||||
double range = 0.0;
|
||||
while (range_values >> range)
|
||||
{
|
||||
scan.ranges.push_back(range);
|
||||
}
|
||||
if (!std::getline(in, line))
|
||||
{
|
||||
break;
|
||||
}
|
||||
std::istringstream intensity_values(line);
|
||||
float intensity = 0.0f;
|
||||
while (intensity_values >> intensity)
|
||||
{
|
||||
scan.intensities.push_back(intensity);
|
||||
}
|
||||
scans.push_back(std::move(scan));
|
||||
}
|
||||
return scans;
|
||||
}
|
||||
|
||||
const RecordedScan& scanNamed(const std::vector<RecordedScan>& scans, const std::string& name)
|
||||
{
|
||||
for (const RecordedScan& s : scans)
|
||||
@@ -117,6 +162,42 @@ LegDetection detect(const RecordedScan& s, bool accept_attached_legs, bool zero_
|
||||
return matcher.match(s.geometry, s.ranges, {}, limits, Pose2D());
|
||||
}
|
||||
|
||||
LegProfile mirrorTapeTrolley(bool enable_fixes = true,
|
||||
TapeLegs tape_legs = TapeLegs::kEntry)
|
||||
{
|
||||
LegProfile p;
|
||||
p.cart_opening = 0.762;
|
||||
p.cart_depth = 0.480;
|
||||
p.cart_dim_tolerance = 0.04;
|
||||
p.leg_shape = LegShape::kBox;
|
||||
p.leg_width = 0.030;
|
||||
p.leg_width_tolerance = 0.02;
|
||||
p.min_legs = 3;
|
||||
p.accept_attached_legs = true;
|
||||
p.min_confidence = 0.5;
|
||||
p.tape_enabled = true;
|
||||
p.tape_legs = tape_legs;
|
||||
p.tape_min_intensity = 8000.0;
|
||||
p.tape_min_points = 2;
|
||||
p.tape_bloom_max_angle = enable_fixes ? 0.10 : 0.0;
|
||||
p.tape_range_bias_sigma = enable_fixes ? 0.05 : 0.0;
|
||||
return p;
|
||||
}
|
||||
|
||||
LegDetection detectMirrorTape(const RecordedScan& scan, bool enable_fixes = true,
|
||||
TapeLegs tape_legs = TapeLegs::kEntry)
|
||||
{
|
||||
LegPatternMatcher matcher;
|
||||
std::string error;
|
||||
EXPECT_TRUE(matcher.configure(mirrorTapeTrolley(enable_fixes, tape_legs), error)) << error;
|
||||
ScanLimits limits;
|
||||
limits.min_range = 0.10;
|
||||
limits.max_range = 3.0;
|
||||
limits.range_sigma = 0.01;
|
||||
limits.zero_range_is_no_echo = true;
|
||||
return matcher.match(scan.geometry, scan.ranges, scan.intensities, limits, Pose2D());
|
||||
}
|
||||
|
||||
double yawError(double a, double b)
|
||||
{
|
||||
return std::fabs(std::atan2(std::sin(a - b), std::cos(a - b)));
|
||||
@@ -200,6 +281,127 @@ TEST(LegPatternMatcherKit, ZeroRangeAsNoEchoClearsTheFalsePartialFlags)
|
||||
EXPECT_LT(no_echo.legs_partial, blocked.legs_partial);
|
||||
}
|
||||
|
||||
TEST(LegPatternMatcherKit, EveryUntapedOcclusionScanKeepsLegacyResults)
|
||||
{
|
||||
const std::vector<RecordedScan> scans = loadScans();
|
||||
ASSERT_EQ(scans.size(), 6u);
|
||||
for (const RecordedScan& scan : scans)
|
||||
{
|
||||
if (scan.name == "far_right_leg_beside_post")
|
||||
{
|
||||
const LegDetection blocked = detect(scan, false, false);
|
||||
ASSERT_TRUE(blocked.valid) << scan.name << ": " << blocked.reason;
|
||||
EXPECT_EQ(blocked.legs_seen, 4) << scan.name;
|
||||
EXPECT_NEAR(blocked.center_x, scan.ref_x, 0.02) << scan.name;
|
||||
EXPECT_NEAR(blocked.center_y, scan.ref_y, 0.02) << scan.name;
|
||||
EXPECT_LT(yawError(blocked.center_yaw, scan.ref_yaw), 1.5 * kDeg) << scan.name;
|
||||
EXPECT_EQ(blocked.legs_partial, 4) << scan.name;
|
||||
|
||||
const LegDetection no_echo = detect(scan, true, true);
|
||||
ASSERT_TRUE(no_echo.valid) << scan.name << ": " << no_echo.reason;
|
||||
EXPECT_EQ(no_echo.legs_seen, 4) << scan.name;
|
||||
EXPECT_NEAR(no_echo.center_x, scan.ref_x, 0.02) << scan.name;
|
||||
EXPECT_NEAR(no_echo.center_y, scan.ref_y, 0.02) << scan.name;
|
||||
EXPECT_LT(yawError(no_echo.center_yaw, scan.ref_yaw), 1.5 * kDeg) << scan.name;
|
||||
EXPECT_LT(no_echo.legs_partial, blocked.legs_partial) << scan.name;
|
||||
continue;
|
||||
}
|
||||
|
||||
EXPECT_FALSE(detect(scan, false, false).valid) << scan.name;
|
||||
const LegDetection attached = detect(scan, true, true);
|
||||
ASSERT_TRUE(attached.valid) << scan.name << ": " << attached.reason;
|
||||
EXPECT_EQ(attached.legs_seen, 3) << scan.name;
|
||||
EXPECT_EQ(attached.legs_attached, 1) << scan.name;
|
||||
EXPECT_EQ(attached.legs_occluded + attached.legs_distorted, 1) << scan.name;
|
||||
EXPECT_NEAR(attached.center_x, scan.ref_x, 0.02) << scan.name;
|
||||
EXPECT_NEAR(attached.center_y, scan.ref_y, 0.02) << scan.name;
|
||||
EXPECT_LT(yawError(attached.center_yaw, scan.ref_yaw), 1.5 * kDeg) << scan.name;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(LegPatternMatcherKit, MirrorTapeDataFileLoadsRangesAndIntensities)
|
||||
{
|
||||
const std::vector<RecordedScan> scans = loadTapeScans();
|
||||
ASSERT_FALSE(scans.empty());
|
||||
for (const RecordedScan& scan : scans)
|
||||
{
|
||||
EXPECT_EQ(scan.ranges.size(), scan.geometry.size) << scan.name;
|
||||
EXPECT_EQ(scan.intensities.size(), scan.geometry.size) << scan.name;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(LegPatternMatcherKit, EveryMirrorTapeScanMatchesItsReplayReference)
|
||||
{
|
||||
const std::vector<RecordedScan> scans = loadTapeScans();
|
||||
ASSERT_FALSE(scans.empty());
|
||||
for (const RecordedScan& scan : scans)
|
||||
{
|
||||
const LegDetection detection = detectMirrorTape(scan);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(LegPatternMatcherKit, OldMirrorTapePathStillFailsTheKnownBloomScans)
|
||||
{
|
||||
const std::vector<RecordedScan> scans = loadTapeScans();
|
||||
bool checked_m5 = false;
|
||||
bool checked_m7 = false;
|
||||
bool checked_m11 = false;
|
||||
for (const RecordedScan& scan : scans)
|
||||
{
|
||||
const bool regression_case = scan.name.rfind("m5_", 0) == 0 ||
|
||||
scan.name.rfind("m7_", 0) == 0 ||
|
||||
scan.name.rfind("m11_", 0) == 0;
|
||||
if (!regression_case)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
EXPECT_FALSE(detectMirrorTape(scan, false).valid) << scan.name;
|
||||
checked_m5 = checked_m5 || scan.name.rfind("m5_", 0) == 0;
|
||||
checked_m7 = checked_m7 || scan.name.rfind("m7_", 0) == 0;
|
||||
checked_m11 = checked_m11 || scan.name.rfind("m11_", 0) == 0;
|
||||
}
|
||||
EXPECT_TRUE(checked_m5);
|
||||
EXPECT_TRUE(checked_m7);
|
||||
EXPECT_TRUE(checked_m11);
|
||||
}
|
||||
|
||||
TEST(LegPatternMatcherKit, BiasCorrectsMeasuredDepthOnFourLegScans)
|
||||
{
|
||||
const std::vector<RecordedScan> scans = loadTapeScans();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(LegPatternMatcherKit, RejectsFarBrightCoreCorruptedByNearMirrorBloom)
|
||||
{
|
||||
const std::vector<RecordedScan> scans = loadTapeScans("kit_f_scan_trolley_tape_all4.txt");
|
||||
ASSERT_EQ(scans.size(), 2u);
|
||||
for (const RecordedScan& scan : scans)
|
||||
{
|
||||
const LegDetection detection = detectMirrorTape(scan, true, TapeLegs::kAll);
|
||||
ASSERT_TRUE(detection.valid) << scan.name << ": " << detection.reason;
|
||||
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;
|
||||
EXPECT_LT(yawError(detection.center_yaw, scan.ref_yaw), 2.0 * kDeg) << scan.name;
|
||||
EXPECT_FALSE(detection.tape_range_bias_estimated) << scan.name;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
||||
Reference in New Issue
Block a user