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:
@@ -104,6 +104,24 @@ TEST(DepthVisibility, EvidencePointsCertifyAVoxelCutByTheImageTop) {
|
||||
d=depth(1.5);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.classifyPoints({Eigen::Vector3d(0,0,1),Eigen::Vector3d(0,0,1.6)}).state,DepthVisibility::Surface);
|
||||
}
|
||||
// A return beyond valid_max_z_m (3 m) proves the ray passed a point well inside the range.
|
||||
TEST(DepthVisibility, FarReturnCountsAsBehindOnlyWhenEnabled) {
|
||||
DepthVisibilityChecker c; DepthFrustumConfig cfg;
|
||||
tf3::TransformStampedMsg p; p.header.frame_id="odom";p.child_frame_id="camera";
|
||||
p.header.stamp=tf3::Time(100,0);p.transform.rotation.w=1;
|
||||
const std::vector<Eigen::Vector3d> point{Eigen::Vector3d(0,0,1)}; // u = 100, v = 80
|
||||
auto d=depth(4);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.classifyPoints(point).state,DepthVisibility::Unknown); // default: not proof
|
||||
cfg.far_return_is_behind=true;ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.classifyPoints(point).state,DepthVisibility::Free);
|
||||
// point + margin reaches the range limit: a far return proves nothing about it
|
||||
EXPECT_EQ(c.classifyPoints({Eigen::Vector3d(0,0,2.99)}).state,DepthVisibility::Unknown);
|
||||
d=depth(4);uint16_t zero=0;std::memcpy(&d->depth.data[80*400+101*2],&zero,2); // no-data in the patch
|
||||
ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.classifyPoints(point).state,DepthVisibility::Unknown);
|
||||
d=depth(.5);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.classifyPoints(point).state,DepthVisibility::Surface); // a nearer surface still keeps it
|
||||
}
|
||||
TEST(DepthVisibility, ProjectsInsideHonoursBorderAndUsableStrips) {
|
||||
DepthVisibilityChecker c; DepthFrustumConfig cfg;cfg.clear_left_border_px=10;
|
||||
tf3::TransformStampedMsg p; p.header.frame_id="odom";p.child_frame_id="camera";
|
||||
@@ -156,6 +174,7 @@ protected:
|
||||
cfg["observation_sources"]="pc_marking pc_clearing";cfg["footprint_clearing_enabled"]=false;cfg["enabled"]=true;
|
||||
// Explicit, so the result does not depend on what the runtime YAML currently enables.
|
||||
cfg["pc_clearing"]["depth_evidence_points_enabled"]=false;
|
||||
cfg["pc_clearing"]["depth_far_return_is_behind"]=false;
|
||||
configure(cfg);
|
||||
robot::NodeHandle nh("~");nh.setParam("depth_test",cfg);
|
||||
parent.getCostmap()->resizeMap(80,80,.05,-2,-2);layer.initialize(&parent,"depth_test",&tf);
|
||||
@@ -297,6 +316,84 @@ TEST_F(DepthEvidenceLayerTest, AStillVisibleObjectIsNeverCertifiedFree) {
|
||||
for(int i=0;i<3;++i) {frameCloud(.62,-.01f,-.45f,.62f);EXPECT_EQ(at(),LETHAL_OBSTACLE);}
|
||||
frame(.62);EXPECT_EQ(at(),LETHAL_OBSTACLE); // no marking this frame, surface still seen
|
||||
}
|
||||
// Two voxels in the column of (0.62, 0.01): z 0.08 m (seen by image rows below 65) and
|
||||
// z 0.48 m (rows above 65). The partial frame frees the low one and keeps the high one
|
||||
// occluded, so a column update would re-derive the cell from any voxel left behind.
|
||||
class DepthColumnClearTest:public DepthEvidenceLayerTest {
|
||||
protected:
|
||||
void configure(YAML::Node& cfg) override {
|
||||
DepthEvidenceLayerTest::configure(cfg);
|
||||
cfg["footprint_clearing_enabled"]=true;
|
||||
}
|
||||
void markTwoVoxels() {
|
||||
auto stamp=now();robot::Time::setNow(stamp);ASSERT_TRUE(tf.setTransform(pose(stamp),"test"));
|
||||
auto c=cloud(stamp);robot_sensor_msgs::PointCloud2Modifier m(c);m.resize(2);
|
||||
robot_sensor_msgs::PointCloud2Iterator<float> x(c,"x"),y(c,"y"),z(c,"z");
|
||||
*x=-.01;*y=.11;*z=.62;++x;++y;++z;*x=-.01;*y=-.29;*z=.62;
|
||||
layer.dataCallBack(c,"/camera/depth/points_proc");
|
||||
robot_sensor_msgs::DepthCameraData::ConstPtr d=depth(.62,stamp);layer.dataCallBack(d,"/camera/depth/data");update();
|
||||
}
|
||||
void partialFrame() {
|
||||
auto stamp=now();robot::Time::setNow(stamp);ASSERT_TRUE(tf.setTransform(pose(stamp),"test"));
|
||||
auto partial=depth(2,stamp);uint16_t blocked=400;
|
||||
for(unsigned v=0;v<65;++v) for(unsigned u=0;u<200;++u)
|
||||
std::memcpy(&partial->depth.data[v*400+u*2],&blocked,2);
|
||||
layer.dataCallBack(cloud(stamp,false),"/camera/depth/points_proc");
|
||||
robot_sensor_msgs::DepthCameraData::ConstPtr d=partial;layer.dataCallBack(d,"/camera/depth/data");update();
|
||||
}
|
||||
void setFootprint(double x0,double x1,double y0,double y1) {
|
||||
std::vector<robot_geometry_msgs::Point> footprint(4);
|
||||
footprint[0].x=footprint[1].x=x0;footprint[2].x=footprint[3].x=x1;
|
||||
footprint[0].y=footprint[3].y=y0;footprint[1].y=footprint[2].y=y1;
|
||||
parent.setFootprint(footprint);
|
||||
}
|
||||
uint32_t markedBits(double x=.62,double y=.01) {
|
||||
unsigned a,b;EXPECT_TRUE(layer.worldToMap(x,y,a,b));
|
||||
return layer.voxelSnapshot().data[b*layer.getSizeInCellsX()+a]>>16;
|
||||
}
|
||||
};
|
||||
TEST_F(DepthColumnClearTest, FootprintClearingAlsoFreesTheVoxelColumn) {
|
||||
setFootprint(-1.9,-1.8,-1.9,-1.8); // far corner of the window
|
||||
markTwoVoxels();ASSERT_EQ(at(),LETHAL_OBSTACLE);ASSERT_NE(markedBits(),0u);
|
||||
setFootprint(.50,.75,-.10,.10);update(); // robot body now covers the cell
|
||||
EXPECT_EQ(at(),FREE_SPACE);EXPECT_EQ(markedBits(),0u);
|
||||
setFootprint(-1.9,-1.8,-1.9,-1.8);partialFrame();
|
||||
EXPECT_EQ(at(),FREE_SPACE); // nothing left in the column to re-derive the cell
|
||||
}
|
||||
TEST_F(DepthColumnClearTest, ClearAreaAlsoFreesTheVoxelColumn) {
|
||||
setFootprint(-1.9,-1.8,-1.9,-1.8);
|
||||
markTwoVoxels();ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
layer.clearArea(0,0,0,0,false); // empty kept window: clear the whole layer
|
||||
EXPECT_EQ(at(),NO_INFORMATION);EXPECT_EQ(markedBits(),0u);
|
||||
partialFrame();EXPECT_NE(at(),LETHAL_OBSTACLE);
|
||||
}
|
||||
TEST_F(DepthColumnClearTest, ClearAreaFollowsTheBaseWindowSelection) {
|
||||
setFootprint(-1.9,-1.8,-1.9,-1.8);
|
||||
markTwoVoxels();ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
unsigned ux,uy;ASSERT_TRUE(layer.worldToMap(.62,.01,ux,uy));
|
||||
const int x=static_cast<int>(ux),y=static_cast<int>(uy);
|
||||
layer.clearArea(x-3,y-3,x+3,y+3,false); // default recovery: keep the window, clear outside it
|
||||
EXPECT_EQ(at(),LETHAL_OBSTACLE);EXPECT_NE(markedBits(),0u);
|
||||
layer.clearArea(x-3,y-3,x+3,y+3,true); // inverted: clear inside the window
|
||||
EXPECT_EQ(at(),NO_INFORMATION);EXPECT_EQ(markedBits(),0u);
|
||||
}
|
||||
class DepthFarReturnLayerTest:public DepthEvidenceLayerTest {
|
||||
protected:
|
||||
void configure(YAML::Node& cfg) override {
|
||||
DepthEvidenceLayerTest::configure(cfg);
|
||||
cfg["pc_clearing"]["depth_far_return_is_behind"]=true;
|
||||
}
|
||||
};
|
||||
TEST_F(DepthEvidenceLayerTest, FarReturnKeepsTheVoxelByDefault) {
|
||||
frame(.62,true);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(4);EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
}
|
||||
TEST_F(DepthFarReturnLayerTest, FarReturnClearsWhenEnabledButNoDataStillKeeps) {
|
||||
frame(.62,true);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(4);EXPECT_EQ(at(),FREE_SPACE);
|
||||
frame(.62,true);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(0);EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
}
|
||||
}
|
||||
int main(int argc,char**argv) {robot::Time::init();testing::InitGoogleTest(&argc,argv);return RUN_ALL_TESTS();}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user