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:
385
test/depth_camera_obstacle_layer_test.cpp
Normal file
385
test/depth_camera_obstacle_layer_test.cpp
Normal file
@@ -0,0 +1,385 @@
|
||||
#include <robot_costmap_2d/depth_camera_obstacle_layer.h>
|
||||
#include <robot_costmap_2d/cost_values.h>
|
||||
#include <robot_sensor_msgs/point_cloud2_iterator.h>
|
||||
#include <robot_sensor_msgs/DepthCameraData.h>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
using namespace robot_costmap_2d;
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr double kFovW = 1.23; // D410 at 424x240, fx = 300 [rad]
|
||||
constexpr double kFovV = 0.76;
|
||||
constexpr char kTopic[] = "/camera/depth/points_proc";
|
||||
|
||||
// Optical frame "camera" 0.19 m above odom, looking along +x of odom (rotated by yaw).
|
||||
tf3::TransformStampedMsg pose(robot::Time stamp, double yaw = 0)
|
||||
{
|
||||
tf3::TransformStampedMsg p;
|
||||
p.header.frame_id = "odom";
|
||||
p.child_frame_id = "camera";
|
||||
p.header.stamp = tf3::Time(stamp.sec, stamp.nsec);
|
||||
Eigen::Matrix3d optical;
|
||||
optical << 0, 0, 1, -1, 0, 0, 0, -1, 0;
|
||||
Eigen::Quaterniond q(Eigen::AngleAxisd(yaw, Eigen::Vector3d::UnitZ()) * optical);
|
||||
p.transform.rotation.x = q.x();
|
||||
p.transform.rotation.y = q.y();
|
||||
p.transform.rotation.z = q.z();
|
||||
p.transform.rotation.w = q.w();
|
||||
p.transform.translation.z = .19;
|
||||
return p;
|
||||
}
|
||||
|
||||
// Points given in odom for a camera at yaw 0; stored in the optical frame of the cloud.
|
||||
robot_sensor_msgs::PointCloud2 cloud(robot::Time stamp, const std::vector<Eigen::Vector3d>& odom_points)
|
||||
{
|
||||
robot_sensor_msgs::PointCloud2 c;
|
||||
c.header.stamp = stamp;
|
||||
c.header.frame_id = "camera";
|
||||
c.height = 1;
|
||||
robot_sensor_msgs::PointCloud2Modifier m(c);
|
||||
m.setPointCloud2FieldsByString(1, "xyz");
|
||||
m.resize(odom_points.size());
|
||||
robot_sensor_msgs::PointCloud2Iterator<float> x(c, "x"), y(c, "y"), z(c, "z");
|
||||
for (const auto& p : odom_points)
|
||||
{
|
||||
*x = -p.y();
|
||||
*y = .19 - p.z();
|
||||
*z = p.x();
|
||||
++x;
|
||||
++y;
|
||||
++z;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
// 3 x 3 points, 6 cm apart (one per 5 cm voxel), one Euclidean cluster. Kept away from cell
|
||||
// boundaries: the source stores (int)(x / 0.05), so y = .07 .13 .19 are columns 1 2 3.
|
||||
std::vector<Eigen::Vector3d> object(double x = 1.02, double y = .13, double z = .30)
|
||||
{
|
||||
std::vector<Eigen::Vector3d> pts;
|
||||
for (double dy : {-.06, 0., .06})
|
||||
for (double dz : {-.06, 0., .06})
|
||||
pts.emplace_back(x, y + dy, z + dz);
|
||||
return pts;
|
||||
}
|
||||
|
||||
// 11 points in a row 0.6 m behind the object: keeps the cloud above 5 points, own cluster.
|
||||
std::vector<Eigen::Vector3d> wall()
|
||||
{
|
||||
std::vector<Eigen::Vector3d> pts;
|
||||
for (int i = -5; i <= 5; ++i)
|
||||
pts.emplace_back(1.62, i * .06 + .13, .30);
|
||||
return pts;
|
||||
}
|
||||
|
||||
std::vector<Eigen::Vector3d> join(std::vector<Eigen::Vector3d> a, const std::vector<Eigen::Vector3d>& b)
|
||||
{
|
||||
a.insert(a.end(), b.begin(), b.end());
|
||||
return a;
|
||||
}
|
||||
|
||||
YAML::Node baseConfig()
|
||||
{
|
||||
YAML::Node cfg;
|
||||
cfg["enabled"] = true;
|
||||
cfg["footprint_clearing_enabled"] = false;
|
||||
cfg["use_global_frame_to_mark"] = true;
|
||||
cfg["enable_near_blocked_protection"] = false;
|
||||
cfg["observation_sources"] = "depth_cam";
|
||||
cfg["debug"]["stats"] = false;
|
||||
cfg["depth_cam"]["topic"] = kTopic;
|
||||
cfg["depth_cam"]["sensor_frame_is_optical"] = true;
|
||||
cfg["depth_cam"]["FOV_W"] = kFovW;
|
||||
cfg["depth_cam"]["FOV_V"] = kFovV;
|
||||
cfg["depth_cam"]["min_detect_distance"] = .15;
|
||||
cfg["depth_cam"]["max_detect_distance"] = 2.5;
|
||||
cfg["depth_cam"]["min_obstacle_height"] = .05;
|
||||
cfg["depth_cam"]["max_obstacle_height"] = 1.0;
|
||||
return cfg;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Frustum geometry
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
TEST(DepthCameraFrustum, InsideFollowsTheConfiguredPyramid)
|
||||
{
|
||||
DepthCameraFrustum f;
|
||||
f.build(Eigen::Isometry3d::Identity(), kFovW, kFovV, .15, 2.5, false); // X forward
|
||||
const float half_w = std::tan(kFovW / 2), half_v = std::tan(kFovV / 2);
|
||||
EXPECT_TRUE(f.inside(Eigen::Vector3f(1, 0, 0)));
|
||||
EXPECT_FALSE(f.inside(Eigen::Vector3f(.1f, 0, 0))); // before the near plane
|
||||
EXPECT_FALSE(f.inside(Eigen::Vector3f(2.6f, 0, 0))); // beyond the far plane
|
||||
EXPECT_FALSE(f.inside(Eigen::Vector3f(-1, 0, 0)));
|
||||
EXPECT_TRUE(f.inside(Eigen::Vector3f(1, .98f * half_w, 0)));
|
||||
EXPECT_FALSE(f.inside(Eigen::Vector3f(1, 1.02f * half_w, 0)));
|
||||
EXPECT_FALSE(f.inside(Eigen::Vector3f(1, -1.02f * half_w, 0)));
|
||||
EXPECT_TRUE(f.inside(Eigen::Vector3f(1, 0, -.98f * half_v)));
|
||||
EXPECT_FALSE(f.inside(Eigen::Vector3f(1, 0, 1.02f * half_v)));
|
||||
}
|
||||
|
||||
TEST(DepthCameraFrustum, AttachBandIsTwelveCentimetresFromEveryFace)
|
||||
{
|
||||
DepthCameraFrustum f;
|
||||
f.build(Eigen::Isometry3d::Identity(), kFovW, kFovV, .15, 2.5, false);
|
||||
EXPECT_FALSE(f.nearFace(Eigen::Vector3f(1, 0, 0)));
|
||||
EXPECT_TRUE(f.nearFace(Eigen::Vector3f(.25f, 0, 0))); // 10 cm past the near plane
|
||||
EXPECT_TRUE(f.nearFace(Eigen::Vector3f(2.4f, 0, 0))); // 10 cm before the far plane
|
||||
const float half_w = std::tan(kFovW / 2);
|
||||
EXPECT_TRUE(f.nearFace(Eigen::Vector3f(1, half_w - .05f, 0)));
|
||||
EXPECT_FALSE(f.nearFace(Eigen::Vector3f(1, half_w - .3f, 0)));
|
||||
}
|
||||
|
||||
TEST(DepthCameraFrustum, OpticalFrameGivesTheSamePyramid)
|
||||
{
|
||||
DepthCameraFrustum link, optical;
|
||||
link.build(Eigen::Isometry3d::Identity(), kFovW, kFovV, .15, 2.5, false);
|
||||
Eigen::Isometry3d T = Eigen::Isometry3d::Identity();
|
||||
T.linear() << 0, 0, 1, -1, 0, 0, 0, -1, 0; // optical axes expressed in camera_link
|
||||
optical.build(T, kFovW, kFovV, .15, 2.5, true);
|
||||
for (int i = 0; i < 8; ++i)
|
||||
EXPECT_LT((link.vertices[i] - optical.vertices[i]).norm(), 1e-5f) << "vertex " << i;
|
||||
EXPECT_TRUE(optical.inside(Eigen::Vector3f(1, 0, 0)));
|
||||
}
|
||||
|
||||
TEST(DepthCameraFrustum, AttachedUnlessWellInsideAnotherFrustum)
|
||||
{
|
||||
DepthCameraFrustum a, b;
|
||||
a.build(Eigen::Isometry3d::Identity(), kFovW, kFovV, .15, 2.5, false);
|
||||
Eigen::Isometry3d T = Eigen::Isometry3d::Identity();
|
||||
T.translation() << 0, .3, 0; // second camera 30 cm to the left
|
||||
b.build(T, kFovW, kFovV, .15, 2.5, false);
|
||||
const Eigen::Vector3f near_left_face_of_a(1, std::tan(kFovW / 2) - .05f, 0);
|
||||
EXPECT_TRUE(attachedToFrustums({a}, near_left_face_of_a));
|
||||
EXPECT_FALSE(attachedToFrustums({a, b}, near_left_face_of_a));
|
||||
EXPECT_FALSE(attachedToFrustums({a}, Eigen::Vector3f(1, 0, 0)));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Layer
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
class DepthCameraLayerTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
tf3::BufferCore tf;
|
||||
LayeredCostmap parent{"odom", false, false};
|
||||
DepthCameraObstacleLayer layer;
|
||||
uint32_t tick = 0;
|
||||
double min_x = 0, min_y = 0, max_x = 0, max_y = 0;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
robot::Time::setNow(robot::Time(100, 0));
|
||||
YAML::Node cfg = baseConfig();
|
||||
configure(cfg);
|
||||
robot::NodeHandle nh("~");
|
||||
nh.setParam("dcam_test", cfg);
|
||||
parent.getCostmap()->resizeMap(80, 80, .05, -2, -2);
|
||||
layer.initialize(&parent, "dcam_test", &tf);
|
||||
ASSERT_TRUE(layer.isEnabled());
|
||||
}
|
||||
virtual void configure(YAML::Node&) {}
|
||||
|
||||
robot::Time next()
|
||||
{
|
||||
return robot::Time(100, ++tick * 10000000);
|
||||
}
|
||||
void update()
|
||||
{
|
||||
min_x = min_y = 1e9;
|
||||
max_x = max_y = -1e9;
|
||||
layer.updateBounds(0, 0, 0, &min_x, &min_y, &max_x, &max_y);
|
||||
}
|
||||
void frame(const std::vector<Eigen::Vector3d>& pts, double yaw = 0, bool has_tf = true)
|
||||
{
|
||||
const robot::Time stamp = next();
|
||||
robot::Time::setNow(stamp);
|
||||
if (has_tf)
|
||||
ASSERT_TRUE(tf.setTransform(pose(stamp, yaw), "test"));
|
||||
layer.dataCallBack(cloud(stamp, pts), kTopic);
|
||||
update();
|
||||
}
|
||||
unsigned char master(double x = 1.01, double y = .11)
|
||||
{
|
||||
Costmap2D& m = *parent.getCostmap();
|
||||
m.resetMap(0, 0, m.getSizeInCellsX(), m.getSizeInCellsY());
|
||||
layer.updateCosts(m, 0, 0, m.getSizeInCellsX(), m.getSizeInCellsY());
|
||||
unsigned int a, b;
|
||||
EXPECT_TRUE(m.worldToMap(x, y, a, b));
|
||||
return m.getCost(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DepthCameraLayerTest, MarksAClusterInsideTheFrustum)
|
||||
{
|
||||
frame(object());
|
||||
EXPECT_EQ(layer.storedPoints(), 9u);
|
||||
EXPECT_EQ(master(), LETHAL_OBSTACLE);
|
||||
EXPECT_TRUE(layer.isCurrent());
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraLayerTest, SmallClusterAndOutOfHeightPointsAreNotMarked)
|
||||
{
|
||||
std::vector<Eigen::Vector3d> five = object();
|
||||
five.resize(5); // <= size_of_cluster_rejection
|
||||
frame(join(five, wall()));
|
||||
EXPECT_NE(master(), LETHAL_OBSTACLE);
|
||||
frame(join(object(1.02, .13, 1.5), wall())); // above max_obstacle_height
|
||||
EXPECT_NE(master(), LETHAL_OBSTACLE);
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraLayerTest, KeptWhileSeenAgainAndClearedWhenGone)
|
||||
{
|
||||
frame(join(object(), wall()));
|
||||
ASSERT_EQ(master(), LETHAL_OBSTACLE);
|
||||
for (int i = 0; i < 5; ++i)
|
||||
frame(join(object(), wall()));
|
||||
EXPECT_EQ(master(), LETHAL_OBSTACLE);
|
||||
frame(wall()); // no cloud point within check_radius of the stored points
|
||||
EXPECT_NE(master(), LETHAL_OBSTACLE);
|
||||
EXPECT_EQ(master(1.61, .11), LETHAL_OBSTACLE);
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraLayerTest, OutsideTheFrustumIsKept)
|
||||
{
|
||||
frame(object());
|
||||
ASSERT_EQ(master(), LETHAL_OBSTACLE);
|
||||
for (int i = 0; i < 5; ++i)
|
||||
frame({}, 1.57); // camera turned away, sees nothing
|
||||
EXPECT_EQ(master(), LETHAL_OBSTACLE);
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraLayerTest, NearlyEmptyCloudClearsEverythingInViewWithoutProtection)
|
||||
{
|
||||
frame(object());
|
||||
ASSERT_EQ(master(), LETHAL_OBSTACLE);
|
||||
frame({});
|
||||
EXPECT_NE(master(), LETHAL_OBSTACLE);
|
||||
}
|
||||
|
||||
class DepthCameraBlockedTest : public DepthCameraLayerTest
|
||||
{
|
||||
protected:
|
||||
void configure(YAML::Node& cfg) override
|
||||
{
|
||||
cfg["enable_near_blocked_protection"] = true;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DepthCameraBlockedTest, NearlyEmptyCloudSkipsClearingWithProtection)
|
||||
{
|
||||
frame(object());
|
||||
ASSERT_EQ(master(), LETHAL_OBSTACLE);
|
||||
for (int i = 0; i < 5; ++i)
|
||||
frame({});
|
||||
EXPECT_EQ(master(), LETHAL_OBSTACLE);
|
||||
frame(wall());
|
||||
EXPECT_NE(master(), LETHAL_OBSTACLE);
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraLayerTest, AttachBandIsNotMarked)
|
||||
{
|
||||
// 10 cm past the near plane (0.15 m) of a camera at x = 0: inside, but attached.
|
||||
frame(wall());
|
||||
const std::size_t wall_points = layer.storedPoints();
|
||||
ASSERT_GT(wall_points, 0u);
|
||||
frame(join(object(.25, .10, .19), wall()));
|
||||
EXPECT_EQ(layer.storedPoints(), wall_points);
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraLayerTest, WaitsForTheMeasurementTfThenDropsAfterTheTolerance)
|
||||
{
|
||||
frame(object(), 0, false); // no TF at this stamp yet
|
||||
EXPECT_EQ(layer.storedPoints(), 0u);
|
||||
const robot::Time stamp(100, tick * 10000000);
|
||||
ASSERT_TRUE(tf.setTransform(pose(stamp), "late_tf"));
|
||||
update();
|
||||
EXPECT_EQ(layer.storedPoints(), 9u);
|
||||
|
||||
frame(object(1.32, -.47, .3), 0, false);
|
||||
const robot::Time late(100, tick * 10000000);
|
||||
robot::Time::setNow(robot::Time(101, 0)); // older than transform_tolerance (0.2 s)
|
||||
update();
|
||||
ASSERT_TRUE(tf.setTransform(pose(late), "too_late_tf"));
|
||||
update();
|
||||
EXPECT_NE(master(1.31, -.44), LETHAL_OBSTACLE); // the waiting cloud was dropped
|
||||
EXPECT_EQ(layer.storedPoints(), 9u);
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraLayerTest, OtherTopicsAndDepthImagesAreIgnored)
|
||||
{
|
||||
const robot::Time stamp = next();
|
||||
robot::Time::setNow(stamp);
|
||||
ASSERT_TRUE(tf.setTransform(pose(stamp), "test"));
|
||||
layer.dataCallBack(cloud(stamp, object()), "/other/points");
|
||||
robot_sensor_msgs::DepthCameraData::ConstPtr depth = boost::make_shared<robot_sensor_msgs::DepthCameraData>();
|
||||
layer.dataCallBack(depth, kTopic);
|
||||
update();
|
||||
EXPECT_EQ(layer.storedPoints(), 0u);
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraLayerTest, MarkingsThatLeaveTheWindowAreDropped)
|
||||
{
|
||||
frame(object());
|
||||
ASSERT_EQ(layer.storedPoints(), 9u);
|
||||
layer.updateOrigin(10, 10); // the stored cells are outside the layer now
|
||||
Costmap2D& m = *parent.getCostmap();
|
||||
layer.updateCosts(m, 0, 0, m.getSizeInCellsX(), m.getSizeInCellsY());
|
||||
EXPECT_EQ(layer.storedPoints(), 0u);
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraLayerTest, ClearedPointsDoNotTouchTheBoundsByDefault)
|
||||
{
|
||||
frame(join(object(), wall()));
|
||||
frame(wall());
|
||||
EXPECT_GT(min_x, 1.5); // only the wall marking touched the bounds
|
||||
}
|
||||
|
||||
class DepthCameraTouchTest : public DepthCameraLayerTest
|
||||
{
|
||||
protected:
|
||||
void configure(YAML::Node& cfg) override
|
||||
{
|
||||
cfg["clear_touches_bounds"] = true;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DepthCameraTouchTest, ClearedPointsTouchTheBoundsWhenEnabled)
|
||||
{
|
||||
frame(join(object(), wall()));
|
||||
frame(wall());
|
||||
EXPECT_LT(min_x, 1.05); // the cleared object cell is reset in the master too
|
||||
}
|
||||
|
||||
TEST(DepthCameraLayerConfig, RejectsUnportedModeAndOutOfRangeValues)
|
||||
{
|
||||
tf3::BufferCore tf;
|
||||
LayeredCostmap parent{"odom", false, false};
|
||||
parent.getCostmap()->resizeMap(80, 80, .05, -2, -2);
|
||||
robot::NodeHandle nh("~");
|
||||
const auto expectThrow = [&](const YAML::Node& cfg) {
|
||||
nh.setParam("dcam_bad", cfg);
|
||||
DepthCameraObstacleLayer layer;
|
||||
EXPECT_THROW(layer.initialize(&parent, "dcam_bad", &tf), std::invalid_argument);
|
||||
};
|
||||
YAML::Node cfg = baseConfig();
|
||||
cfg["use_global_frame_to_mark"] = false;
|
||||
expectThrow(cfg);
|
||||
cfg = baseConfig();
|
||||
cfg["depth_cam"]["FOV_W"] = 3.5;
|
||||
expectThrow(cfg);
|
||||
cfg = baseConfig();
|
||||
cfg["depth_cam"]["min_detect_distance"] = 3.0;
|
||||
expectThrow(cfg);
|
||||
cfg = baseConfig();
|
||||
cfg["voxel_resolution"] = 0.0;
|
||||
expectThrow(cfg);
|
||||
}
|
||||
@@ -87,6 +87,22 @@ TEST(DepthEvidenceStore, EraseEraseIfClearAndNonFinite)
|
||||
EXPECT_EQ(store.size(), 0u);
|
||||
}
|
||||
|
||||
TEST(DepthEvidenceStore, MissCountRestartsOnMarkingAndLeavesWithTheVoxel)
|
||||
{
|
||||
DepthEvidenceStore store(8);
|
||||
const DepthEvidenceStore::VoxelKey key{1, 2, 3};
|
||||
EXPECT_FLOAT_EQ(store.addMiss(key, 1.f), 0.f); // no evidence, nothing to count
|
||||
store.add(key, Eigen::Vector3f(1.f, 2.f, .3f), false);
|
||||
EXPECT_FLOAT_EQ(store.addMiss(key, 1.f), 1.f);
|
||||
EXPECT_FLOAT_EQ(store.addMiss(key, .5f), 1.5f);
|
||||
store.add(key, Eigen::Vector3f(1.01f, 2.f, .3f), false); // marked again
|
||||
EXPECT_FLOAT_EQ(store.addMiss(key, 1.f), 1.f);
|
||||
store.resetMiss(key);
|
||||
EXPECT_FLOAT_EQ(store.addMiss(key, 1.f), 1.f);
|
||||
store.erase(key);
|
||||
EXPECT_FLOAT_EQ(store.addMiss(key, 1.f), 0.f);
|
||||
}
|
||||
|
||||
TEST(DepthEvidenceStore, CapacityIsClamped)
|
||||
{
|
||||
EXPECT_EQ(DepthEvidenceStore(2).pointsPerVoxel(), DepthEvidenceStore::kExtremeSlots);
|
||||
|
||||
@@ -247,7 +247,9 @@ TEST(DepthBuffer, RuntimeFactoryForwardsObservedVolumeModeAndPairsSources)
|
||||
YAML::LoadFile((runtime / "costmap_common_params.yaml").string())["obstacles"]["pc_clearing"];
|
||||
for (const char* key : {"depth_evidence_points_enabled", "depth_evidence_points_per_voxel",
|
||||
"depth_marking_border_px", "depth_projection_margin_px", "depth_valid_max_z_m",
|
||||
"depth_far_return_is_behind"})
|
||||
"depth_far_return_is_behind", "depth_reobserve_clearing", "depth_confirm_tolerance_m",
|
||||
"depth_miss_frames", "depth_no_return_weight", "depth_stereo_baseline_m",
|
||||
"depth_stereo_band_margin_px"})
|
||||
{
|
||||
ASSERT_TRUE(runtime_clearing[key].IsDefined()) << key;
|
||||
ASSERT_TRUE(settings.hasParam(key)) << key;
|
||||
|
||||
@@ -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