ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Approximate time synchronizer for Different message Types

asked 2015-11-24 10:01:25 -0500

thomai gravatar image

Hi everyone,

I am trying to incorporate message filtering in my code. I need to subscribe to two topics and execute the callback when both topics get a message at the same time (or approximately). This is what I wrote so far:

 /// Subscribers to the two topics
typedef message_filters::Subscriber<sensor_msgs::Image> blobSubscriber;
typedef message_filters::Subscriber<std_msgs::Float32MultiArray> PCLSubscriber;
typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, std_msgs::Float32MultiArray> sync_policy_classification;

void callback(const sensor_msgs::Image::ConstPtr& image, const std_msgs::Float32MultiArray::ConstPtr& object_coordinates)
   // Some stuff here

int main(int argc, char **argv) {

  ros::init(argc, argv, "colour_classification");

  ros::NodeHandle n;

  blobSubscriber blob_sub(n, "/object_detection/object_mask", 1);
  PCLSubscriber PCL_sub(n, "/PCL_wooden_shape_recognition", 1);;

  message_filters::Synchronizer<sync_policy_classification> class_sync(sync_policy_classification(10), blob_sub, PCL_sub);

  class_sync.registerCallback(boost::bind(&callback, _1, _2));

  return 0;

This is the part of my code that includes the message filtering stuff.

When I try to compile this I get a large number of errors, that have to do with the different types of the messages. I actually tried using sensor_msgs::Image for both messages and was able to compile without any issues.

So my question is: Is it actually possible to implement message filtering for different types of messages? And if yes, is there something obviously wrong with my code?

Thank you in advance!!!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-11-24 10:33:32 -0500

dornhege gravatar image

I suspect that the compilation problem comes from using Float32MultiArray. This cannot work in principle as that message does not have a time stamp, so there is nothing to synchronize to.

edit flag offensive delete link more


Yes, that was the problem! Switched to geometry_msgs::PolygonStamped and compiled! :)

Thank you!

thomai gravatar image thomai  ( 2015-11-24 10:40:53 -0500 )edit

Question Tools

1 follower


Asked: 2015-11-24 10:01:25 -0500

Seen: 1,075 times

Last updated: Nov 24 '15