Cannot retrieve data from bag file. Topic won't be listed.

asked 2022-03-19 17:08:18 -0500

I have a big bag file 20GB+. I want to access data from a specific topic and loop over it to save the data seperately. If I start the ros core via roslaunch, I can access the data (e.g. via rviz).

If I try to access the data via the C++ api, the rosbag::View object seems to be null. Therefore, I checked if the topic is available. However, the following code just lists a few topics but not all. Ros answer for listing topics

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

BOOST_FOREACH(const rosbag::ConnectionInfo *info, connection_infos) {
    std::cout << info->topic << std::endl;
}

How do I want to access the topic:

#include "rosbag/bag.h"
#include "rosbag/view.h"
#include "sensor_msgs/PointCloud2.h"    

rosbag::Bag bag("test.bag");
rosbag::View view(bag, rosbag::TopicQuery("/sensors/velodyne_points"));
BOOST_FOREACH(rosbag::MessageInstance const m, view)
{
    sensor_msgs::PointCloud2::ConstPtr i = m.instantiate<sensor_msgs::PointCloud2>();
    if (i != NULL)
        std::cout << i->data << std::endl;
}
bag.close();

I just want to iterate over all point clouds within the bag file to save the data in a different format. If this does not work, is there a another way to retrieve the data from the bag file? I could also subscribe with a node, but then I have to take care of the time (i.e. start node -> start playing rosbag somehow -> save data within callback) but this seems to be too much trouble. Is this maybe some ros time issue?

edit retag flag offensive close merge delete