How to get ros topic message type by coding
I'm trying to write a node that read a config file, which includes topic names, then read the messages published to that topics. Currently, I can retrieve the message type like this:
ros::master::V_TopicInfo topic_list;
ros::master::getTopics(topic_list);
for (auto i : topic_list) {
if (i.name == "/battery_info") {
std::cout << "Data type is: " << i.datatype << std::endl;
}
}
But the datatype is a string, how can I convert this string to the equivalent type so that I can create a topic callback function, or is there another way, maybe written with Python code?
What is the overall goal of this task? Do you want to create a generic topic subscriber?
Thanks a lot, this is exactly what I'm looking for.
Glad you found it useful!