Understanding registerCallback() from TF MessageFilter tutorial
I'm going through the TF MessageFilter tutorial and I understand the code except for line 13:
tf_filter_->registerCallback( boost::bind(&PoseDrawer::msgCallback, this, _1) );
I'm more of a novice when it comes to using the boost
libraries, but after reading some documentation, it seems that this line is creating a function object that equates to something of this form: msgCallback(this, _1)
where this
is the PoseDrawer object and _1
is a placeholder that will be substituted with the first argument provided to the function object (which I'm assuming is done by the TF library under the hood).
What I'm confused about is how you know to provide the this
object and that the callback function needs an _1
placeholder. Is the _1
simply because the callback function (shown below) only takes one argument? If my callback function had no parameters, would I just remove the _1
argument when calling the function? Why is the this
object necessary?
void msgCallback(const boost::shared_ptr<const geometry_msgs::PointStamped>& point_ptr)
These are all C++ questions and not directly related to ROS. I would however recommend reading up on C++ Lamba functions to understand exactly what they do. This tutorial is a good start.
Ok sorry about that. Do you think I should post this somewhere else? I posted here because this was code directly given in the ROS TF MessageFilters tutorial and thought it might help someone else going through the tutorials.
Also, I looked at the Lambda functions tutorial you linked. Could you specify how my question is related? I don't think the code above is using Lambda functions. I think the
registerCallback
line is just calling a function within a function.