0
$\begingroup$

Rosanswers logo

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!!!


Originally posted by thomai on ROS Answers with karma: 13 on 2015-11-24

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by dornhege with karma: 31395 on 2015-11-24

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by thomai on 2015-11-24:
Yes, that was the problem! Switched to geometry_msgs::PolygonStamped and compiled! :)

Thank you!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.