rosbag C++ api writting multiple topics synchronously

asked 2021-06-12 04:00:33 -0600

long gravatar image

I am a newer to ros, and I have a problem when try to save three different topics data to rosbag synchronously. I use the following code block to ensure the three different topics synchronously.

message_filters::Subscriber<sensor_msgs::PointCloud2> pointCloud_sub_; 
message_filters::Subscriber<sensor_msgs::Image> left_image_sub_;
message_filters::Subscriber<sensor_msgs::Image> right_image_sub_;
typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::PointCloud2, sensor_msgs::Image, 
sensor_msgs::Image> multiSyncPolicy;
typedef message_filters::Synchronizer<multiSyncPolicy> multiSync;
boost::shared_ptr<multiSync> multiSync_;

std::string bagPath = "/home/XXX/Desktop/rosbagData/test.bag";
bag_.open(bagPath, rosbag::bagmode::Write);
pointCloud_sub_.subscribe(pMTNH, "/lidar", 1);
left_image_sub_.subscribe(pMTNH, "/leftCamera/nodeletTalker/RawImg", 1);
right_image_sub_.subscribe(pMTNH, "/rightCamera/nodeletTalker/RawImg", 1);
multiSync_.reset(new multiSync(multiSyncPolicy(4), pointCloud_sub_, left_image_sub_, right_image_sub_));
multiSync_->registerCallback(&nodeletListener::multiTopicsCallback, this);

the callback function is here: void nodeletListener::multiTopicsCallback(const sensor_msgs::PointCloud2ConstPtr &pointCloud, const sensor_msgs::Image::ConstPtr &leftImage, const sensor_msgs::Image::ConstPtr &rightImage) { NODELET_INFO_STREAM("pointCloud--left image diff time is " << pointCloud->header.stamp.toSec() - leftImage->header.stamp.toSec()); NODELET_INFO_STREAM("left--right image diff time is " << leftImage->header.stamp.toSec() - rightImage->header.stamp.toSec()); //rosbag all the topics string leftCamTopic = "/leftCamera/nodeletTalker/RawImg"; string rightCamTopic = "/rightCamera/nodeletTalker/RawImg"; string lidarTopic = "/lidar";

bag_.write(leftCamTopic, leftImage->header.stamp, leftImage);
bag_.write(rightCamTopic, rightImage->header.stamp, rightImage);
bag_.write(lidarTopic, pointCloud->header.stamp, pointCloud);

}

the question is: I save the data in myown PC, the test.bag file is saved correctly, and can be used. However, when I copy this test.bag file into the other PC , the test.bag file can not be used correctly. I don't know why, please give me a hand, thank you very much.

edit retag flag offensive close merge delete

Comments

Please edit your question and provide more detail than "file can not be used". Exactly what does not work? Are there any error messages?

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-06-23 09:10:27 -0600 )edit