wip: state before depth cleanup
Uncommitted work as it ran on the KIT robot until 2026-10-20: the ROC observed_volume tuning patch on top of 63707c9 and the DepthCameraObstacleLayer plugin (clone of tsengapola/costmap_depth_camera noetic, B6 window fix), its 17 unit tests and the CMake wiring. Kept as one commit so the cleanup that follows has a recoverable starting point; not meant to be pushed.
This commit is contained in:
@@ -133,6 +133,77 @@ TEST(DepthVisibility, ProjectsInsideHonoursBorderAndUsableStrips) {
|
||||
EXPECT_FALSE(c.projectsInside(Eigen::Vector3d(-.89,0,1),2)); // u = 11, inside the left strip + 2
|
||||
EXPECT_FALSE(c.projectsInside(Eigen::Vector3d(0,0,.05),2)); // nearer than valid_min_z
|
||||
}
|
||||
// Re-observe-or-clear checker. Camera frame == global frame; (0,0,1) projects to u = 100, v = 80.
|
||||
void setPixel(robot_sensor_msgs::DepthCameraData::Ptr& d,unsigned u,unsigned v,double meters) {
|
||||
uint16_t value=static_cast<uint16_t>(meters*1000);std::memcpy(&d->depth.data[v*400+u*2],&value,2);
|
||||
}
|
||||
tf3::TransformStampedMsg identity() {
|
||||
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;return p;
|
||||
}
|
||||
TEST(DepthReobserve, FourOutcomesOfOnePoint) {
|
||||
DepthVisibilityChecker c; DepthFrustumConfig cfg; const auto p=identity();
|
||||
const std::vector<Eigen::Vector3d> point{Eigen::Vector3d(0,0,1)};
|
||||
auto d=depth(1.03);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints(point),DepthObservation::Confirmed); // within 5 cm
|
||||
d=depth(.9);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints(point),DepthObservation::Occluded);
|
||||
d=depth(1.2);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints(point),DepthObservation::SeenThrough);
|
||||
d=depth(0);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints(point),DepthObservation::NoReturn);
|
||||
}
|
||||
TEST(DepthReobserve, OutOfViewWhenNotProjectableOrOutsideTheTrustedRange) {
|
||||
DepthVisibilityChecker c; DepthFrustumConfig cfg; const auto p=identity();
|
||||
auto d=depth(2);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints({}),DepthObservation::OutOfView);
|
||||
EXPECT_EQ(c.observePoints({Eigen::Vector3d(0,0,-1)}),DepthObservation::OutOfView); // behind the camera
|
||||
EXPECT_EQ(c.observePoints({Eigen::Vector3d(0,0,3.5)}),DepthObservation::OutOfView); // beyond valid_max_z_m
|
||||
EXPECT_EQ(c.observePoints({Eigen::Vector3d(0,-.80,1)}),DepthObservation::OutOfView); // v = 0: no full patch
|
||||
EXPECT_EQ(c.observePoints({Eigen::Vector3d(5,0,1)}),DepthObservation::OutOfView); // right of the image
|
||||
}
|
||||
TEST(DepthReobserve, InvalidPixelsDoNotBlockSeeingThrough) {
|
||||
DepthVisibilityChecker c; DepthFrustumConfig cfg; const auto p=identity();
|
||||
const std::vector<Eigen::Vector3d> point{Eigen::Vector3d(0,0,1)};
|
||||
auto d=depth(0);setPixel(d,101,81,2); // one valid pixel behind, eight with no return
|
||||
ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints(point),DepthObservation::SeenThrough);
|
||||
}
|
||||
TEST(DepthReobserve, OccluderInThePatchBeatsSeenThroughAndConfirmBeatsBoth) {
|
||||
DepthVisibilityChecker c; DepthFrustumConfig cfg; const auto p=identity();
|
||||
const std::vector<Eigen::Vector3d> point{Eigen::Vector3d(0,0,1)};
|
||||
auto d=depth(2);setPixel(d,99,79,.5);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints(point),DepthObservation::Occluded);
|
||||
setPixel(d,101,81,1.02);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints(point),DepthObservation::Confirmed);
|
||||
// The voxel takes its strongest point: one point still on a surface keeps it.
|
||||
d=depth(1.5);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints({Eigen::Vector3d(0,0,1),Eigen::Vector3d(0,0,1.5)}),DepthObservation::Confirmed);
|
||||
d=depth(1.2);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints({Eigen::Vector3d(0,0,1),Eigen::Vector3d(0,0,1.5)}),DepthObservation::Occluded);
|
||||
}
|
||||
TEST(DepthReobserve, FarReturnIsBehindOnlyWhenEnabledAndInsideTheRange) {
|
||||
DepthVisibilityChecker c; DepthFrustumConfig cfg; const auto p=identity();
|
||||
auto d=depth(4);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints({Eigen::Vector3d(0,0,1)}),DepthObservation::NoReturn);
|
||||
cfg.far_return_is_behind=true;ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints({Eigen::Vector3d(0,0,1)}),DepthObservation::SeenThrough);
|
||||
EXPECT_EQ(c.observePoints({Eigen::Vector3d(0,0,2.99)}),DepthObservation::NoReturn); // 2.99 + 0.05 >= 3
|
||||
}
|
||||
// fx = 100: the band at depth z is ceil(100 * 0.1 / z) + 10 px. Column u = 30 is in it at 0.5 m
|
||||
// (30 + 1 px patch > 30) and clear of it at 2.5 m (14 + 1 px).
|
||||
TEST(DepthReobserve, StereoBandIsOutOfViewNearAndUsableFar) {
|
||||
DepthVisibilityChecker c; DepthFrustumConfig cfg; const auto p=identity();
|
||||
const Eigen::Vector3d near(-.35,0,.5), far(-1.75,0,2.5); // both u = 30
|
||||
auto d=depth(.5);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints({near}),DepthObservation::Confirmed); // band disabled
|
||||
cfg.stereo_baseline_m=.1;cfg.stereo_band_margin_px=10;ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints({near}),DepthObservation::OutOfView);
|
||||
EXPECT_FALSE(c.projectsInside(near,2));
|
||||
d=depth(2.5);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.observePoints({far}),DepthObservation::Confirmed);
|
||||
EXPECT_TRUE(c.projectsInside(far,2));
|
||||
}
|
||||
TEST(DepthPairer, MissingHalfExactPairAndDeduplication) {
|
||||
robot::Time::setNow(robot::Time(100,0));DepthFrustumConfig cfg;DepthFramePairer p(cfg,.5);
|
||||
auto c=cloud(robot::Time(100,0));p.addCloud(c);DepthFramePairer::Candidate next;
|
||||
@@ -175,6 +246,8 @@ protected:
|
||||
// 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;
|
||||
cfg["pc_clearing"]["depth_reobserve_clearing"]=false;
|
||||
cfg["pc_clearing"]["depth_stereo_baseline_m"]=0.0;
|
||||
configure(cfg);
|
||||
robot::NodeHandle nh("~");nh.setParam("depth_test",cfg);
|
||||
parent.getCostmap()->resizeMap(80,80,.05,-2,-2);layer.initialize(&parent,"depth_test",&tf);
|
||||
@@ -394,6 +467,76 @@ TEST_F(DepthFarReturnLayerTest, FarReturnClearsWhenEnabledButNoDataStillKeeps) {
|
||||
frame(.62,true);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(0);EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
}
|
||||
// Re-observe-or-clear on the layer. The marked point (0.62, 0.01, 0.08) projects to (98, 98);
|
||||
// frame(m) shows depth m everywhere: .62 re-observes it, 2 sees through, .4 occludes, 0 is no return.
|
||||
class DepthReobserveLayerTest:public DepthEvidenceLayerTest {
|
||||
protected:
|
||||
void configure(YAML::Node& cfg) override {
|
||||
DepthEvidenceLayerTest::configure(cfg);
|
||||
cfg["pc_clearing"]["depth_reobserve_clearing"]=true;
|
||||
cfg["pc_clearing"]["depth_confirm_tolerance_m"]=.05;
|
||||
cfg["pc_clearing"]["depth_miss_frames"]=3;
|
||||
cfg["pc_clearing"]["depth_no_return_weight"]=noReturnWeight();
|
||||
cfg["pc_clearing"]["depth_stereo_baseline_m"]=stereoBaseline();
|
||||
cfg["pc_clearing"]["depth_stereo_band_margin_px"]=10;
|
||||
}
|
||||
virtual double noReturnWeight() const {return 0.;}
|
||||
virtual double stereoBaseline() const {return 0.;}
|
||||
};
|
||||
TEST_F(DepthReobserveLayerTest, SeenThroughFreesOnlyAfterMissFrames) {
|
||||
frame(.62,true);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(2);EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(2);EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(2);EXPECT_EQ(at(),FREE_SPACE);
|
||||
}
|
||||
TEST_F(DepthReobserveLayerTest, ConfirmRestartsTheMissCount) {
|
||||
frame(.62,true);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(2);frame(2);frame(.62); // surface measured again, no marking point
|
||||
frame(2);frame(2);EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(2);EXPECT_EQ(at(),FREE_SPACE);
|
||||
}
|
||||
TEST_F(DepthReobserveLayerTest, RemarkedVoxelStartsANewMissCount) {
|
||||
frame(.62,true);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(2);
|
||||
frameCloud(2,-.01f,.11f,.62f); // seen through (2nd miss), then marked again in the same frame
|
||||
frame(2);frame(2);EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(2);EXPECT_EQ(at(),FREE_SPACE);
|
||||
}
|
||||
TEST_F(DepthReobserveLayerTest, OccludedOutOfViewAndNoReturnNeverExpire) {
|
||||
frame(.62,true);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
for(int i=0;i<20;++i) frame(.4);
|
||||
EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
for(int i=0;i<20;++i) frame(2,false,1.57); // camera turned away
|
||||
EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
for(int i=0;i<20;++i) frame(0);
|
||||
EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(2);frame(2);EXPECT_EQ(at(),LETHAL_OBSTACLE); // none of the above counted as a miss
|
||||
frame(2);EXPECT_EQ(at(),FREE_SPACE);
|
||||
}
|
||||
TEST_F(DepthReobserveLayerTest, StillVisibleObjectIsKept) {
|
||||
frame(.62,true);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
for(int i=0;i<20;++i) frame(i%2?.64:.60); // depth noise inside the 5 cm tolerance
|
||||
EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
}
|
||||
class DepthReobserveNoReturnTest:public DepthReobserveLayerTest {
|
||||
protected:
|
||||
double noReturnWeight() const override {return .5;}
|
||||
};
|
||||
TEST_F(DepthReobserveNoReturnTest, NoReturnFreesWhenWeighted) {
|
||||
frame(.62,true);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
for(int i=0;i<5;++i) frame(0);
|
||||
EXPECT_EQ(at(),LETHAL_OBSTACLE); // 2.5 misses
|
||||
frame(0);EXPECT_EQ(at(),FREE_SPACE);
|
||||
}
|
||||
// Band at 0.62 m: ceil(100 * 0.1 / 0.62) + 10 = 27 px, plus the 2 px marking border.
|
||||
class DepthReobserveStereoBandTest:public DepthReobserveLayerTest {
|
||||
protected:
|
||||
double stereoBaseline() const override {return .1;}
|
||||
};
|
||||
TEST_F(DepthReobserveStereoBandTest, MarkingSkipsTheStereoBand) {
|
||||
frameCloud(.62,-.496f,.11f,.62f);EXPECT_NE(at(.62,.496),LETHAL_OBSTACLE); // u = 20
|
||||
frameCloud(.62,-.248f,.11f,.62f);EXPECT_EQ(at(.62,.248),LETHAL_OBSTACLE); // u = 60
|
||||
}
|
||||
}
|
||||
int main(int argc,char**argv) {robot::Time::init();testing::InitGoogleTest(&argc,argv);return RUN_ALL_TESTS();}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user