Ask Your Question
1

boost::bind errors in subscriber callback

asked 2017-12-03 11:10:58 -0500

epsillon gravatar image

updated 2017-12-03 17:07:27 -0500

jayess gravatar image

Hello. New to ROS, Boost, and if I'm quite honest, C++ in general. Basically, I am trying to pass a few parameters to a callback function using boost::bind, but am unable to compile. I am running into the same issue as this question, among others, but none of the solutions I've found seem to be working for me.

Based on some of the things I found, I had some suspicions that I may not have had bind at all, so I made changes to try and do so, with no change in results.

relevant source:

#include "ros/ros.h"
#include <nav_msgs/OccupancyGrid.h>
//#include <boost/bind.hpp>

void mapcallback(const nav_msgs::OccupancyGrid::ConstPtr& msg, int* k)//Map_Info* mapdata)
{
//doing stuff
}

int main(int argc, char **argv)
{
    ros::init(argc, argv, "mapper");
    ros::NodeHandle n;
    int test;
    //boost::bind(&mapcallback, _1, test);
    ros::Subscriber sub2=n.subscribe("map",1, boost::bind(&mapcallback, _1, &test));
    while (ros::ok())
    {       
        ros::spinOnce();
        sleep(2);
    }

return 0;
}

Ultimately, test is going to be replaced with a class generated by a different subscriber, but right now I'm just trying to get the basic case to compile. I've tried both with and without the pointers in the boost::bind, with no difference. Also, the include makes no difference, and the compiler doesn't complain about the currently commented line.

The error I am getting is

error: no matching function for call to ‘ros::NodeHandle::subscribe(const char [4], int, boost::_bi::bind_t<void, void (*)(const boost::shared_ptr<const nav_msgs::OccupancyGrid_<std::allocator<void> > >&, int), boost::_bi::list2<boost::arg<1>, boost::_bi::value<int> > >)’
  ros::Subscriber sub2=n.subscribe("map",1, boost::bind(&mapcallback, _1, test));

followed by a bunch of candidates, and then

/opt/ros/kinetic/include/ros/node_handle.h:835:14: note:   candidate expects 1 argument, 3 provided

if I add the line find_package(Boost REQUIRED COMPONENTS bind) to my CMakeLists.txt, it does stop earlier saying that it is unable to find package bind, but a different package (I thing it was system) worked without issue.

I've been fighting this issue for most of a day now, so help would be very appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2017-12-03 11:49:45 -0500

epsillon gravatar image

Finally found a working solution in dornhege's answer here

Changing my subscriber line to

os::Subscriber sub2=n.subscribe<nav_msgs::OccupancyGrid> ("map",1, boost::bind(&mapcallback, _1, &test));

Compiled, but I still have to test to make sure it's doing what I want. My error the last time I tried the brackets was I had a space between subscribe and <nav_msgs...

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: 2017-12-03 02:21:50 -0500

Seen: 3,024 times

Last updated: Dec 03 '17