Skip to content

Commit a27e166

Browse files
authored
test: fix the tests on ROS 2 Lyrical (#552)
1 parent 821bdd4 commit a27e166

5 files changed

Lines changed: 25 additions & 28 deletions

File tree

‎grid_map_costmap_2d/test/test_costmap_2d_converter.cpp‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ class TestCostmap2DConversion
4040
const nav2_costmap_2d::Costmap2D & costMap)
4141
{
4242
// Check map info.
43-
// Different conventions: Costmap2d returns the *centerpoint* of the last cell in the map.
44-
grid_map::Length length =
45-
gridMap.getLength() - grid_map::Length::Constant(0.5 * gridMap.getResolution());
43+
grid_map::Length length = gridMap.getLength();
4644
grid_map::Length position = gridMap.getPosition() - 0.5 * gridMap.getLength().matrix();
4745
EXPECT_EQ(costMap.getSizeInMetersX(), length.x());
4846
EXPECT_EQ(costMap.getSizeInMetersY(), length.y());

‎grid_map_costmap_2d/test/test_costmap_2d_ros.cpp‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
#include "rclcpp/rclcpp.hpp"
1313

14-
#include "tf2_ros/transform_broadcaster.h"
15-
#include "tf2/transform_datatypes.h"
14+
#include "tf2_ros/transform_broadcaster.hpp"
15+
#include "tf2/transform_datatypes.hpp"
1616

1717
#include "test_costmap_2d_ros.hpp"
1818

@@ -63,22 +63,22 @@ ROSCostmapServer::ROSCostmapServer(
6363
: tfBuffer_(node_->get_clock()),
6464
tfListener_(tfBuffer_)
6565
{
66-
// lots of parameters here affect the construction ( e.g. rolling window)
67-
// if you don't have any parameters set, then this
68-
// - alot of defaults which get dumped on the ros param server
69-
// - fires up an obstacle layer and an inflation layer
70-
// - creates a publisher for an occupancy grid
71-
72-
costmap_ = std::make_shared<ROSCostmap>(name);
73-
costmap_->set_parameter(rclcpp::Parameter{"plugins", std::vector<std::string>()});
74-
costmap_->set_parameter(rclcpp::Parameter{"robot_base_frame", baseLinkTransformName});
75-
costmap_->set_parameter(rclcpp::Parameter{"origin_x", origin.x()});
76-
costmap_->set_parameter(rclcpp::Parameter{"origin_y", origin.y()});
77-
costmap_->set_parameter(rclcpp::Parameter{"width", width});
78-
costmap_->set_parameter(rclcpp::Parameter{"height", height});
79-
costmap_->set_parameter(rclcpp::Parameter{"resolution", 0.5});
80-
// clears 1 cell if inside, up to 4 cells on a vertex
81-
costmap_->set_parameter(rclcpp::Parameter{"robot_radius", 0.03});
66+
// Costmap2DROS declares most parameters in on_configure(), so set them as overrides.
67+
// Only the NodeOptions constructor keeps the overrides.
68+
rclcpp::NodeOptions options;
69+
options.arguments({"--ros-args", "-r", "__node:=" + name, "-r", "__ns:=/" + name});
70+
options.parameter_overrides({
71+
{"plugins", std::vector<std::string>()},
72+
{"robot_base_frame", baseLinkTransformName},
73+
{"origin_x", origin.x()},
74+
{"origin_y", origin.y()},
75+
{"width", width},
76+
{"height", height},
77+
{"resolution", 0.5},
78+
// clears 1 cell if inside, up to 4 cells on a vertex
79+
{"robot_radius", 0.03},
80+
});
81+
costmap_ = std::make_shared<ROSCostmap>(options);
8282

8383
costmap_->configure();
8484
costmap_->activate();

‎grid_map_costmap_2d/test/test_costmap_2d_ros.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include "rclcpp/rclcpp.hpp"
1717

18-
#include "tf2_ros/transform_listener.h"
18+
#include "tf2_ros/transform_listener.hpp"
1919
#include "geometry_msgs/msg/transform.hpp"
2020
#include "geometry_msgs/msg/vector3.hpp"
2121
#include "geometry_msgs/msg/quaternion.hpp"

‎grid_map_pcl/test/test_helpers.cpp‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Institute: ETH Zurich, Robotic Systems Lab
77
*/
88

9-
#include <ament_index_cpp/get_package_share_directory.hpp>
9+
#include <ament_index_cpp/get_package_share_path.hpp>
1010

1111
#include <string>
1212
#include <vector>
@@ -29,8 +29,8 @@ std::string getConfigFilePath()
2929

3030
std::string getTestDataFolderPath()
3131
{
32-
std::string dir = ament_index_cpp::get_package_share_directory("grid_map_pcl") +
33-
"/test_data";
32+
const auto sharePath = ament_index_cpp::get_package_share_path("grid_map_pcl");
33+
std::string dir = (sharePath / "test_data").string();
3434
return dir;
3535
}
3636

@@ -195,8 +195,8 @@ Pointcloud::Ptr createStepTerrain(
195195

196196
std::string getTestPcdFilePath()
197197
{
198-
std::string filename = ament_index_cpp::get_package_share_directory("grid_map_pcl") +
199-
"/test_data/plane_noisy.pcd";
198+
const auto sharePath = ament_index_cpp::get_package_share_path("grid_map_pcl");
199+
std::string filename = (sharePath / "test_data" / "plane_noisy.pcd").string();
200200
return filename;
201201
}
202202

‎grid_map_pcl/test/test_helpers.hpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <Eigen/Core>
1313
#include <pcl/common/common.h>
14-
#include <ament_index_cpp/get_package_share_directory.hpp>
1514
#include <string>
1615
#include <vector>
1716
#include <random>

0 commit comments

Comments
 (0)