fix(depth): free voxels on clearArea/footprint, accept far returns as behind

clearArea and footprint clearing only wrote the 2D cells, so the voxels and
evidence points stayed MARKED and the next column update brought the phantom
back. VoxelLayer now frees the voxel column and its evidence in both paths
(footprint only for observed_volume; legacy unchanged).

A valid return deeper than depth_valid_max_z_m kept every evidence point
unknown, so phantoms with nothing within 3 m behind never cleared. New key
depth_far_return_is_behind (default false) counts such a return as behind a
point that lies at least free_margin_m inside the trusted range.

Replay of the 2026-10-15 bags: real phantoms 62 -> 53, static-cell dropouts
unchanged, object kept on 10/11 FOV exits as before.
This commit is contained in:
2026-10-15 16:58:23 +07:00
parent 6340838dac
commit 63707c968c
8 changed files with 169 additions and 4 deletions

View File

@@ -240,6 +240,54 @@ void VoxelLayer::updateBounds(double robot_x, double robot_y, double robot_yaw,
processPairedDepth(min_x, min_y, max_x, max_y);
current_ = current_ && pairedDepthCurrent();
updateFootprint(robot_x, robot_y, robot_yaw, min_x, min_y, max_x, max_y);
if (footprint_clearing_enabled_ && !paired_depth_sources_.empty())
clearFootprintVoxels();
}
void VoxelLayer::clearDepthColumn(unsigned int x, unsigned int y)
{
if (x >= size_x_ || y >= size_y_)
return;
const unsigned int index = getIndex(x, y);
if (robot_voxel_grid_.getData()[index] >> 16)
for (unsigned int z = 0; z < size_z_; ++z)
depth_evidence_.erase(evidenceKey(x, y, z));
robot_voxel_grid_.clearVoxelColumn(index);
}
void VoxelLayer::clearFootprintVoxels()
{
if (transformed_footprint_.size() < 3)
return;
std::vector<MapLocation> map_polygon;
for (const auto& point : transformed_footprint_)
{
MapLocation location;
// Same rule as setConvexPolygonCost: a footprint partly outside the window clears nothing.
if (!worldToMap(point.x, point.y, location.x, location.y))
return;
map_polygon.push_back(location);
}
std::vector<MapLocation> cells;
convexFillCells(map_polygon, cells);
for (const auto& cell : cells)
{
clearDepthColumn(cell.x, cell.y);
costmap_[getIndex(cell.x, cell.y)] = FREE_SPACE;
}
}
void VoxelLayer::clearArea(int start_x, int start_y, int end_x, int end_y, bool invert_area)
{
// Same cell selection as CostmapLayer::clearArea, which then writes the 2D cells.
for (int x = 0; x < static_cast<int>(size_x_); ++x)
{
const bool xrange = x > start_x && x < end_x;
for (int y = 0; y < static_cast<int>(size_y_); ++y)
if ((xrange && y > start_y && y < end_y) == invert_area)
clearDepthColumn(static_cast<unsigned int>(x), static_cast<unsigned int>(y));
}
CostmapLayer::clearArea(start_x, start_y, end_x, end_y, invert_area);
}
void VoxelLayer::markObservation(const Observation& obs, double* min_x, double* min_y,