ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
4

Publish unknown number of topics?

asked 2013-10-29 02:39:24 -0600

Barbas gravatar image

updated 2013-11-14 10:49:15 -0600

tfoote gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
5

answered 2013-10-29 04:09:48 -0600

dornhege gravatar image

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.

edit flag offensive delete link more

Comments

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?

Barbas gravatar image Barbas  ( 2013-10-29 05:51:50 -0600 )edit

If you mean the NodeHandle you can create those on the fly.

dornhege gravatar image dornhege  ( 2013-10-29 06:52:56 -0600 )edit

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?

Barbas gravatar image Barbas  ( 2013-10-29 08:11:41 -0600 )edit

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.

dornhege gravatar image dornhege  ( 2013-10-29 08:18:25 -0600 )edit
3

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

Barbas gravatar image Barbas  ( 2013-10-29 08:38:23 -0600 )edit

Sorry, I know this is a really old post, but would you happen to have that code available? @Barbas

Tanmay gravatar image Tanmay  ( 2015-08-21 05:50:36 -0600 )edit

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.

kerollosghobrial gravatar image kerollosghobrial  ( 2015-10-31 08:56:15 -0600 )edit

i know its very old post, but can i see your code please? i'm facing the same problem right now

alfan gravatar image alfan  ( 2020-05-27 02:26:06 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2013-10-29 02:39:24 -0600

Seen: 747 times

Last updated: May 27 '20