Ask Your Question
4

rosbag info in C++

asked 2012-07-19 23:35:06 -0500

Ankush gravatar image

updated 2014-01-28 17:13:05 -0500

ngrennan gravatar image

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.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
3

answered 2012-07-20 01:39:23 -0500

Lorenz gravatar image

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);
  }
}
edit flag offensive delete link more

Comments

1

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.

Ankush gravatar imageAnkush ( 2012-07-20 14:58:27 -0500 )edit
2

answered 2015-06-05 09:35:39 -0500

beginner gravatar image

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);
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-07-19 23:35:06 -0500

Seen: 2,559 times

Last updated: Jun 05 '15