feat(depth): certify evidence points instead of whole voxels (phase 1)
The whole-voxel rule never clears a voxel whose box crosses the image edge. A person bending over to lift an object leaves high voxels at the top edge of the image: in the 2026-10-15 lift bag 0 of 54 phantom cells cleared. - DepthEvidenceStore keeps, per marked voxel, the 6 per-axis extreme points plus the most recent ones, keyed by a window-independent cell index. - DepthVisibilityChecker::classifyPoints: Free only when every evidence point projects with a full patch inside the usable image and sees valid depth behind it; any surface in front keeps it, invalid depth keeps it. - Paired marking drops points within depth_marking_border_px of the image edge, so every kept point can be re-checked from the pose that saw it. - Voxels without evidence keep the whole-voxel rule; evidence is erased on clear, pruned on rolling shift and every 50 frames. - New keys depth_evidence_points_enabled (default false), depth_evidence_points_per_voxel (8, 6..16), depth_marking_border_px (must be > depth_projection_margin_px when enabled); startup log and counters (by_evidence, border_dropped_points, evidence_voxels). - Tests: depth_evidence_store_test; checker and layer tests for the image top cut, border drop, rolling shift and a still-visible object.
This commit is contained in:
@@ -149,6 +149,10 @@ bool VoxelLayer::getParams(const std::string& config_file_name, robot::NodeHandl
|
||||
throw std::invalid_argument("observed_volume marking height band must fit its voxel grid");
|
||||
robot::log_info("observed_volume grid: z_resolution=%.4f m bins=%u span=[%.3f, %.3f) m\n",
|
||||
z_resolution_, size_z_, origin_z_, origin_z_ + size_z_ * z_resolution_);
|
||||
depth_evidence_.setPointsPerVoxel(source->config.evidence_points_per_voxel);
|
||||
robot::log_info("observed_volume evidence points: %s, points_per_voxel=%u, marking_border_px=%u px\n",
|
||||
source->config.evidence_points_enabled ? "enabled" : "disabled (whole-voxel check)",
|
||||
depth_evidence_.pointsPerVoxel(), source->config.marking_border_px);
|
||||
}
|
||||
this->matchSize();
|
||||
}
|
||||
@@ -164,6 +168,7 @@ void VoxelLayer::matchSize()
|
||||
{
|
||||
ObstacleLayer::matchSize();
|
||||
robot_voxel_grid_.resize(size_x_, size_y_, size_z_);
|
||||
depth_evidence_.clear();
|
||||
if (!(robot_voxel_grid_.sizeX() == size_x_ && robot_voxel_grid_.sizeY() == size_y_))
|
||||
{
|
||||
std::cerr << "[FATAL] Voxel grid size mismatch: "
|
||||
@@ -186,6 +191,7 @@ void VoxelLayer::resetMaps()
|
||||
resetPairedDepth();
|
||||
Costmap2D::resetMaps();
|
||||
robot_voxel_grid_.reset();
|
||||
depth_evidence_.clear();
|
||||
}
|
||||
|
||||
void VoxelLayer::updateBounds(double robot_x, double robot_y, double robot_yaw, double* min_x,
|
||||
@@ -237,8 +243,9 @@ void VoxelLayer::updateBounds(double robot_x, double robot_y, double robot_yaw,
|
||||
}
|
||||
|
||||
void VoxelLayer::markObservation(const Observation& obs, double* min_x, double* min_y,
|
||||
double* max_x, double* max_y)
|
||||
double* max_x, double* max_y, const PairedMarking* paired)
|
||||
{
|
||||
const bool record_evidence = paired != nullptr && paired->config->evidence_points_enabled;
|
||||
|
||||
const robot_sensor_msgs::PointCloud2& cloud = *(obs.cloud_);
|
||||
|
||||
@@ -275,6 +282,21 @@ void VoxelLayer::markObservation(const Observation& obs, double* min_x, double*
|
||||
continue;
|
||||
}
|
||||
|
||||
bool fresh_voxel = false;
|
||||
if (record_evidence)
|
||||
{
|
||||
// A point at the image edge could never be re-checked with a full patch from the
|
||||
// pose that saw it, and would leave a voxel that only the whole-box rule judges.
|
||||
const Eigen::Vector3d point(*iter_x, *iter_y, *iter_z);
|
||||
if (paired->config->marking_border_px > 0 &&
|
||||
!paired->checker->projectsInside(point, paired->config->marking_border_px))
|
||||
{
|
||||
++visibility_counts_.border_dropped;
|
||||
continue;
|
||||
}
|
||||
fresh_voxel = robot_voxel_grid_.getVoxel(mx, my, mz) != robot_voxel_grid::MARKED;
|
||||
}
|
||||
|
||||
// mark the cell in the voxel grid and check if we should also mark it in the costmap
|
||||
if (robot_voxel_grid_.markVoxelInMap(mx, my, mz, mark_threshold_))
|
||||
{
|
||||
@@ -283,9 +305,25 @@ void VoxelLayer::markObservation(const Observation& obs, double* min_x, double*
|
||||
costmap_[index] = LETHAL_OBSTACLE;
|
||||
touch(double(*iter_x), double(*iter_y), min_x, min_y, max_x, max_y);
|
||||
}
|
||||
if (record_evidence)
|
||||
depth_evidence_.add(evidenceKey(mx, my, mz), Eigen::Vector3f(*iter_x, *iter_y, *iter_z), fresh_voxel);
|
||||
}
|
||||
}
|
||||
|
||||
void VoxelLayer::pruneDepthEvidence()
|
||||
{
|
||||
if (depth_evidence_.size() == 0)
|
||||
return;
|
||||
depth_evidence_.eraseIf([this](const DepthEvidenceStore::VoxelKey& key) {
|
||||
const int x = key.x - evidence_offset_x_;
|
||||
const int y = key.y - evidence_offset_y_;
|
||||
return x < 0 || y < 0 || x >= static_cast<int>(size_x_) || y >= static_cast<int>(size_y_) ||
|
||||
key.z >= size_z_ ||
|
||||
robot_voxel_grid_.getVoxel(static_cast<unsigned int>(x), static_cast<unsigned int>(y), key.z) !=
|
||||
robot_voxel_grid::MARKED;
|
||||
});
|
||||
}
|
||||
|
||||
void VoxelLayer::processPairedDepth(double* min_x, double* min_y, double* max_x, double* max_y)
|
||||
{
|
||||
for (const auto& source : paired_depth_sources_)
|
||||
@@ -329,6 +367,10 @@ void VoxelLayer::processPairedDepth(double* min_x, double* min_y, double* max_x,
|
||||
|
||||
// No occupied cache: the live voxel grid already contains rolling-window overlap.
|
||||
// Plan all clears before applying this frame; both branches share exactly one pose.
|
||||
// With evidence points a voxel is judged by the points that marked it; a voxel
|
||||
// without evidence (marked before the mode was enabled) keeps the whole-box rule.
|
||||
const bool use_evidence = source->config.evidence_points_enabled;
|
||||
std::vector<Eigen::Vector3d> evidence;
|
||||
std::vector<std::array<unsigned int, 3>> free_voxels;
|
||||
for (unsigned int y = 0; y < size_y_; ++y)
|
||||
for (unsigned int x = 0; x < size_x_; ++x)
|
||||
@@ -337,10 +379,19 @@ void VoxelLayer::processPairedDepth(double* min_x, double* min_y, double* max_x,
|
||||
for (unsigned int z = 0; z < size_z_; ++z)
|
||||
{
|
||||
if (robot_voxel_grid_.getVoxel(x, y, z) != robot_voxel_grid::MARKED) continue;
|
||||
const Eigen::Vector3d lower(origin_x_ + x * resolution_,
|
||||
origin_y_ + y * resolution_, origin_z_ + z * z_resolution_);
|
||||
const Eigen::Vector3d upper = lower + Eigen::Vector3d(resolution_, resolution_, z_resolution_);
|
||||
const auto visibility = checker.classify(lower, upper);
|
||||
DepthVisibilityResult visibility;
|
||||
if (use_evidence && depth_evidence_.points(evidenceKey(x, y, z), evidence))
|
||||
{
|
||||
visibility = checker.classifyPoints(evidence);
|
||||
++visibility_counts_.by_evidence;
|
||||
}
|
||||
else
|
||||
{
|
||||
const Eigen::Vector3d lower(origin_x_ + x * resolution_,
|
||||
origin_y_ + y * resolution_, origin_z_ + z * z_resolution_);
|
||||
const Eigen::Vector3d upper = lower + Eigen::Vector3d(resolution_, resolution_, z_resolution_);
|
||||
visibility = checker.classify(lower, upper);
|
||||
}
|
||||
if (visibility.state == DepthVisibility::Free)
|
||||
{ free_voxels.push_back({x, y, z}); ++visibility_counts_.free; }
|
||||
else if (visibility.state == DepthVisibility::Surface) ++visibility_counts_.surface;
|
||||
@@ -351,6 +402,7 @@ void VoxelLayer::processPairedDepth(double* min_x, double* min_y, double* max_x,
|
||||
{
|
||||
const auto x = voxel[0], y = voxel[1], z = voxel[2];
|
||||
robot_voxel_grid_.clearVoxel(x, y, z);
|
||||
depth_evidence_.erase(evidenceKey(x, y, z));
|
||||
const auto status = robot_voxel_grid_.getVoxelColumn(x, y, unknown_threshold_, mark_threshold_);
|
||||
costmap_[getIndex(x, y)] = status == robot_voxel_grid::MARKED ? LETHAL_OBSTACLE :
|
||||
status == robot_voxel_grid::FREE ? FREE_SPACE : NO_INFORMATION;
|
||||
@@ -358,21 +410,33 @@ void VoxelLayer::processPairedDepth(double* min_x, double* min_y, double* max_x,
|
||||
touch(origin_x_ + x * resolution_, origin_y_ + y * resolution_, min_x, min_y, max_x, max_y);
|
||||
touch(origin_x_ + (x + 1) * resolution_, origin_y_ + (y + 1) * resolution_, min_x, min_y, max_x, max_y);
|
||||
}
|
||||
markObservation(observations.front(), min_x, min_y, max_x, max_y);
|
||||
const PairedMarking paired_marking{&checker, &source->config};
|
||||
markObservation(observations.front(), min_x, min_y, max_x, max_y, &paired_marking);
|
||||
source->pairer.applied(pair.stamp);
|
||||
++visibility_counts_.frames;
|
||||
// Voxels cleared by other paths (footprint, recovery, legacy rays) leave stale
|
||||
// evidence; a bounded sweep keeps the store at the size of the live occupancy.
|
||||
constexpr uint64_t kEvidencePrunePeriodFrames = 50;
|
||||
if (use_evidence && ++frames_since_evidence_prune_ >= kEvidencePrunePeriodFrames)
|
||||
{
|
||||
pruneDepthEvidence();
|
||||
frames_since_evidence_prune_ = 0;
|
||||
}
|
||||
}
|
||||
const auto counts = source->pairer.counts();
|
||||
robot::log_info_throttle(5.0, "paired depth [%s]: applied=%llu tf_wait=%llu "
|
||||
"invalid=%llu stale=%llu expired=%llu overflow=%llu duplicate=%llu; "
|
||||
"voxel decisions free=%llu surface=%llu unknown=%llu (cumulative)\n",
|
||||
"voxel decisions free=%llu surface=%llu unknown=%llu by_evidence=%llu; "
|
||||
"border_dropped_points=%llu evidence_voxels=%zu (cumulative)\n",
|
||||
name_.c_str(), static_cast<unsigned long long>(counts.applied),
|
||||
static_cast<unsigned long long>(counts.tf_wait), static_cast<unsigned long long>(counts.invalid),
|
||||
static_cast<unsigned long long>(counts.stale), static_cast<unsigned long long>(counts.expired),
|
||||
static_cast<unsigned long long>(counts.overflow), static_cast<unsigned long long>(counts.duplicate),
|
||||
static_cast<unsigned long long>(visibility_counts_.free),
|
||||
static_cast<unsigned long long>(visibility_counts_.surface),
|
||||
static_cast<unsigned long long>(visibility_counts_.unknown));
|
||||
static_cast<unsigned long long>(visibility_counts_.unknown),
|
||||
static_cast<unsigned long long>(visibility_counts_.by_evidence),
|
||||
static_cast<unsigned long long>(visibility_counts_.border_dropped), depth_evidence_.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1132,6 +1196,10 @@ void VoxelLayer::updateOrigin(double new_origin_x, double new_origin_y)
|
||||
size_x_, cell_size_x, cell_size_y);
|
||||
}
|
||||
|
||||
// Evidence keys are window-independent: track the shift, then drop what left the window.
|
||||
evidence_offset_x_ += cell_ox;
|
||||
evidence_offset_y_ += cell_oy;
|
||||
pruneDepthEvidence();
|
||||
}
|
||||
|
||||
// Export factory function
|
||||
|
||||
Reference in New Issue
Block a user