Rosanswers logo

I'm using the vicon_bridge node, which publishes a topic "vicon/<subject_name>/<segment_name>" for every subject and segment it finds. In this example, consider that it publishes the topics:

vicon/subject1/segment1 vicon/subject2/segment1

Is there a way, from within C++ code, to get a list of all "vicon/*" topics that are being published? Something like 'rostopic list' that can be used from within the code and can search on a topic "subdirectory"?

Originally posted by Jordan9 on ROS Answers with karma: 113 on 2015-04-08

Post score: 1


1 Answer 1


Rosanswers logo

You could

#include <ros/master.h>

and call

  ros::master::V_TopicInfo topic_infos;

This gets you topic infos (topic name and data type as std::strings) of all advertised topics; obviously not just those in vicon/ but you can filter them with boost:regex or e. g. split and check like:

  std::vector<std::string> lv_elems;
  char lc_delim[2];
  lc_delim[0] = '/';
  lc_delim[1] = '\0';
  boost::algorithm::split( lv_elems, topic_infos[0].name, boost::algorithm::is_any_of( lc_delim ) );
  if ( lv_elems[0] == "vicon" )
   // topic of topic_infos[0] is really in namespace vicon!!

Originally posted by Wolf with karma: 7555 on 2015-04-08

This answer was ACCEPTED on the original site

Post score: 5


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.