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

Get all topics in c++

asked 2013-01-24 00:47:47 -0600

nemo gravatar image

updated 2014-01-28 17:14:58 -0600

ngrennan gravatar image

Hi everyone,

is there any way to do something like "rostopic list" or "rostopic find <msg_type>" NOT in a command line but in a C++ code and get the corresponding topics?

Thank you in advance

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-01-24 01:06:40 -0600

dornhege gravatar image

updated 2013-01-24 01:07:38 -0600

Yes, look at the Master API.

getPublishedTopics or getSystemState should do what you want.

edit flag offensive delete link more


do you have an c++ and/or python example for the command getPublishedTopics??????????

silgon gravatar image silgon  ( 2014-01-13 04:20:19 -0600 )edit

answered 2015-05-07 08:41:46 -0600

Gzork gravatar image

I got this one

bool getRosTopics(ros::master::V_TopicInfo& topics){
    XmlRpc::XmlRpcValue args, result, payload;
    args[0] = ros::this_node::getName();

    if (!ros::master::execute("getTopicTypes", args, result, payload, true)){
        std::cout << "Failed!" << std::endl;
        return false;

    for (int i = 0; i < payload.size(); ++i)
        topics.push_back(ros::master::TopicInfo(std::string(payload[i][0]), std::string(payload[i][1])));
    return true;
edit flag offensive delete link more

Question Tools



Asked: 2013-01-24 00:47:47 -0600

Seen: 3,359 times

Last updated: Jan 24 '13