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).
255 lines
7.4 KiB
C++
255 lines
7.4 KiB
C++
/*********************************************************************
|
|
*
|
|
* Software License Agreement (BSD License)
|
|
*
|
|
* dock_pattern_detector — kiểm miền của LegProfile.
|
|
*
|
|
* Author: DuongTD
|
|
*********************************************************************/
|
|
#include <dock_pattern_detector/leg_profile.h>
|
|
|
|
#include <cmath>
|
|
#include <string>
|
|
|
|
namespace dock_pattern_detector
|
|
{
|
|
namespace
|
|
{
|
|
bool positiveFinite(double value)
|
|
{
|
|
return std::isfinite(value) && value > 0.0;
|
|
}
|
|
} // namespace
|
|
|
|
const char* toString(LegShape shape)
|
|
{
|
|
switch (shape)
|
|
{
|
|
case LegShape::kBox:
|
|
return "box";
|
|
case LegShape::kRound:
|
|
return "round";
|
|
}
|
|
return "unknown";
|
|
}
|
|
|
|
bool legShapeFromString(const std::string& name, LegShape& out, std::string& error)
|
|
{
|
|
if (name == "box")
|
|
{
|
|
out = LegShape::kBox;
|
|
return true;
|
|
}
|
|
if (name == "round")
|
|
{
|
|
out = LegShape::kRound;
|
|
return true;
|
|
}
|
|
error = "unknown leg_shape '" + name + "'; known values are: box, round";
|
|
return false;
|
|
}
|
|
|
|
const char* toString(TapeLegs legs)
|
|
{
|
|
switch (legs)
|
|
{
|
|
case TapeLegs::kAll:
|
|
return "all";
|
|
case TapeLegs::kEntry:
|
|
return "entry";
|
|
}
|
|
return "unknown";
|
|
}
|
|
|
|
bool tapeLegsFromString(const std::string& name, TapeLegs& out, std::string& error)
|
|
{
|
|
if (name == "all")
|
|
{
|
|
out = TapeLegs::kAll;
|
|
return true;
|
|
}
|
|
if (name == "entry")
|
|
{
|
|
out = TapeLegs::kEntry;
|
|
return true;
|
|
}
|
|
error = "unknown tape_legs '" + name + "'; known values are: all, entry";
|
|
return false;
|
|
}
|
|
|
|
bool LegProfile::validate(std::string& error) const
|
|
{
|
|
if (!positiveFinite(cart_opening) || !positiveFinite(cart_depth))
|
|
{
|
|
error = "cart_opening and cart_depth must be finite and > 0 [m] (both are required)";
|
|
return false;
|
|
}
|
|
if (!positiveFinite(leg_width))
|
|
{
|
|
error = "leg_width must be finite and > 0 [m] (it is required)";
|
|
return false;
|
|
}
|
|
if (cart_opening <= leg_width + 0.2)
|
|
{
|
|
// Khe lọt giữa hai chân cạnh vào dưới 0.2 m: không robot nào chui được. Gần như chắc là khai
|
|
// nhầm đơn vị (mm thay vì m) hoặc nhầm hai khoá.
|
|
error = "cart_opening must exceed leg_width + 0.2 m; nothing fits through a narrower opening "
|
|
"(wrong unit?)";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(cart_dim_tolerance) || cart_dim_tolerance <= 0.0 ||
|
|
cart_dim_tolerance >= std::min(cart_opening, cart_depth) / 4.0)
|
|
{
|
|
error = "cart_dim_tolerance must be > 0 and < min(cart_opening, cart_depth)/4 [m]";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(leg_width_tolerance) || leg_width_tolerance < 0.0)
|
|
{
|
|
error = "leg_width_tolerance must be finite and >= 0 [m]";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(leg_depth) || leg_depth < 0.0)
|
|
{
|
|
error = "leg_depth must be finite and >= 0 [m] (0 = same as leg_width)";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(leg_yaw_offset))
|
|
{
|
|
error = "leg_yaw_offset must be finite [rad]";
|
|
return false;
|
|
}
|
|
if (leg_shape == LegShape::kRound && (leg_depth > 0.0 || leg_yaw_offset != 0.0))
|
|
{
|
|
// Nói thẳng thay vì nhận rồi lờ đi: chân tròn không có bề dày riêng hay góc xoay.
|
|
error = "leg_depth and leg_yaw_offset only apply to leg_shape 'box'";
|
|
return false;
|
|
}
|
|
if (min_leg_points < 1)
|
|
{
|
|
error = "min_leg_points must be >= 1";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(shadow_min_angle) || shadow_min_angle < 0.0 ||
|
|
shadow_min_angle >= M_PI / 2.0)
|
|
{
|
|
error = "shadow_min_angle must be in [0, pi/2) [rad] (0 disables the shadow filter)";
|
|
return false;
|
|
}
|
|
if (!positiveFinite(leg_cluster_gap))
|
|
{
|
|
error = "leg_cluster_gap must be finite and > 0 [m]";
|
|
return false;
|
|
}
|
|
if (!positiveFinite(leg_min_depth_gap))
|
|
{
|
|
error = "leg_min_depth_gap must be finite and > 0 [m]";
|
|
return false;
|
|
}
|
|
if (min_legs < 2 || min_legs > 4)
|
|
{
|
|
error = "min_legs must be 2, 3 or 4";
|
|
return false;
|
|
}
|
|
if (min_legs == 2 && !has_prior)
|
|
{
|
|
// Hai chân có thể là cạnh vào, cạnh dọc hoặc đường chéo, mỗi loại hai phía. Không có prior thì
|
|
// không có gì chọn giữa các khả năng đó.
|
|
error = "min_legs 2 requires has_prior: two legs alone fit several cart poses";
|
|
return false;
|
|
}
|
|
if (!positiveFinite(leg_assoc_radius))
|
|
{
|
|
error = "leg_assoc_radius must be finite and > 0 [m]";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(interior_margin) || interior_margin < 0.0 ||
|
|
2.0 * interior_margin >= std::min(cart_opening, cart_depth))
|
|
{
|
|
error = "interior_margin must be >= 0 and leave a non-empty interior [m]";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(ambiguity_margin) || ambiguity_margin < 0.0 || ambiguity_margin >= 1.0)
|
|
{
|
|
error = "ambiguity_margin must be in [0, 1)";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(min_confidence) || min_confidence < 0.0 || min_confidence > 1.0)
|
|
{
|
|
error = "min_confidence must be in [0, 1]";
|
|
return false;
|
|
}
|
|
if (tape_legs == TapeLegs::kEntry && !tape_enabled)
|
|
{
|
|
error = "tape_legs 'entry' requires tape_enabled: true (forgot to turn the tape on?)";
|
|
return false;
|
|
}
|
|
if (tape_enabled && (!std::isfinite(tape_min_intensity) || tape_min_points < 1))
|
|
{
|
|
error = "tape_min_intensity must be finite and tape_min_points >= 1";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(tape_bloom_max_angle) || tape_bloom_max_angle < 0.0 ||
|
|
tape_bloom_max_angle >= 0.5)
|
|
{
|
|
error = "tape_bloom_max_angle must be finite and in [0, 0.5) [rad]";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(tape_range_bias_sigma) || tape_range_bias_sigma < 0.0 ||
|
|
tape_range_bias_sigma > 0.2)
|
|
{
|
|
error = "tape_range_bias_sigma must be finite and in [0, 0.2] [m]";
|
|
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)
|
|
{
|
|
// 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
|
|
// vào chân xe — phải có thứ khác chọn hộ.
|
|
const bool yaw_prior = has_prior && prior_yaw_tolerance < M_PI / 4.0;
|
|
const bool entry_tape = tape_enabled && tape_legs == TapeLegs::kEntry;
|
|
if (!yaw_prior && !entry_tape)
|
|
{
|
|
error = "cart_opening and cart_depth differ by less than 2*cart_dim_tolerance, so the entry "
|
|
"side is ambiguous by 90 deg; set has_prior with prior_yaw_tolerance < pi/4, or "
|
|
"tape_legs: entry";
|
|
return false;
|
|
}
|
|
}
|
|
if (has_prior)
|
|
{
|
|
if (!std::isfinite(prior_x) || !std::isfinite(prior_y) || !std::isfinite(prior_yaw))
|
|
{
|
|
error = "prior_x, prior_y and prior_yaw must be finite";
|
|
return false;
|
|
}
|
|
if (!positiveFinite(search_radius))
|
|
{
|
|
error = "search_radius must be finite and > 0 [m] when has_prior is true";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(prior_yaw_tolerance) || prior_yaw_tolerance <= 0.0 ||
|
|
prior_yaw_tolerance > M_PI)
|
|
{
|
|
error = "prior_yaw_tolerance must be in (0, pi] [rad]";
|
|
return false;
|
|
}
|
|
}
|
|
if (!std::isfinite(search_fov))
|
|
{
|
|
error = "search_fov must be finite [rad] (<= 0 disables the fan)";
|
|
return false;
|
|
}
|
|
if (!std::isfinite(offset_x) || !std::isfinite(offset_y) || !std::isfinite(offset_yaw))
|
|
{
|
|
error = "offset_x, offset_y and offset_yaw must be finite";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
} // namespace dock_pattern_detector
|