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.
111 lines
4.1 KiB
C++
111 lines
4.1 KiB
C++
#include <robot_costmap_2d/depth_evidence_store.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
using robot_costmap_2d::DepthEvidenceStore;
|
|
|
|
namespace
|
|
{
|
|
bool contains(const std::vector<Eigen::Vector3d>& points, const Eigen::Vector3d& point)
|
|
{
|
|
return std::any_of(points.begin(), points.end(),
|
|
[&](const Eigen::Vector3d& p) { return (p - point).norm() < 1e-6; });
|
|
}
|
|
} // namespace
|
|
|
|
TEST(DepthEvidenceStore, FirstPointIsTheOnlyEvidence)
|
|
{
|
|
DepthEvidenceStore store(8);
|
|
std::vector<Eigen::Vector3d> points;
|
|
EXPECT_FALSE(store.points({1, 2, 3}, points));
|
|
store.add({1, 2, 3}, Eigen::Vector3f(1.f, 2.f, .3f), false);
|
|
ASSERT_TRUE(store.points({1, 2, 3}, points));
|
|
ASSERT_EQ(points.size(), 1u);
|
|
EXPECT_TRUE(contains(points, Eigen::Vector3d(1.0, 2.0, 0.3)));
|
|
EXPECT_FALSE(store.points({1, 2, 4}, points));
|
|
}
|
|
|
|
TEST(DepthEvidenceStore, KeepsAxisExtremesWhenFull)
|
|
{
|
|
DepthEvidenceStore store(6); // extremes only, no recent slots
|
|
const DepthEvidenceStore::VoxelKey key{0, 0, 0};
|
|
store.add(key, Eigen::Vector3f(.02f, .02f, .02f), false);
|
|
store.add(key, Eigen::Vector3f(.00f, .03f, .03f), false); // new min x
|
|
store.add(key, Eigen::Vector3f(.04f, .01f, .01f), false); // new max x, min y, min z
|
|
store.add(key, Eigen::Vector3f(.02f, .02f, .02f), false); // inside: changes nothing
|
|
std::vector<Eigen::Vector3d> points;
|
|
ASSERT_TRUE(store.points(key, points));
|
|
EXPECT_TRUE(contains(points, Eigen::Vector3d(.00, .03, .03)));
|
|
EXPECT_TRUE(contains(points, Eigen::Vector3d(.04, .01, .01)));
|
|
EXPECT_LE(points.size(), 6u);
|
|
}
|
|
|
|
TEST(DepthEvidenceStore, RecentSlotsRotate)
|
|
{
|
|
DepthEvidenceStore store(7); // one recent slot
|
|
const DepthEvidenceStore::VoxelKey key{0, 0, 0};
|
|
store.add(key, Eigen::Vector3f(.0f, .0f, .0f), false);
|
|
store.add(key, Eigen::Vector3f(.04f, .04f, .04f), false);
|
|
store.add(key, Eigen::Vector3f(.01f, .02f, .03f), false);
|
|
store.add(key, Eigen::Vector3f(.03f, .02f, .01f), false);
|
|
std::vector<Eigen::Vector3d> points;
|
|
ASSERT_TRUE(store.points(key, points));
|
|
EXPECT_TRUE(contains(points, Eigen::Vector3d(.03, .02, .01)));
|
|
EXPECT_FALSE(contains(points, Eigen::Vector3d(.01, .02, .03)));
|
|
}
|
|
|
|
TEST(DepthEvidenceStore, FreshVoxelDropsOldEvidence)
|
|
{
|
|
DepthEvidenceStore store(8);
|
|
const DepthEvidenceStore::VoxelKey key{5, -3, 2};
|
|
store.add(key, Eigen::Vector3f(1.f, 1.f, .2f), false);
|
|
store.add(key, Eigen::Vector3f(1.04f, 1.04f, .24f), true);
|
|
std::vector<Eigen::Vector3d> points;
|
|
ASSERT_TRUE(store.points(key, points));
|
|
ASSERT_EQ(points.size(), 1u);
|
|
EXPECT_TRUE(contains(points, Eigen::Vector3d(1.04, 1.04, .24)));
|
|
}
|
|
|
|
TEST(DepthEvidenceStore, EraseEraseIfClearAndNonFinite)
|
|
{
|
|
DepthEvidenceStore store(8);
|
|
store.add({0, 0, 0}, Eigen::Vector3f(0.f, 0.f, 0.f), false);
|
|
store.add({1, 0, 0}, Eigen::Vector3f(.05f, 0.f, 0.f), false);
|
|
store.add({2, 0, 0}, Eigen::Vector3f(.1f, 0.f, 0.f), false);
|
|
store.add({3, 0, 0}, Eigen::Vector3f(std::nanf(""), 0.f, 0.f), false);
|
|
EXPECT_EQ(store.size(), 3u);
|
|
store.erase({0, 0, 0});
|
|
EXPECT_EQ(store.size(), 2u);
|
|
store.eraseIf([](const DepthEvidenceStore::VoxelKey& key) { return key.x == 2; });
|
|
std::vector<Eigen::Vector3d> points;
|
|
EXPECT_TRUE(store.points({1, 0, 0}, points));
|
|
EXPECT_FALSE(store.points({2, 0, 0}, points));
|
|
store.clear();
|
|
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);
|
|
EXPECT_EQ(DepthEvidenceStore(100).pointsPerVoxel(), DepthEvidenceStore::kMaxPoints);
|
|
}
|