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

Get all topics in c++

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

nemo gravatar image

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

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
4

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

dornhege gravatar image

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

Yes, look at the Master API.

getPublishedTopics or getSystemState should do what you want.

edit flag offensive delete link more

Comments

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

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

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

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;
    }

    topics.clear();
    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

2 followers

Stats

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

Seen: 3,363 times

Last updated: Jan 24 '13