What is boost::bind() commonly used in Action servers

I saw this boost::bind code used multiple times in Action servers and after looking through documentations, i still can’t wrap my head around how and more importantly, why it’s used.


This code is from "Solutions for Unit 4 Actions Part 2"


Also, I was looking through the forum for an answer and realised someone asked this question before 2 years ago but there was no answer for it yet. This question was however, catered towards the Fibonnaci Action in the examples.

I have gotten very good answers from this forum in the past, and i hope this someone here can assist in clearing my doubts.

Thanks!

It might be for passing external context/arguments to your callback. In certain cases you want to pass more things to your callback that what is passed by the caller.

See : https://answers.ros.org/question/12045/how-to-deliver-arguments-to-a-callback-function/

In that case it would be to be able to access this into your callback as well as the parameters that get passed to the callback by the action.

Hi, just one more thing. In the parameters inside boost::bind, i see a “_1” parameter. This “_1” acts as a placeholder for arguments given to the “executeCB” method right?

And if i’m wrong, what exactly does it represent?