Multiple callbacks with approximate time sync policy

asked 2022-03-14 07:30:46 -0500

pravin1 gravatar image

I am trying to synchronize lidar point cloud with two camera images(each processed separately). I have tried following to implement my desired output.

using namespace sensor_msgs;
using namespace message_filters;

void callback1(const CompressedImageConstPtr& image1, const PointCloud2ConstPtr& pc1) {
//perfrom some task here
}

void callback2(const CompressedImageConstPtr& image2, const PointCloud2ConstPtr& pc1) {
//perfrom some task here
}

int main(int argc, char** argv) {
// some codes
message_filters::Subscriber<CompressedImage> image1_sub(nh, "/left/image_raw/compressed", 1);
message_filters::Subscriber<CompressedImage> image2_sub(nh, "/right/image_raw/compressed", 1);
message_filters::Subscriber<PointCloud2> pc_sub(nh, "/lidar", 1);
typedef sync_policies::ApproximateTime<CompressedImage, PointCloud2> MySyncPolicy;

Synchronizer<MySyncPolicy> sync1(MySyncPolicy(10), image1_sub, pc_sub);
Synchronizer<MySyncPolicy> sync2(MySyncPolicy(10), image2_sub, pc_sub);

sync1.registerCallback(boost::bind(&callback1, _1, _2));
sync2.registerCallback(boost::bind(&callback2, _1, _2));
ros::spin();

}

This works but leads to a lot of message drops. The rate of lidar topic is 10/sec, the camera is 6-7/sec. When I use only one camera image(say left camera only) then almost 5-6 images are synchronized per sec with lidar point cloud but when I use both cameras, only 3 images are synchronized from each camera per sec.

How would I avoid message drop?

edit retag flag offensive close merge delete