Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions nav2_costmap_2d/include/nav2_costmap_2d/testing_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,30 @@ unsigned int countValues(
return count;
}

nav2_costmap_2d::StaticLayer * addStaticLayer(
std::shared_ptr<nav2_costmap_2d::StaticLayer> addStaticLayer(
nav2_costmap_2d::LayeredCostmap & layers,
tf2_ros::Buffer & tf, nav2_util::LifecycleNode::SharedPtr node)
{
nav2_costmap_2d::StaticLayer * slayer = new nav2_costmap_2d::StaticLayer();
std::shared_ptr<nav2_costmap_2d::StaticLayer> slayer =
std::make_shared<nav2_costmap_2d::StaticLayer>();
layers.addPlugin(std::shared_ptr<nav2_costmap_2d::Layer>(slayer));
slayer->initialize(&layers, "static", &tf, node, nullptr, nullptr /*TODO*/);
return slayer;
}

nav2_costmap_2d::ObstacleLayer * addObstacleLayer(
std::shared_ptr<nav2_costmap_2d::ObstacleLayer> addObstacleLayer(
nav2_costmap_2d::LayeredCostmap & layers,
tf2_ros::Buffer & tf, nav2_util::LifecycleNode::SharedPtr node)
{
nav2_costmap_2d::ObstacleLayer * olayer = new nav2_costmap_2d::ObstacleLayer();
std::shared_ptr<nav2_costmap_2d::ObstacleLayer> olayer =
std::make_shared<nav2_costmap_2d::ObstacleLayer>();
olayer->initialize(&layers, "obstacles", &tf, node, nullptr, nullptr /*TODO*/);
layers.addPlugin(std::shared_ptr<nav2_costmap_2d::Layer>(olayer));
return olayer;
}

void addObservation(
nav2_costmap_2d::ObstacleLayer * olayer, double x, double y, double z = 0.0,
std::shared_ptr<nav2_costmap_2d::ObstacleLayer> & olayer, double x, double y, double z = 0.0,
double ox = 0.0, double oy = 0.0, double oz = MAX_Z)
{
sensor_msgs::msg::PointCloud2 cloud;
Expand All @@ -122,11 +124,12 @@ void addObservation(
olayer->addStaticObservation(obs, true, true);
}

nav2_costmap_2d::InflationLayer * addInflationLayer(
std::shared_ptr<nav2_costmap_2d::InflationLayer> addInflationLayer(
nav2_costmap_2d::LayeredCostmap & layers,
tf2_ros::Buffer & tf, nav2_util::LifecycleNode::SharedPtr node)
{
nav2_costmap_2d::InflationLayer * ilayer = new nav2_costmap_2d::InflationLayer();
std::shared_ptr<nav2_costmap_2d::InflationLayer> ilayer =
std::make_shared<nav2_costmap_2d::InflationLayer>();
ilayer->initialize(&layers, "inflation", &tf, node, nullptr, nullptr /*TODO*/);
std::shared_ptr<nav2_costmap_2d::Layer> ipointer(ilayer);
layers.addPlugin(ipointer);
Expand Down
26 changes: 13 additions & 13 deletions nav2_costmap_2d/test/integration/inflation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ class TestNode : public ::testing::Test
void validatePointInflation(
unsigned int mx, unsigned int my,
nav2_costmap_2d::Costmap2D * costmap,
nav2_costmap_2d::InflationLayer * ilayer,
std::shared_ptr<nav2_costmap_2d::InflationLayer> & ilayer,
double inflation_radius);

void initNode(double inflation_radius);

void waitForMap(nav2_costmap_2d::StaticLayer * slayer);
void waitForMap(std::shared_ptr<nav2_costmap_2d::StaticLayer> & slayer);

protected:
nav2_util::LifecycleNode::SharedPtr node_;
Expand Down Expand Up @@ -106,7 +106,7 @@ std::vector<Point> TestNode::setRadii(
return polygon;
}

void TestNode::waitForMap(nav2_costmap_2d::StaticLayer * slayer)
void TestNode::waitForMap(std::shared_ptr<nav2_costmap_2d::StaticLayer> & slayer)
{
while (!slayer->isCurrent()) {
rclcpp::spin_some(node_->get_node_base_interface());
Expand All @@ -117,7 +117,7 @@ void TestNode::waitForMap(nav2_costmap_2d::StaticLayer * slayer)
void TestNode::validatePointInflation(
unsigned int mx, unsigned int my,
nav2_costmap_2d::Costmap2D * costmap,
nav2_costmap_2d::InflationLayer * ilayer,
std::shared_ptr<nav2_costmap_2d::InflationLayer> & ilayer,
double inflation_radius)
{
bool * seen = new bool[costmap->getSizeInCellsX() * costmap->getSizeInCellsY()];
Expand Down Expand Up @@ -206,7 +206,7 @@ TEST_F(TestNode, testAdjacentToObstacleCanStillMove)
// circumscribed radius = 3.1
std::vector<Point> polygon = setRadii(layers, 2.1, 2.3);

nav2_costmap_2d::ObstacleLayer * olayer = addObstacleLayer(layers, tf, node_);
auto olayer = addObstacleLayer(layers, tf, node_);
addInflationLayer(layers, tf, node_);
layers.setFootprint(polygon);

Expand Down Expand Up @@ -234,7 +234,7 @@ TEST_F(TestNode, testInflationShouldNotCreateUnknowns)
// circumscribed radius = 3.1
std::vector<Point> polygon = setRadii(layers, 2.1, 2.3);

nav2_costmap_2d::ObstacleLayer * olayer = addObstacleLayer(layers, tf, node_);
auto olayer = addObstacleLayer(layers, tf, node_);
addInflationLayer(layers, tf, node_);
layers.setFootprint(polygon);

Expand All @@ -260,8 +260,8 @@ TEST_F(TestNode, testCostFunctionCorrectness)
// circumscribed radius = 8.0
std::vector<Point> polygon = setRadii(layers, 5.0, 6.25);

nav2_costmap_2d::ObstacleLayer * olayer = addObstacleLayer(layers, tf, node_);
nav2_costmap_2d::InflationLayer * ilayer = addInflationLayer(layers, tf, node_);
auto olayer = addObstacleLayer(layers, tf, node_);
auto ilayer = addInflationLayer(layers, tf, node_);
layers.setFootprint(polygon);

addObservation(olayer, 50, 50, MAX_Z);
Expand Down Expand Up @@ -331,8 +331,8 @@ TEST_F(TestNode, testInflationOrderCorrectness)
// circumscribed radius = 3.1
std::vector<Point> polygon = setRadii(layers, 2.1, 2.3);

nav2_costmap_2d::ObstacleLayer * olayer = addObstacleLayer(layers, tf, node_);
nav2_costmap_2d::InflationLayer * ilayer = addInflationLayer(layers, tf, node_);
auto olayer = addObstacleLayer(layers, tf, node_);
auto ilayer = addInflationLayer(layers, tf, node_);
layers.setFootprint(polygon);

// Add two diagonal cells, they would induce problems under the
Expand Down Expand Up @@ -360,7 +360,7 @@ TEST_F(TestNode, testInflation)
std::vector<Point> polygon = setRadii(layers, 1, 1);

auto slayer = addStaticLayer(layers, tf, node_);
nav2_costmap_2d::ObstacleLayer * olayer = addObstacleLayer(layers, tf, node_);
auto olayer = addObstacleLayer(layers, tf, node_);
addInflationLayer(layers, tf, node_);
layers.setFootprint(polygon);

Expand Down Expand Up @@ -433,7 +433,7 @@ TEST_F(TestNode, testInflation2)
std::vector<Point> polygon = setRadii(layers, 1, 1);

auto slayer = addStaticLayer(layers, tf, node_);
nav2_costmap_2d::ObstacleLayer * olayer = addObstacleLayer(layers, tf, node_);
auto olayer = addObstacleLayer(layers, tf, node_);
addInflationLayer(layers, tf, node_);
layers.setFootprint(polygon);

Expand Down Expand Up @@ -464,7 +464,7 @@ TEST_F(TestNode, testInflation3)
// 1 2 3
std::vector<Point> polygon = setRadii(layers, 1, 1.75);

nav2_costmap_2d::ObstacleLayer * olayer = addObstacleLayer(layers, tf, node_);
auto olayer = addObstacleLayer(layers, tf, node_);
addInflationLayer(layers, tf, node_);
layers.setFootprint(polygon);

Expand Down
12 changes: 6 additions & 6 deletions nav2_costmap_2d/test/integration/obstacle_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ TEST_F(TestNode, testRaytracing) {

nav2_costmap_2d::LayeredCostmap layers("frame", false, false);
addStaticLayer(layers, tf, node_);
nav2_costmap_2d::ObstacleLayer * olayer = addObstacleLayer(layers, tf, node_);
auto olayer = addObstacleLayer(layers, tf, node_);

// Add a point at 0, 0, 0
addObservation(olayer, 0.0, 0.0, MAX_Z / 2, 0, 0, MAX_Z / 2);
Expand All @@ -179,7 +179,7 @@ TEST_F(TestNode, testRaytracing2) {
tf2_ros::Buffer tf(node_->get_clock());
nav2_costmap_2d::LayeredCostmap layers("frame", false, false);
addStaticLayer(layers, tf, node_);
nav2_costmap_2d::ObstacleLayer * olayer = addObstacleLayer(layers, tf, node_);
auto olayer = addObstacleLayer(layers, tf, node_);

// If we print map now, it is 10x10 all value 0
// printMap(*(layers.getCostmap()));
Expand Down Expand Up @@ -236,7 +236,7 @@ TEST_F(TestNode, testWaveInterference) {
// Start with an empty map, no rolling window, tracking unknown
nav2_costmap_2d::LayeredCostmap layers("frame", false, true);
layers.resizeMap(10, 10, 1, 0, 0);
nav2_costmap_2d::ObstacleLayer * olayer = addObstacleLayer(layers, tf, node_);
auto olayer = addObstacleLayer(layers, tf, node_);

// If we print map now, it is 10x10, all cells are 255 (NO_INFORMATION)
// printMap(*(layers.getCostmap()));
Expand Down Expand Up @@ -265,7 +265,7 @@ TEST_F(TestNode, testZThreshold) {
nav2_costmap_2d::LayeredCostmap layers("frame", false, true);
layers.resizeMap(10, 10, 1, 0, 0);

nav2_costmap_2d::ObstacleLayer * olayer = addObstacleLayer(layers, tf, node_);
auto olayer = addObstacleLayer(layers, tf, node_);

// A point cloud with 2 points falling in a cell with a non-lethal cost
addObservation(olayer, 0.0, 5.0, 0.4);
Expand All @@ -285,7 +285,7 @@ TEST_F(TestNode, testDynamicObstacles) {
nav2_costmap_2d::LayeredCostmap layers("frame", false, false);
addStaticLayer(layers, tf, node_);

nav2_costmap_2d::ObstacleLayer * olayer = addObstacleLayer(layers, tf, node_);
auto olayer = addObstacleLayer(layers, tf, node_);

// Add a point cloud and verify its insertion. There should be only one new one
addObservation(olayer, 0.0, 0.0);
Expand All @@ -310,7 +310,7 @@ TEST_F(TestNode, testMultipleAdditions) {
nav2_costmap_2d::LayeredCostmap layers("frame", false, false);
addStaticLayer(layers, tf, node_);

nav2_costmap_2d::ObstacleLayer * olayer = addObstacleLayer(layers, tf, node_);
auto olayer = addObstacleLayer(layers, tf, node_);

// A point cloud with one point that falls within an existing obstacle
addObservation(olayer, 9.5, 0.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ INSTANTIATE_TEST_CASE_P(
std::make_tuple(M_PIf32, 0.1),
std::make_tuple(3.0 * M_PIf32 / 2.0, 0.15),
std::make_tuple(-2.0 * M_PIf32, 0.1),
std::make_tuple(4.0 * M_PIf32, 0.15)), );
std::make_tuple(4.0 * M_PIf32, 0.15)),
testing::PrintToStringParamName());

int main(int argc, char ** argv)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ INSTANTIATE_TEST_CASE_P(
::testing::Values(
std::make_tuple(1.0, 0.0),
std::make_tuple(2.0, 0.0),
std::make_tuple(5.0, 0.0)), );
std::make_tuple(5.0, 0.0)),
testing::PrintToStringParamName());

int main(int argc, char ** argv)
{
Expand Down