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

rosbag info in C++

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

Ankush gravatar image

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

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
4

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

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 image Ankush  ( 2012-07-20 14:58:27 -0600 )edit
3

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

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

Comments

So how do we print them in terminal? maybe cout << info->topic << "\t[" << info->datatype << "]" << endl; inside BOOST_FOREACH function?

Farid gravatar image Farid  ( 2020-01-08 10:51:35 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 4,630 times

Last updated: Jun 05 '15