Ask Your Question
0

multiple subscriber to single callback function not working

asked 2017-03-08 21:06:30 -0600

dinesh gravatar image

updated 2017-03-08 21:47:53 -0600

I am trying to subscribe to two topics of type ros_arduino_msgs/Digital type in a single callback function like below:

#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/CameraInfo.h>
#include <iostream>
#include <ros_arduino_msgs/Digital.h>
using namespace ros_arduino_msgs;
using namespace message_filters;

void callback(const DigitalConstPtr& e1, const DigitalConstPtr& e2)
{ 
  std::cout<<"callback"<<std::endl;
  std::cout<<e1<<std::endl;
}

int main(int argc, char** argv)
{
  ros::init(argc, argv, "vision_node");
  std::cout<<"main"<<std::endl;
  ros::NodeHandle nh;
  message_filters::Subscriber<Digital> e1(nh, "/arduino/sensor/left_encoder_A", 10);
  message_filters::Subscriber<Digital> e2(nh, "/arduino/sensor/left_encoder_B", 10);
  TimeSynchronizer<Digital, Digital> sync(e1, e2, 10);
  sync.registerCallback(boost::bind(&callback, _1, _2));

  ros::spin();

  return 0;
}

But when i run it is not working. Cant't i use type of subscirbed topic as arduino_ros_msgs/Digital, does it only works with ros msgs types like sensor msgs and std_msgs?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-03-08 22:04:44 -0600

Are the timestamps in your topics synchronized? If they are not, you should try ApproximateTime policy instead.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-03-08 21:06:30 -0600

Seen: 110 times

Last updated: Mar 08 '17