- ReferenceGraph / ReferenceGraphWorker: Voronoi ridges and one-way lanes are computed on a low-priority thread when the map changes (reference_graph_* keys, off with rolling_window), with unit tests. - Shared costmap keys can live in a root: map or flat at the top of the YAML; costmap_common_root_test covers both layouts. - Static and directional layers report map changes to the layered costmap.
99 lines
4.2 KiB
C++
99 lines
4.2 KiB
C++
#include <robot_costmap_2d/costmap_2d_robot.h>
|
|
|
|
#include <cstdlib>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
namespace
|
|
{
|
|
using robot_costmap_2d::Costmap2DROBOT;
|
|
|
|
TEST(CostmapCommonParameters, SelectAndCopySharedValues)
|
|
{
|
|
const char* layout = std::getenv("COSTMAP_TEST_LAYOUT");
|
|
ASSERT_NE(layout, nullptr);
|
|
const std::string expected_layout(layout);
|
|
ASSERT_TRUE(expected_layout == "rooted" || expected_layout == "flat");
|
|
ASSERT_NE(std::getenv("PNKX_NAV_CORE_CONFIG_DIR"), nullptr);
|
|
|
|
robot::NodeHandle tree_nh("~");
|
|
EXPECT_EQ(tree_nh.hasParam("root"), expected_layout == "rooted");
|
|
robot::NodeHandle common_nh = Costmap2DROBOT::commonParametersHandle(tree_nh);
|
|
|
|
double tolerance = 0.0;
|
|
ASSERT_TRUE(common_nh.getParam("transform_tolerance", tolerance));
|
|
EXPECT_DOUBLE_EQ(tolerance, 1.0);
|
|
std::string frame;
|
|
ASSERT_TRUE(common_nh.getParam("robot_base_frame", frame));
|
|
EXPECT_EQ(frame, "base_link");
|
|
|
|
Costmap2DROBOT::copyParentParameters("local_costmap", "obstacles", "VoxelLayer", common_nh, tree_nh);
|
|
Costmap2DROBOT::copyParentParameters("global_costmap", "obstacles", "VoxelLayer", common_nh, tree_nh);
|
|
Costmap2DROBOT::copyParentParameters("local_costmap", "forbidden", "StaticLayer", common_nh, tree_nh);
|
|
Costmap2DROBOT::copyParentParameters("global_costmap", "preferred", "PreferredLayer", common_nh, tree_nh);
|
|
|
|
std::string value;
|
|
ASSERT_TRUE(tree_nh.getParam("local_costmap/obstacles/observation_sources", value));
|
|
EXPECT_EQ(value, "f_scan b_scan");
|
|
ASSERT_TRUE(tree_nh.getParam("local_costmap/obstacles/f_scan/topic", value));
|
|
EXPECT_EQ(value, "/f_scan");
|
|
ASSERT_TRUE(tree_nh.getParam("local_costmap/forbidden/map_topic", value));
|
|
EXPECT_EQ(value, "forbidden");
|
|
ASSERT_TRUE(tree_nh.getParam("global_costmap/preferred/map_topic", value));
|
|
EXPECT_EQ(value, "preferred");
|
|
|
|
int voxels = 0;
|
|
double resolution = 0.0;
|
|
ASSERT_TRUE(tree_nh.getParam("global_costmap/obstacles/z_voxels", voxels));
|
|
EXPECT_EQ(voxels, 10);
|
|
ASSERT_TRUE(tree_nh.getParam("global_costmap/obstacles/z_resolution", resolution));
|
|
EXPECT_DOUBLE_EQ(resolution, 0.2);
|
|
ASSERT_TRUE(tree_nh.getParam("local_costmap/obstacles/z_voxels", voxels));
|
|
EXPECT_EQ(voxels, 8);
|
|
ASSERT_TRUE(tree_nh.getParam("local_costmap/obstacles/z_resolution", resolution));
|
|
EXPECT_DOUBLE_EQ(resolution, 0.15);
|
|
}
|
|
|
|
TEST(CostmapCommonParameters, PreservesSourceOverridesAndFillsMissingSourceKeys)
|
|
{
|
|
robot::NodeHandle tree_nh("~");
|
|
robot::NodeHandle common_nh = Costmap2DROBOT::commonParametersHandle(tree_nh);
|
|
Costmap2DROBOT::copyParentParameters("override_costmap", "obstacles", "VoxelLayer", common_nh, tree_nh);
|
|
|
|
std::string value;
|
|
ASSERT_TRUE(tree_nh.getParam("override_costmap/obstacles/observation_sources", value));
|
|
EXPECT_EQ(value, "b_scan");
|
|
ASSERT_TRUE(tree_nh.getParam("override_costmap/obstacles/b_scan/topic", value));
|
|
EXPECT_EQ(value, "/local_override");
|
|
ASSERT_TRUE(tree_nh.getParam("override_costmap/obstacles/b_scan/data_type", value));
|
|
EXPECT_EQ(value, "LaserScan");
|
|
EXPECT_FALSE(tree_nh.hasParam("override_costmap/obstacles/f_scan/topic"));
|
|
}
|
|
|
|
TEST(CostmapCommonParameters, RejectsInvalidSharedTypeOnlyWhenCopied)
|
|
{
|
|
robot::NodeHandle tree_nh("~");
|
|
robot::NodeHandle common_nh = Costmap2DROBOT::commonParametersHandle(tree_nh);
|
|
EXPECT_THROW(Costmap2DROBOT::copyParentParameters("invalid_costmap", "bad_obstacles", "VoxelLayer",
|
|
common_nh, tree_nh), std::invalid_argument);
|
|
EXPECT_NO_THROW(Costmap2DROBOT::copyParentParameters("protected_costmap", "bad_obstacles", "VoxelLayer",
|
|
common_nh, tree_nh));
|
|
int voxels = 0;
|
|
ASSERT_TRUE(tree_nh.getParam("protected_costmap/bad_obstacles/z_voxels", voxels));
|
|
EXPECT_EQ(voxels, 12);
|
|
}
|
|
|
|
TEST(CostmapCommonParameters, CreatesMissingCostmapNamespace)
|
|
{
|
|
robot::NodeHandle tree_nh("~");
|
|
robot::NodeHandle common_nh = Costmap2DROBOT::commonParametersHandle(tree_nh);
|
|
ASSERT_FALSE(tree_nh.hasParam("missing_costmap"));
|
|
Costmap2DROBOT::copyParentParameters("missing_costmap", "forbidden", "StaticLayer", common_nh, tree_nh);
|
|
std::string topic;
|
|
ASSERT_TRUE(tree_nh.getParam("missing_costmap/forbidden/map_topic", topic));
|
|
EXPECT_EQ(topic, "forbidden");
|
|
}
|
|
} // namespace
|