Problem with 'message_filters' Time Synchronize with Gazebo

asked 2019-07-04 03:30:28 -0500

NEET gravatar image

I try to use 'message_filters' to sync two topics which is published from gazebo simulator. But it doesn't work fine :(

There is my code below:


#include "ros/ros.h"
#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h>
#include <message_filters/sync_policies/exact_time.h>
#include "pkgA/msgA.h"
#include "pkgB/msgB.h"

void callback(const pkgA::msgA &a, const pkgB::msgB &b)
  // Solve all of perception here...

int main(int argc, char **argv)
  ros::init(argc, argv, "gazebo_relay_node");

  ros::NodeHandle nh;
  message_filters::Subscriber<pkgA::msgA> subA(nh, "topicA", 1);
  message_filters::Subscriber<pkgB::msgB> subB(nh, "topicB", 1);

  TimeSynchronizer<pkgA::msgA, pkgB::msgB> sync(subA, subB, 100);
  sync.registerCallback(boost::bind(&callback, _1, _2));


  return 0;

I also tried 'approximate_time' and 'exact_time', but does not work, either.

There is a problem that I did a experiment:

I opened new terminal and published topics by manual, like:

$ rostopic pub "/topicA" pkgA/msgA "" -r 10
$ rostopic pub "/topicB" pkgB/msgB "" -r 10

Then 'my_node' worked very well.
It just can not sync the topics from gazebo.

edit retag flag offensive close merge delete