@@ -112,6 +112,9 @@ OctomapServer::OctomapServer(const rclcpp::NodeOptions & node_options)
112112 min_x_size_ = declare_parameter (" min_x_size" , 0.0 );
113113 min_y_size_ = declare_parameter (" min_y_size" , 0.0 );
114114
115+ std::vector<std::string> cloud_topics =
116+ declare_parameter (" cloud_topics" , std::vector<std::string>());
117+
115118 {
116119 rcl_interfaces::msg::ParameterDescriptor filter_speckles_desc;
117120 filter_speckles_desc.description = " Filter speckle nodes (with no neighbors)" ;
@@ -308,13 +311,12 @@ OctomapServer::OctomapServer(const rclcpp::NodeOptions & node_options)
308311 tf2_listener_ =
309312 std::make_shared<tf2_ros::TransformListener>(*tf2_buffer_);
310313
311- using std::chrono_literals::operator " " s;
312- point_cloud_sub_.subscribe (this , " cloud_in" , rmw_qos_profile_sensor_data);
313- tf_point_cloud_sub_ = std::make_shared<tf2_ros::MessageFilter<PointCloud2>>(
314- point_cloud_sub_, *tf2_buffer_, world_frame_id_, 5 , this ->get_node_logging_interface (),
315- this ->get_node_clock_interface (), 5s);
316-
317- tf_point_cloud_sub_->registerCallback (&OctomapServer::insertCloudCallback, this );
314+ if (cloud_topics.size () == 0 ) {
315+ cloud_topics.push_back (" cloud_in" );
316+ }
317+ for (const std::string & topic : cloud_topics) {
318+ addCloudTopic (topic);
319+ }
318320
319321 octomap_binary_srv_ = create_service<OctomapSrv>(
320322 " octomap_binary" , std::bind (&OctomapServer::onOctomapBinarySrv, this , _1, _2));
@@ -335,6 +337,18 @@ OctomapServer::OctomapServer(const rclcpp::NodeOptions & node_options)
335337 }
336338}
337339
340+ void OctomapServer::addCloudTopic (const std::string & topic)
341+ {
342+ using std::chrono_literals::operator " " s;
343+ point_cloud_subs_.push_back (std::make_shared<message_filters::Subscriber<PointCloud2>>());
344+ point_cloud_subs_.back ()->subscribe (this , topic, rmw_qos_profile_sensor_data);
345+ tf_point_cloud_subs_.push_back (
346+ std::make_shared<tf2_ros::MessageFilter<PointCloud2>>(
347+ *point_cloud_subs_.back (), *tf2_buffer_, world_frame_id_, 5 ,
348+ this ->get_node_logging_interface (), this ->get_node_clock_interface (), 5s));
349+ tf_point_cloud_subs_.back ()->registerCallback (&OctomapServer::insertCloudCallback, this );
350+ }
351+
338352bool OctomapServer::openFile (const std::string & filename)
339353{
340354 if (filename.length () <= 3 ) {
0 commit comments