How to get ros topic message type by coding

asked 2022-09-28 21:34:18 -0600

Kevin1719 gravatar image

updated 2022-09-28 22:27:07 -0600

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;
for (auto i : topic_list) {
    if ( == "/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?

edit retag flag offensive close merge delete



What is the overall goal of this task? Do you want to create a generic topic subscriber?

ravijoshi gravatar image ravijoshi  ( 2022-09-29 04:46:25 -0600 )edit

Thanks a lot, this is exactly what I'm looking for.

Kevin1719 gravatar image Kevin1719  ( 2022-09-30 03:22:06 -0600 )edit

Glad you found it useful!

ravijoshi gravatar image ravijoshi  ( 2022-09-30 03:26:48 -0600 )edit