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

How to subscribe to uknown amount of topics with unknown type.

asked 2018-09-19 08:39:38 -0600

Kliffu gravatar image

updated 2018-09-19 11:58:17 -0600

ahendrix gravatar image

I am trying to make a lognode which reads the available topics and types, use this information in a GUI to select the topics you want to save. After the selection of topics I would like to subscribe to these topics and save the data in a .csv file.

I have been searching for a while how to subscribe to an unknown amount of topics with unknown types. Does anyone have ever made it or knows how to do this to get me in the right direction!

For example from the tutorials:

void chatterCallback(const std_msgs::String::ConstPtr& msg)

ROS_INFO("I heard: [%s]", msg->data.c_str());

int main(int argc, char **argv)

  ros::init(argc, argv, "listener");

 ros::NodeHandle n;

  ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);


  return 0;

Do I have to make an uknown amound of void newCallbacks? Or can I do this anotherway? If we can make an uknown amount of callbacks for an unkown topic and type, how can I do this?

I hope my question is clear! If not, please ask! Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-09-19 13:14:47 -0600

updated 2018-09-20 14:09:56 -0600

The ROS Master_API will probably be your friend. Please also look at #q260633, which covers parts of your question.

With getPublishedTopics you can create a list of all available topics. Then use getTopicTypes to create the subscribers accordingly.

You might find a good code example for subscribers to unknown topic types in the source code of rostopic echo.

edit flag offensive delete link more


Andre Volk gravatar image Andre Volk  ( 2018-09-19 13:27:16 -0600 )edit

Hi Andre! Thank you for your answer. Right now I can already get the topics and its types in the node by using getTopics and types. But it is very hard to make a unknown amount of subscribers with different for the unknown topics and types.

Kliffu gravatar image Kliffu  ( 2018-09-24 03:30:56 -0600 )edit

I want the node to be able the data of the topics in a .csv file which you choose in a GUI from al published topics. In addition this node has to be compatible with any e.g. robot and user.

Kliffu gravatar image Kliffu  ( 2018-09-24 03:32:59 -0600 )edit

Hey Kliffu Did you get any way to do it?

rohitsuri gravatar image rohitsuri  ( 2018-10-16 03:35:30 -0600 )edit

Question Tools



Asked: 2018-09-19 08:39:38 -0600

Seen: 895 times

Last updated: Sep 20 '18