callback for two topics at the same time
Hi everyone,
I would like to save an image from a depthcamera and a webcam at the same time as a mouse click. So I subscribed to the depth image and in this callback I used
webcam_image = ros::topic::waitForMessage<Image>("/logitech_usb_webcam/image_raw");
but it seems that the wait for message skips the first message and uses the second one instead...
So I went on and tried another solution. Therefore, I used the registerCallback function from the message_filter package but it doesn't behave like I want it because the callback gets never triggered (both topics are published).
My code looks like this
#include <ros/ros.h>
#include <std_msgs/String.h>
#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <sensor_msgs/Image.h>
using namespace sensor_msgs;
using namespace message_filters;
void sync_callback(const ImageConstPtr& depth_image, const ImageConstPtr& webcam_image){
ROS_INFO("syncro callback");
}
int main(int argc, char **argv){
ros::init(argc, argv, "listener");
ros::NodeHandle nh;
message_filters::Subscriber<Image> depth_sub(nh, "/camera/depth/image", 1);
message_filters::Subscriber<Image> webcam_sub(nh, "/logitech_usb_webcam/image_raw", 1);
TimeSynchronizer<Image, Image> sync(depth_sub, webcam_sub, 50);
sync.registerCallback(boost::bind(&sync_callback, _1, _2));
ros::spin();
return 0;
}
Would be great to get your help to get this working.