0
$\begingroup$

Rosanswers logo

I need to get the names of all the topics in a rosbag in C++ (that is using something like rosbag API). The rosbag cookbook mentions how to get information about the rosbag using python but not C++.

Any help would be appreciated.


Originally posted by Ankush on ROS Answers with karma: 75 on 2012-07-19

Post score: 4

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

You can use rosbag::View::getConnectionInfo.

rosbag::Bag bag("foo.bag");
rosbag::View view(bag);
std::vector<const rosbag::ConnectionInfo *> connection_infos = view.getConnectionInfo();
std::set<std::string> topics;

BOOST_FOREACH(const rosbag::ConnectionInfo *info, connection_infos) {
  if( !topics.find(info->topic) ) {
    topics.insert(info->topic);
  }
}

Originally posted by Lorenz with karma: 22731 on 2012-07-20

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by Ankush on 2012-07-20:
Thank you, that really helped. On the same note, what is the C++ equivalent of "rewriting bag", given in the cookbook (http://www.ros.org/wiki/rosbag/Cookbook)?

I want to process a particular topic from a rosbag file and write the others unchanged to a new bagfile.

$\endgroup$
0
$\begingroup$

Rosanswers logo

The code proposed by Lorenz did not compile! This is what it should be after fixing the errors:

rosbag::Bag bag("foo.bag");
rosbag::View view(bag);
std::vector<const rosbag::ConnectionInfo *> connection_infos = view.getConnections();
std::set<std::string> topics;

BOOST_FOREACH(const rosbag::ConnectionInfo *info, connection_infos) {
  topics.insert(info->topic);
}

Originally posted by beginner with karma: 83 on 2015-06-05

This answer was NOT ACCEPTED on the original site

Post score: 3


Original comments

Comment by Farid on 2020-01-08:
So how do we print them in terminal? maybe cout << info->topic << "\t[" << info->datatype << "]" << endl; inside BOOST_FOREACH function?

$\endgroup$

Your Answer

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