How to subscribe to uknown amount of topics with unknown type.
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);
ros::spin();
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.
Asked by Kliffu on 2018-09-19 08:39:38 UTC
Answers
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.
Asked by Andre Volk on 2018-09-19 13:14:47 UTC
Comments
Arrrr! (https://discourse.ros.org/t/answer-ros-questions-like-a-pirate-day-2k18/6058)
Asked by Andre Volk on 2018-09-19 13:27:16 UTC
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.
Asked by Kliffu on 2018-09-24 03:30:56 UTC
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.
Asked by Kliffu on 2018-09-24 03:32:59 UTC
Hey Kliffu Did you get any way to do it?
Asked by rohitsuri on 2018-10-16 03:35:30 UTC
Comments