Skip to content

Commit

Permalink
added clearArea test
Browse files Browse the repository at this point in the history
Signed-off-by: alexander <[email protected]>
  • Loading branch information
alexanderjyuen committed Dec 9, 2024
1 parent ebd67ad commit 51798af
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions nav2_costmap_2d/test/integration/plugin_container_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,75 @@ TEST_F(TestNode, testResetting) {
ASSERT_EQ(ilayer_b->isCurrent(), false);
}

TEST_F(TestNode, testClearing) {
tf2_ros::Buffer tf(node_->get_clock());

node_->declare_parameter("pclayer_a.static.map_topic",
rclcpp::ParameterValue(std::string("map")));

node_->declare_parameter("pclayer_a.inflation.cost_scaling_factor",
rclcpp::ParameterValue(1.0));

node_->declare_parameter("pclayer_a.inflation.inflation_radius",
rclcpp::ParameterValue(1.0));

node_->declare_parameter("pclayer_b.inflation.cost_scaling_factor",
rclcpp::ParameterValue(1.0));

node_->declare_parameter("pclayer_b.inflation.inflation_radius",
rclcpp::ParameterValue(1.0));

nav2_costmap_2d::LayeredCostmap layers("frame", false, false);

layers.resizeMap(10, 10, 1, 0, 0);

std::shared_ptr<nav2_costmap_2d::PluginContainerLayer> pclayer_a = nullptr;
addPluginContainerLayer(layers, tf, node_, pclayer_a, "pclayer_a");

std::shared_ptr<nav2_costmap_2d::PluginContainerLayer> pclayer_b = nullptr;
addPluginContainerLayer(layers, tf, node_, pclayer_b, "pclayer_b");

std::shared_ptr<nav2_costmap_2d::StaticLayer> slayer =
std::make_shared<nav2_costmap_2d::StaticLayer>();
pclayer_a->addPlugin(slayer, "pclayer_a.static");

std::shared_ptr<nav2_costmap_2d::InflationLayer> ilayer_a =
std::make_shared<nav2_costmap_2d::InflationLayer>();
pclayer_a->addPlugin(ilayer_a, "pclayer_a.inflation");

std::shared_ptr<nav2_costmap_2d::ObstacleLayer> olayer_b =
std::make_shared<nav2_costmap_2d::ObstacleLayer>();
pclayer_b->addPlugin(olayer_b, "pclayer_b.obstacles");

std::shared_ptr<nav2_costmap_2d::InflationLayer> ilayer_b =
std::make_shared<nav2_costmap_2d::InflationLayer>();
pclayer_b->addPlugin(ilayer_b, "pclayer_a.inflation");

std::vector<geometry_msgs::msg::Point> polygon = setRadii(layers, 1, 1);
layers.setFootprint(polygon);

addObservation(olayer_b, 9.0, 9.0);

waitForMap(slayer);

layers.updateMap(0, 0, 0);

nav2_costmap_2d::Costmap2D * costmap = layers.getCostmap();

ASSERT_EQ(countValues(*costmap, nav2_costmap_2d::LETHAL_OBSTACLE), 21);
ASSERT_EQ(countValues(*costmap, nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE), 29);

pclayer_a->clearArea(-1, -1, 10, 10, false);
pclayer_b->clearArea(-1, -1, 10, 10, false);

layers.updateMap(0, 0, 0);

costmap = layers.getCostmap();

ASSERT_EQ(countValues(*costmap, nav2_costmap_2d::LETHAL_OBSTACLE), 1);
ASSERT_EQ(countValues(*costmap, nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE), 2);
}

TEST_F(TestNode, testOverwriteCombinationMethods) {
tf2_ros::Buffer tf(node_->get_clock());

Expand Down

0 comments on commit 51798af

Please sign in to comment.