Ask Your Question
0

message_filters code explained

asked 2016-12-14 02:31:34 -0500

fabbro gravatar image

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-12-14 04:24:41 -0500

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.

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

1 follower

Stats

Asked: 2016-12-14 02:31:34 -0500

Seen: 970 times

Last updated: Dec 14 '16