Skip to content

Commit b066a18

Browse files
Include option to use PointCloud Transport (#5264)
* Rebase Signed-off-by: ElSayed ElSheikh <[email protected]> * Make linters happy Signed-off-by: ElSayed ElSheikh <[email protected]> * Rename point_cloud_transport parameter Signed-off-by: ElSayed ElSheikh <[email protected]> * Rebase Signed-off-by: ElSayed ElSheikh <[email protected]> * Feedback Signed-off-by: ElSayed ElSheikh <[email protected]> * Feedback Signed-off-by: ElSayed ElSheikh <[email protected]> * Fix Signed-off-by: ElSayed ElSheikh <[email protected]> --------- Signed-off-by: ElSayed ElSheikh <[email protected]>
1 parent 2a377c3 commit b066a18

File tree

10 files changed

+52
-3
lines changed

10 files changed

+52
-3
lines changed

nav2_collision_monitor/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ find_package(tf2 REQUIRED)
1717
find_package(tf2_ros REQUIRED)
1818
find_package(visualization_msgs REQUIRED)
1919
find_package(nav2_ros_common REQUIRED)
20+
find_package(point_cloud_transport REQUIRED)
2021

2122
nav2_package()
2223

@@ -54,6 +55,7 @@ target_link_libraries(${monitor_library_name} PUBLIC
5455
tf2::tf2
5556
tf2_ros::tf2_ros
5657
${visualization_msgs_TARGETS}
58+
point_cloud_transport::point_cloud_transport
5759
)
5860
target_link_libraries(${monitor_library_name} PRIVATE
5961
rclcpp_components::component
@@ -88,6 +90,7 @@ target_link_libraries(${detector_library_name} PUBLIC
8890
tf2_ros::tf2_ros
8991
tf2::tf2
9092
${visualization_msgs_TARGETS}
93+
point_cloud_transport::point_cloud_transport
9194
)
9295
target_link_libraries(${detector_library_name} PRIVATE
9396
rclcpp_components::component
@@ -169,6 +172,7 @@ ament_export_dependencies(
169172
tf2_ros
170173
nav2_ros_common
171174
visualization_msgs
175+
point_cloud_transport
172176
)
173177
ament_export_targets(export_${PROJECT_NAME})
174178

nav2_collision_monitor/include/nav2_collision_monitor/pointcloud.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <string>
2121

2222
#include "sensor_msgs/msg/point_cloud2.hpp"
23+
#include "point_cloud_transport/point_cloud_transport.hpp"
2324

2425
#include "nav2_collision_monitor/source.hpp"
2526

@@ -98,7 +99,15 @@ class PointCloud : public Source
9899
// ----- Variables -----
99100

100101
/// @brief PointCloud data subscriber
102+
#if RCLCPP_VERSION_GTE(30, 0, 0)
103+
std::shared_ptr<point_cloud_transport::PointCloudTransport> pct_;
104+
point_cloud_transport::Subscriber data_sub_;
105+
#else
101106
nav2::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr data_sub_;
107+
#endif
108+
109+
// Transport type used for PointCloud messages (e.g., raw or compressed)
110+
std::string transport_type_;
102111

103112
// Minimum and maximum height of PointCloud projected to 2D space
104113
double min_height_, max_height_;

nav2_collision_monitor/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
<depend>tf2_ros</depend>
2626
<depend>visualization_msgs</depend>
2727
<depend>nav2_ros_common</depend>
28+
<depend>point_cloud_transport</depend>
29+
<depend>point_cloud_transport_plugins</depend>
2830

2931
<test_depend>ament_cmake_gtest</test_depend>
3032
<test_depend>ament_lint_common</test_depend>

nav2_collision_monitor/params/collision_detector_params.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ collision_detector:
2323
pointcloud:
2424
type: "pointcloud"
2525
topic: "/intel_realsense_r200_depth/points"
26+
transport_type: "raw" # Options: raw, zlib, draco, zstd
2627
min_height: 0.1
2728
max_height: 0.5
2829
enabled: True

nav2_collision_monitor/params/collision_monitor_params.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ collision_monitor:
9696
pointcloud:
9797
type: "pointcloud"
9898
topic: "/intel_realsense_r200_depth/points"
99+
transport_type: "raw" # Options: raw, zlib, draco, zstd
99100
min_height: 0.1
100101
max_height: 0.5
101102
enabled: True

nav2_collision_monitor/src/pointcloud.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ PointCloud::PointCloud(
4545
PointCloud::~PointCloud()
4646
{
4747
RCLCPP_INFO(logger_, "[%s]: Destroying PointCloud", source_name_.c_str());
48+
#if RCLCPP_VERSION_GTE(30, 0, 0)
49+
data_sub_.shutdown();
50+
#else
4851
data_sub_.reset();
52+
#endif
4953
}
5054

5155
void PointCloud::configure()
@@ -60,10 +64,20 @@ void PointCloud::configure()
6064

6165
getParameters(source_topic);
6266

67+
#if RCLCPP_VERSION_GTE(30, 0, 0)
68+
const point_cloud_transport::TransportHints hint(transport_type_);
69+
pct_ = std::make_shared<point_cloud_transport::PointCloudTransport>(*node);
70+
data_sub_ = pct_->subscribe(
71+
source_topic, nav2::qos::SensorDataQoS(),
72+
std::bind(&PointCloud::dataCallback, this, std::placeholders::_1),
73+
{}, &hint
74+
);
75+
#else
6376
data_sub_ = node->create_subscription<sensor_msgs::msg::PointCloud2>(
6477
source_topic,
6578
std::bind(&PointCloud::dataCallback, this, std::placeholders::_1),
6679
nav2::qos::SensorDataQoS());
80+
#endif
6781

6882
// Add callback for dynamic parameters
6983
dyn_params_handler_ = node->add_on_set_parameters_callback(
@@ -131,6 +145,9 @@ void PointCloud::getParameters(std::string & source_topic)
131145
nav2::declare_parameter_if_not_declared(
132146
node, source_name_ + ".min_range", rclcpp::ParameterValue(0.0));
133147
min_range_ = node->get_parameter(source_name_ + ".min_range").as_double();
148+
nav2::declare_parameter_if_not_declared(
149+
node, source_name_ + ".transport_type", rclcpp::ParameterValue(std::string("raw")));
150+
transport_type_ = node->get_parameter(source_name_ + ".transport_type").as_string();
134151
}
135152

136153
void PointCloud::dataCallback(sensor_msgs::msg::PointCloud2::ConstSharedPtr msg)

nav2_costmap_2d/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ find_package(tf2_ros REQUIRED)
2626
find_package(nav2_ros_common REQUIRED)
2727
find_package(tf2_sensor_msgs REQUIRED)
2828
find_package(visualization_msgs REQUIRED)
29+
find_package(point_cloud_transport REQUIRED)
2930

3031
nav2_package()
3132

@@ -88,6 +89,7 @@ target_link_libraries(layers PUBLIC
8889
nav2_ros_common::nav2_ros_common
8990
tf2::tf2
9091
nav2_ros_common::nav2_ros_common
92+
point_cloud_transport::point_cloud_transport
9193
)
9294
target_link_libraries(layers PRIVATE
9395
pluginlib::pluginlib
@@ -222,6 +224,7 @@ ament_export_dependencies(
222224
tf2_ros
223225
tf2_sensor_msgs
224226
nav2_ros_common
227+
point_cloud_transport
225228
)
226229
pluginlib_export_plugin_description_file(nav2_costmap_2d costmap_plugins.xml)
227230
ament_package()

nav2_costmap_2d/include/nav2_costmap_2d/obstacle_layer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#pragma GCC diagnostic pop
5252

5353
#include "message_filters/subscriber.hpp"
54+
#include "point_cloud_transport/subscriber_filter.hpp"
5455

5556
#include "nav_msgs/msg/occupancy_grid.hpp"
5657
#include "sensor_msgs/msg/laser_scan.hpp"

nav2_costmap_2d/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
<depend>tf2_sensor_msgs</depend>
4343
<depend>visualization_msgs</depend>
4444
<depend>nav2_ros_common</depend>
45+
<depend>point_cloud_transport</depend>
46+
<depend>point_cloud_transport_plugins</depend>
4547

4648
<test_depend>ament_lint_common</test_depend>
4749
<test_depend>ament_lint_auto</test_depend>

nav2_costmap_2d/plugins/obstacle_layer.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void ObstacleLayer::onInitialize()
141141
while (ss >> source) {
142142
// get the parameters for the specific topic
143143
double observation_keep_time, expected_update_rate, min_obstacle_height, max_obstacle_height;
144-
std::string topic, sensor_frame, data_type;
144+
std::string topic, sensor_frame, data_type, transport_type;
145145
bool inf_is_valid, clearing, marking;
146146

147147
declareParameter(source + "." + "topic", rclcpp::ParameterValue(source));
@@ -158,6 +158,7 @@ void ObstacleLayer::onInitialize()
158158
declareParameter(source + "." + "obstacle_min_range", rclcpp::ParameterValue(0.0));
159159
declareParameter(source + "." + "raytrace_max_range", rclcpp::ParameterValue(3.0));
160160
declareParameter(source + "." + "raytrace_min_range", rclcpp::ParameterValue(0.0));
161+
declareParameter(source + "." + "transport_type", rclcpp::ParameterValue(std::string("raw")));
161162

162163
node->get_parameter(name_ + "." + source + "." + "topic", topic);
163164
node->get_parameter(name_ + "." + source + "." + "sensor_frame", sensor_frame);
@@ -173,6 +174,7 @@ void ObstacleLayer::onInitialize()
173174
node->get_parameter(name_ + "." + source + "." + "inf_is_valid", inf_is_valid);
174175
node->get_parameter(name_ + "." + source + "." + "marking", marking);
175176
node->get_parameter(name_ + "." + source + "." + "clearing", clearing);
177+
node->get_parameter(name_ + "." + source + "." + "transport_type", transport_type);
176178

177179
if (!(data_type == "PointCloud2" || data_type == "LaserScan")) {
178180
RCLCPP_FATAL(
@@ -287,16 +289,23 @@ void ObstacleLayer::onInitialize()
287289
tf_filter_tolerance));
288290

289291
} else {
292+
// For Rolling and Newer Support from PointCloudTransport API change
293+
#if RCLCPP_VERSION_GTE(30, 0, 0)
294+
std::shared_ptr<point_cloud_transport::SubscriberFilter> sub;
290295
// For Kilted and Older Support from Message Filters API change
291-
#if RCLCPP_VERSION_GTE(29, 6, 0)
296+
#elif RCLCPP_VERSION_GTE(29, 6, 0)
292297
std::shared_ptr<message_filters::Subscriber<sensor_msgs::msg::PointCloud2>> sub;
293298
#else
294299
std::shared_ptr<message_filters::Subscriber<sensor_msgs::msg::PointCloud2,
295300
rclcpp_lifecycle::LifecycleNode>> sub;
296301
#endif
297302

303+
// For Rolling compatibility in PointCloudTransport API change
304+
#if RCLCPP_VERSION_GTE(30, 0, 0)
305+
sub = std::make_shared<point_cloud_transport::SubscriberFilter>(
306+
*node, topic, transport_type, custom_qos_profile, sub_opt);
298307
// For Kilted compatibility in Message Filters API change
299-
#if RCLCPP_VERSION_GTE(29, 6, 0)
308+
#elif RCLCPP_VERSION_GTE(29, 6, 0)
300309
sub = std::make_shared<message_filters::Subscriber<sensor_msgs::msg::PointCloud2>>(
301310
node, topic, custom_qos_profile, sub_opt);
302311
// For Jazzy compatibility in Message Filters API change

0 commit comments

Comments
 (0)