Skip to content

Commit 01095d4

Browse files
committed
input any number of point cloud topics
1 parent c003623 commit 01095d4

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

octomap_server/include/octomap_server/octomap_server.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ class OctomapServer : public rclcpp::Node
123123
virtual bool openFile(const std::string & filename);
124124

125125
protected:
126+
/// Add an input point cloud topic
127+
void addCloudTopic(const std::string & topic);
128+
126129
inline static void updateMinKey(const octomap::OcTreeKey & in, octomap::OcTreeKey & min)
127130
{
128131
for (size_t i = 0; i < 3; ++i) {
@@ -247,8 +250,8 @@ class OctomapServer : public rclcpp::Node
247250
rclcpp::Publisher<PointCloud2>::SharedPtr point_cloud_pub_;
248251
rclcpp::Publisher<OccupancyGrid>::SharedPtr map_pub_;
249252
rclcpp::Publisher<MarkerArray>::SharedPtr fmarker_pub_;
250-
message_filters::Subscriber<PointCloud2> point_cloud_sub_;
251-
std::shared_ptr<tf2_ros::MessageFilter<PointCloud2>> tf_point_cloud_sub_;
253+
std::vector<std::shared_ptr<message_filters::Subscriber<PointCloud2>>> point_cloud_subs_;
254+
std::vector<std::shared_ptr<tf2_ros::MessageFilter<PointCloud2>>> tf_point_cloud_subs_;
252255
rclcpp::Service<OctomapSrv>::SharedPtr octomap_binary_srv_;
253256
rclcpp::Service<OctomapSrv>::SharedPtr octomap_full_srv_;
254257
rclcpp::Service<BBoxSrv>::SharedPtr clear_bbox_srv_;

octomap_server/src/octomap_server.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
338352
bool OctomapServer::openFile(const std::string & filename)
339353
{
340354
if (filename.length() <= 3) {

0 commit comments

Comments
 (0)