fix(leg_profile): ignore tuned tape keys when tape_enabled is false instead of rejecting the profile
This commit is contained in:
@@ -167,6 +167,11 @@ biến) → cổng prior → từ chối khi hai xe điểm sát nhau ở hai ch
|
|||||||
|
|
||||||
### Lõi phản quang bị loang và bias cự ly
|
### Lõi phản quang bị loang và bias cự ly
|
||||||
|
|
||||||
|
Khi `tape_enabled: false`, bốn khoá `tape_bloom_max_angle`, `tape_range_bias_sigma`,
|
||||||
|
`tape_plateau_min_fraction` và `tape_range_bias_all_max_std` bị bỏ qua; handler liệt kê giá trị khác
|
||||||
|
0 trong cảnh báo lúc boot, nên có thể giữ giá trị đã chỉnh khi tháo dải. Miền giá trị vẫn được kiểm
|
||||||
|
tra. `tape_legs: entry` vẫn bị từ chối khi tape tắt vì nó xác định cạnh vào.
|
||||||
|
|
||||||
Mặc định `tape_bloom_max_angle: 0` giữ nguyên hoàn toàn đường phân cụm hình học. Khi bật dải và đặt
|
Mặc định `tape_bloom_max_angle: 0` giữ nguyên hoàn toàn đường phân cụm hình học. Khi bật dải và đặt
|
||||||
góc dương, matcher tìm các run tia sáng trước, đi ra ngoài lõi tối đa góc này để nhận diện vệt
|
góc dương, matcher tìm các run tia sáng trước, đi ra ngoài lõi tối đa góc này để nhận diện vệt
|
||||||
`bloom`, rồi loại lõi và vệt khỏi phân cụm hình học. Chỉ điểm lõi đi vào candidate; hai mép vẫn được
|
`bloom`, rồi loại lõi và vệt khỏi phân cụm hình học. Chỉ điểm lõi đi vào candidate; hai mép vẫn được
|
||||||
|
|||||||
@@ -244,6 +244,9 @@ struct LegProfile
|
|||||||
* mãi không ra", nhìn giống hệt xe không có trong tầm.
|
* mãi không ra", nhìn giống hệt xe không có trong tầm.
|
||||||
*/
|
*/
|
||||||
bool validate(std::string& error) const;
|
bool validate(std::string& error) const;
|
||||||
|
|
||||||
|
/// @brief Liệt kê các giá trị tape khác 0 bị bỏ qua khi tape tắt; rỗng nếu không có.
|
||||||
|
std::string ignoredTapeKeys() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dock_pattern_detector
|
} // namespace dock_pattern_detector
|
||||||
|
|||||||
@@ -595,7 +595,8 @@ std::string LegPatternMatcher::describeClusterRejections() const
|
|||||||
format("%.3f", profile_.maxApparentLegWidth()) +
|
format("%.3f", profile_.maxApparentLegWidth()) +
|
||||||
" m in range (bloom from a nearer mirror)";
|
" m in range (bloom from a nearer mirror)";
|
||||||
}
|
}
|
||||||
if (profile_.tape_plateau_min_fraction > 0.0)
|
if (profile_.tape_enabled && profile_.tape_bloom_max_angle > 0.0 &&
|
||||||
|
profile_.tape_plateau_min_fraction > 0.0)
|
||||||
{
|
{
|
||||||
text += ", " + std::to_string(rescued_tape_plateau_) + " bright core(s) kept by their plateau";
|
text += ", " + std::to_string(rescued_tape_plateau_) + " bright core(s) kept by their plateau";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#include <dock_pattern_detector/leg_profile.h>
|
#include <dock_pattern_detector/leg_profile.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace dock_pattern_detector
|
namespace dock_pattern_detector
|
||||||
@@ -206,7 +208,7 @@ bool LegProfile::validate(std::string& error) const
|
|||||||
error = "tape_range_bias_all_max_std must be finite and in [0, 0.1] [m]";
|
error = "tape_range_bias_all_max_std must be finite and in [0, 0.1] [m]";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (tape_range_bias_all_max_std > 0.0 && (!tape_enabled || tape_range_bias_sigma <= 0.0))
|
if (tape_enabled && tape_range_bias_all_max_std > 0.0 && tape_range_bias_sigma <= 0.0)
|
||||||
{
|
{
|
||||||
error = "non-zero tape_range_bias_all_max_std requires tape_enabled: true and "
|
error = "non-zero tape_range_bias_all_max_std requires tape_enabled: true and "
|
||||||
"tape_range_bias_sigma > 0";
|
"tape_range_bias_sigma > 0";
|
||||||
@@ -218,17 +220,12 @@ bool LegProfile::validate(std::string& error) const
|
|||||||
error = "tape_plateau_min_fraction must be finite and in [0, 1)";
|
error = "tape_plateau_min_fraction must be finite and in [0, 1)";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (tape_plateau_min_fraction > 0.0 && (!tape_enabled || tape_bloom_max_angle <= 0.0))
|
if (tape_enabled && tape_plateau_min_fraction > 0.0 && tape_bloom_max_angle <= 0.0)
|
||||||
{
|
{
|
||||||
error = "non-zero tape_plateau_min_fraction requires tape_enabled: true and "
|
error = "non-zero tape_plateau_min_fraction requires tape_enabled: true and "
|
||||||
"tape_bloom_max_angle > 0";
|
"tape_bloom_max_angle > 0";
|
||||||
return false;
|
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";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (std::fabs(cart_opening - cart_depth) < 2.0 * cart_dim_tolerance)
|
if (std::fabs(cart_opening - cart_depth) < 2.0 * cart_dim_tolerance)
|
||||||
{
|
{
|
||||||
// Xe gần vuông: hình học không biết cạnh nào là cạnh vào. Dò ra cạnh bên là robot chui ngang
|
// Xe gần vuông: hình học không biết cạnh nào là cạnh vào. Dò ra cạnh bên là robot chui ngang
|
||||||
@@ -275,4 +272,29 @@ bool LegProfile::validate(std::string& error) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string LegProfile::ignoredTapeKeys() const
|
||||||
|
{
|
||||||
|
if (tape_enabled)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
std::ostringstream out;
|
||||||
|
out << std::fixed << std::setprecision(3);
|
||||||
|
const auto append = [&out](const char* name, double value) {
|
||||||
|
if (value != 0.0)
|
||||||
|
{
|
||||||
|
if (out.tellp() > 0)
|
||||||
|
{
|
||||||
|
out << ", ";
|
||||||
|
}
|
||||||
|
out << name << " " << value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
append("tape_bloom_max_angle", tape_bloom_max_angle);
|
||||||
|
append("tape_range_bias_sigma", tape_range_bias_sigma);
|
||||||
|
append("tape_plateau_min_fraction", tape_plateau_min_fraction);
|
||||||
|
append("tape_range_bias_all_max_std", tape_range_bias_all_max_std);
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dock_pattern_detector
|
} // namespace dock_pattern_detector
|
||||||
|
|||||||
@@ -331,6 +331,41 @@ TEST(LegPatternMatcherKit, EveryUntapedOcclusionScanKeepsLegacyResults)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(LegPatternMatcherKit, TapeOffTunedKeysMatchZeroKeysOnEveryOcclusionScan)
|
||||||
|
{
|
||||||
|
const std::vector<RecordedScan> scans = loadScans();
|
||||||
|
ASSERT_EQ(scans.size(), 6u);
|
||||||
|
LegProfile zero = kitTrolley(true);
|
||||||
|
LegProfile tuned = zero;
|
||||||
|
tuned.tape_bloom_max_angle = 0.10;
|
||||||
|
tuned.tape_range_bias_sigma = 0.05;
|
||||||
|
tuned.tape_plateau_min_fraction = 0.65;
|
||||||
|
tuned.tape_range_bias_all_max_std = 0.02;
|
||||||
|
LegPatternMatcher zero_matcher, tuned_matcher;
|
||||||
|
std::string error;
|
||||||
|
ASSERT_TRUE(zero_matcher.configure(zero, error)) << error;
|
||||||
|
ASSERT_TRUE(tuned_matcher.configure(tuned, 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;
|
||||||
|
for (const RecordedScan& scan : scans)
|
||||||
|
{
|
||||||
|
SCOPED_TRACE(scan.name);
|
||||||
|
const LegDetection a = zero_matcher.match(scan.geometry, scan.ranges, {}, limits, Pose2D());
|
||||||
|
const LegDetection b = tuned_matcher.match(scan.geometry, scan.ranges, {}, limits, Pose2D());
|
||||||
|
EXPECT_EQ(a.valid, b.valid);
|
||||||
|
EXPECT_EQ(a.legs_seen, b.legs_seen);
|
||||||
|
EXPECT_NEAR(a.x, b.x, 1e-12);
|
||||||
|
EXPECT_NEAR(a.y, b.y, 1e-12);
|
||||||
|
EXPECT_NEAR(a.yaw, b.yaw, 1e-12);
|
||||||
|
EXPECT_NEAR(a.center_x, b.center_x, 1e-12);
|
||||||
|
EXPECT_NEAR(a.center_y, b.center_y, 1e-12);
|
||||||
|
EXPECT_NEAR(a.center_yaw, b.center_yaw, 1e-12);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST(LegPatternMatcherKit, MirrorTapeDataFileLoadsRangesAndIntensities)
|
TEST(LegPatternMatcherKit, MirrorTapeDataFileLoadsRangesAndIntensities)
|
||||||
{
|
{
|
||||||
const std::vector<RecordedScan> scans = loadTapeScans();
|
const std::vector<RecordedScan> scans = loadTapeScans();
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ TEST(LegProfile, ValidatesAllBrightBiasThreshold)
|
|||||||
EXPECT_FALSE(p.validate(error));
|
EXPECT_FALSE(p.validate(error));
|
||||||
}
|
}
|
||||||
p.tape_range_bias_all_max_std = 0.02;
|
p.tape_range_bias_all_max_std = 0.02;
|
||||||
EXPECT_FALSE(p.validate(error));
|
EXPECT_TRUE(p.validate(error)) << error;
|
||||||
p.tape_enabled = true;
|
p.tape_enabled = true;
|
||||||
EXPECT_FALSE(p.validate(error));
|
EXPECT_FALSE(p.validate(error));
|
||||||
p.tape_range_bias_sigma = 0.05;
|
p.tape_range_bias_sigma = 0.05;
|
||||||
@@ -869,12 +869,12 @@ TEST(LegProfile, ValidateRefusesBrokenProfiles)
|
|||||||
EXPECT_FALSE(p.validate(error));
|
EXPECT_FALSE(p.validate(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LegProfile, TapeBloomAndRangeBiasRequireTapeAndValidRanges)
|
TEST(LegProfile, TapeBloomAndRangeBiasRequireValidRanges)
|
||||||
{
|
{
|
||||||
std::string error;
|
std::string error;
|
||||||
LegProfile p = tciTrolley();
|
LegProfile p = tciTrolley();
|
||||||
p.tape_bloom_max_angle = 0.10;
|
p.tape_bloom_max_angle = 0.10;
|
||||||
EXPECT_FALSE(p.validate(error));
|
EXPECT_TRUE(p.validate(error)) << error;
|
||||||
|
|
||||||
p = reflectiveTrolley();
|
p = reflectiveTrolley();
|
||||||
p.tape_bloom_max_angle = 0.5;
|
p.tape_bloom_max_angle = 0.5;
|
||||||
@@ -902,7 +902,7 @@ TEST(LegProfile, TapePlateauRequiresValidFractionAndBloom)
|
|||||||
}
|
}
|
||||||
p = tciTrolley();
|
p = tciTrolley();
|
||||||
p.tape_plateau_min_fraction = 0.65;
|
p.tape_plateau_min_fraction = 0.65;
|
||||||
EXPECT_FALSE(p.validate(error));
|
EXPECT_TRUE(p.validate(error)) << error;
|
||||||
p = reflectiveTrolley();
|
p = reflectiveTrolley();
|
||||||
p.tape_bloom_max_angle = 0.0;
|
p.tape_bloom_max_angle = 0.0;
|
||||||
p.tape_plateau_min_fraction = 0.65;
|
p.tape_plateau_min_fraction = 0.65;
|
||||||
@@ -916,6 +916,55 @@ TEST(LegProfile, TapePlateauRequiresValidFractionAndBloom)
|
|||||||
EXPECT_TRUE(p.validate(error)) << error;
|
EXPECT_TRUE(p.validate(error)) << error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(LegProfile, TapeOffIgnoresTunedKeysButStillRejectsEntryTape)
|
||||||
|
{
|
||||||
|
LegProfile p = tciTrolley();
|
||||||
|
std::string error;
|
||||||
|
EXPECT_TRUE(p.ignoredTapeKeys().empty());
|
||||||
|
p.tape_bloom_max_angle = 0.10;
|
||||||
|
p.tape_range_bias_sigma = 0.05;
|
||||||
|
p.tape_plateau_min_fraction = 0.65;
|
||||||
|
p.tape_range_bias_all_max_std = 0.02;
|
||||||
|
ASSERT_TRUE(p.validate(error)) << error;
|
||||||
|
EXPECT_EQ(p.ignoredTapeKeys(), "tape_bloom_max_angle 0.100, tape_range_bias_sigma 0.050, "
|
||||||
|
"tape_plateau_min_fraction 0.650, tape_range_bias_all_max_std 0.020");
|
||||||
|
p.tape_enabled = true;
|
||||||
|
EXPECT_TRUE(p.validate(error)) << error;
|
||||||
|
EXPECT_TRUE(p.ignoredTapeKeys().empty());
|
||||||
|
p.tape_enabled = false;
|
||||||
|
p.tape_legs = TapeLegs::kEntry;
|
||||||
|
EXPECT_FALSE(p.validate(error));
|
||||||
|
EXPECT_EQ(error, "tape_legs 'entry' requires tape_enabled: true (forgot to turn the tape on?)");
|
||||||
|
p.tape_legs = TapeLegs::kAll;
|
||||||
|
p.tape_bloom_max_angle = 0.0;
|
||||||
|
p.tape_plateau_min_fraction = 0.0;
|
||||||
|
p.tape_range_bias_all_max_std = 0.0;
|
||||||
|
EXPECT_EQ(p.ignoredTapeKeys(), "tape_range_bias_sigma 0.050");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(LegProfile, TapeKeyRangesAreCheckedEvenWhenTapeIsOff)
|
||||||
|
{
|
||||||
|
std::string error;
|
||||||
|
const double nan = std::numeric_limits<double>::quiet_NaN();
|
||||||
|
const double inf = std::numeric_limits<double>::infinity();
|
||||||
|
for (bool enabled : { false, true })
|
||||||
|
{
|
||||||
|
for (const auto& test : { std::pair<double LegProfile::*, double>{ &LegProfile::tape_bloom_max_angle, 0.5 },
|
||||||
|
{ &LegProfile::tape_range_bias_sigma, 0.201 },
|
||||||
|
{ &LegProfile::tape_plateau_min_fraction, 1.0 },
|
||||||
|
{ &LegProfile::tape_range_bias_all_max_std, 0.101 } })
|
||||||
|
{
|
||||||
|
for (double value : { -0.01, test.second, nan, inf })
|
||||||
|
{
|
||||||
|
LegProfile p = tciTrolley();
|
||||||
|
p.tape_enabled = enabled;
|
||||||
|
p.*test.first = value;
|
||||||
|
EXPECT_FALSE(p.validate(error)) << "tape_enabled=" << enabled << ", value=" << value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST(LegPatternMatcher, PlateauRescuesEdgeRampButRejectsSlopeAndShortPlateau)
|
TEST(LegPatternMatcher, PlateauRescuesEdgeRampButRejectsSlopeAndShortPlateau)
|
||||||
{
|
{
|
||||||
LegProfile p = reflectiveTrolley();
|
LegProfile p = reflectiveTrolley();
|
||||||
|
|||||||
Reference in New Issue
Block a user