0
$\begingroup$

Rosanswers logo

Hello,

I'm trying to adapt the Euclidean Cluster Extraction tutorial from PCL to work with ROS.

I can get the tutorial working as it should, my question is with handling the detected clusters.

My idea was to publish each cluster in a different topic so I can look at them separately in rviz. My question is how can I do that?

Currently I'm creating one publisher as a global variable, and using nodehandle.advertise<sensor_msgs::PointCloud2>() in main() to create a topic and publish on it. This means that I can only publish only one pointcloud through this.

Is it possible to create a number of publishers, unknown at compile time, since I don't know how many objects will be detected, that each publish on a different topic?

How else would you recommend I use/view the vector of PointClouds that get created by the cluster extraction? The tutorial extracts them to files, but I would rather view them in rviz somehow.


Originally posted by Barbas on ROS Answers with karma: 55 on 2013-10-29

Post score: 4

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You can just create multiple Publisher within your node dynamically. They don't need to be static variables.

As to viewing them: That might be annoying as you need to add an extra display for each. For clustering I'd rather send one point cloud with colors and choose a random color per cluster.


Originally posted by dornhege with karma: 31395 on 2013-10-29

This answer was ACCEPTED on the original site

Post score: 5


Original comments

Comment by Barbas on 2013-10-29:
But how can I get access to my nodehandler in the callback function, where the Publishers would be dynamically created? Is it possible to pass a reference to it in the callback?

Comment by dornhege on 2013-10-29:
If you mean the NodeHandle you can create those on the fly.

Comment by Barbas on 2013-10-29:
OK what I've tried now is:

-Create a vector of publishers inside the callback function. -In a for loop initialize the publishers, using nodehandle.advertise<sensor_msgs::PointCloud2>() -Convert the cluster clouds to ros, and publish them. My problem is that apart from the first publisher, all the other publishers do not receive messages.

Is there some other way to publish the different clouds in different topics?

Comment by dornhege on 2013-10-29:
If you publish immediately after creating, there won't be a connection yet. Try waiting until getNumSubscribers is > 0 or create a bunch of publishers ahead.

Comment by Barbas on 2013-10-29:
Thanks, for the help, got it working now. Here a gist of the code, if anyone wants to take a look:

https://gist.github.com/Barbas/7220227

Comment by Tanmay on 2015-08-21:
Sorry, I know this is a really old post, but would you happen to have that code available? @Barbas

Comment by kerollosghobrial on 2015-10-31:
hello Barbas, i want use your concept for publishing unknown topic, can you send your code again because this link does not work. thanks in advance.

Comment by alfan on 2020-05-27:
i know its very old post, but can i see your code please? i'm facing the same problem right now

Comment by alfan on 2020-05-27:
this is the code

https://gist.githubusercontent.com/Barbas/7220227/raw/ec0f2231ba4f1999200da7cda87e23dfb7141622/cluster_extraction.cpp

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.