message_filters code explained
Hi,
I am using this code in my node but I would like to understand it more (line by line): [of course I read : http://wiki.ros.org/message_filters]
message_filters::Subscriber<sensor_msgs::Image> raw_image_subscriber(nh_, image_topic, queue_size_);
message_filters::Subscriber<sensor_msgs::CameraInfo> camera_info_subscriber(nh_, camera_info_topic, queue_size_);
message_filters::TimeSynchronizer<sensor_msgs::Image, sensor_msgs::CameraInfo> image_info_sync(raw_image_subscriber, camera_info_subscriber, queue_size_);
image_info_sync.registerCallback(boost::bind(&Node::frameCallback,this, _1, _2));
As far as I understood:
message_filters::Subscriber<sensor_msgs::Image> raw_image_subscriber(nh_, image_topic, queue_size_);
Creates an object of type message_filters::Subscriber<sensor_msgs::Image>
which is connected to the image_topic specified somewhere else in my code.
message_filters::Subscriber<sensor_msgs::CameraInfo> camera_info_subscriber(nh_, camera_info_topic, queue_size_);
Creates an object of type message_filters::Subscriber<sensor_msgs::CameraInfo>
which is connected to the canerainfotopic specified somewhere else in my code.
message_filters::TimeSynchronizer<sensor_msgs::Image, sensor_msgs::CameraInfo> image_info_sync(raw_image_subscriber, camera_info_subscriber, queue_size_);
Creates an object of type message_filters::TymeSynchronizer<sensor_msgs::Image, sensor_msgs::CameraInfo>
which is connected to the 2 subscribers created before.
If I understood it correctly it synchronizes incoming channels by the timestamps contained in their headers, and outputs them in the form of a single callback that takes the same number of channels.
Is it all correct?
image_info_sync.registerCallback(boost::bind(&Node::frameCallback,this, _1, _2));
This is the most difficult expression for me to understand. Why do I need the boost::bind
function? And how this function works?
Thanks in advance
Asked by fabbro on 2016-12-14 03:31:34 UTC
Answers
Yes, your understanding is correct.
The line
image_info_sync.registerCallback(boost::bind(&Node::frameCallback,this, _1, _2));
Is telling the TimeSynchronizer that whenever it receives the syncronized info from raw_image_subscriber and camera_info_subscriber it should call the method frameCallback. This method's fingerprint is:
class Node{
...
void frameCallback( sensor_msgs::ImageConstPtr& img, sensor_msgs::CameraInfoConstPtr& info);
...
};
The boost::bind function is getting a valid pointer to a member function named Node::frameCallback in the object "this" (here you could pass a pointer to any object of class Node), that accepts two parameters and giving it to image_info_sync. Here _1 is a placeholder argument that means "substitute with the first input argument" and _2 means "substitute with the second input argument".
I hope this clarifies your doubt.
Asked by Martin Peris on 2016-12-14 05:24:41 UTC
Comments