Synchronisation with Subscribers
I would like to have two subscribers in one file. Two subscribers are supposed to subscribe to two different topics, get their respective data and process them. In order to get this working, I need to solve the synchronization issue. I've already look here but it wasn't very helping, since his way of subscribing is not how I do.
Here is my code:
ros::init(argc, argv, "radarSubscriber");
ros::NodeHandle n("~");
// subscribe to the multibeam
ros::Subscriber sub = n.subscribe("/multibeam", 500, multibeamCallback);
// subscribe to image_processor
ros::Subscriber sub = n.subscribe("/processor", 500, processorCallback);
// part I took from the link ------------------------------------------------------------------
typedef sync_policies::ApproximateTime<Image, Image> MySyncPolicy;
// ApproximateTime takes a queue size as its constructor argument, hence MySyncPolicy(10)
Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), image1_sub, image2_sub);
sync.registerCallback(boost::bind(&callback, _1, _2));
// -------------------------------------------------------------------------------------------
What should come there instead of image, image is what I need to know. He was trying to synchronize two cameras, therefore image image works for him. What is it going to be there for me? Should I put the data types of mine (the ones that I subscribe to and get via callback) ?
Thanks in advance.
EDIT:
So after figuring out that the regular subscribers won't work, I used the message filters. However the problem persists. Here is the code that I try to compile:
// subscribe to two topics, one for radar beams, one for frame sectors
message_filters::Subscriber<sensor_msgs::LaserScan> subMultibeam(n, "multibeam", 1);
message_filters::Subscriber<std_msgs::Int32MultiArray> subProcessor(n, "imgProcessor", 1);
// synchronize the callback through approximate time approach
typedef sync_policies::ApproximateTime<sensor_msgs::LaserScan, std_msgs::Int32MultiArray> MySyncPolicy;
Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), subMultibeam, subProcessor);
sync.registerCallback(boost::bind(&callback, _1, _2));
and here is a small piece of the error message that I am getting (the whole message is enormously big and I can't paste it here):
/opt/ros/hydro/include/message_filters/sync_policies/approximate_time.h: In member function ‘void message_filters::sync_policies::ApproximateTime<M0, M1, M2, M3, M4, M5, M6, M7, M8>::checkInterMessageBound() [with int i = 1, M0 = sensor_msgs::LaserScan_<std::allocator<void> >, M1 = std_msgs::Int32MultiArray_<std::allocator<void> >, M2 = message_filters::NullType, M3 = message_filters::NullType, M4 = message_filters::NullType, M5 = message_filters::NullType, M6 = message_filters::NullType, M7 = message_filters::NullType, M8 = message_filters::NullType]’:
/opt/ros/hydro/include/message_filters/sync_policies/approximate_time.h:218:7: instantiated from ‘void message_filters::sync_policies::ApproximateTime<M0, M1, M2, M3, M4, M5, M6, M7, M8>::add(const typename boost::mpl::at_c<typename message_filters::PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>::Events, i>::type&) [with int i = 1, M0 = sensor_msgs::LaserScan_<std::allocator<void> >, M1 = std_msgs::Int32MultiArray_<std::allocator<void> >, M2 = message_filters::NullType, M3 = message_filters::NullType, M4 = message_filters::NullType, M5 = message_filters::NullType, M6 = message_filters::NullType, M7 = message_filters::NullType, M8 = message_filters::NullType, typename boost::mpl::at_c<typename message_filters::PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>::Events, i>::type = ros::MessageEvent<const std_msgs::Int32MultiArray_<std::allocator<void> > >]’
/opt/ros/hydro/include/message_filters/synchronizer.h:160:5: instantiated from ‘message_filters::Synchronizer<Policy>::Synchronizer(const Policy&, F0&, F1&) [with F0 = message_filters::Subscriber ...