2014-11-06 54 views

回答

3

Gabor Meszaros的回答后编辑。

您会发现ROS C++ API参考(roscpp)here和 - 在Python中 - 您会在ros::master小节中找到getTopics方法。

下面是如何使用它的一个示例代码:

ros::master::V_TopicInfo master_topics; 
ros::master::getTopics(master_topics); 

for (ros::master::V_TopicInfo::iterator it = master_topics.begin() ; it != master_topics.end(); it++) { 
    const ros::master::TopicInfo& info = *it; 
    std::cout << "topic_" << it - master_topics.begin() << ": " << info.name << std::endl; 
} 
1

我不熟悉ROS API,是getTopics你正在寻找?

或者,您可以检查rostopic list(它是python,但可能与C++ API有重叠)的实现。你可以找到它here

+0

感谢您的回答!我更喜欢Alex给出的一个片段来介绍这个用法。 – 2014-11-07 11:34:50

+0

@ linzhang.robot如你所愿,我只是想帮忙。 :) – 2014-11-07 11:54:42

相关问题