Ask Your Question

epsillon's profile - activity

2021-05-03 04:23:34 -0600 received badge  Guru (source)
2021-05-03 04:23:34 -0600 received badge  Great Answer (source)
2019-10-03 03:25:55 -0600 received badge  Enlightened (source)
2019-10-03 03:25:55 -0600 received badge  Good Answer (source)
2019-04-11 00:12:05 -0600 received badge  Student (source)
2018-10-23 10:14:15 -0600 received badge  Nice Answer (source)
2018-01-30 05:50:24 -0600 received badge  Famous Question (source)
2018-01-30 05:50:24 -0600 received badge  Notable Question (source)
2017-12-04 07:14:10 -0600 marked best answer boost::bind errors in subscriber callback

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.

2017-12-04 07:13:43 -0600 received badge  Popular Question (source)
2017-12-03 23:06:16 -0600 received badge  Teacher (source)
2017-12-03 23:06:16 -0600 received badge  Self-Learner (source)
2017-12-03 14:52:42 -0600 answered a question boost::bind errors in subscriber callback

Finally found a working solution in dornhege's answer here Changing my subscriber line to os::Subscriber sub2=n.subsc

2017-12-03 14:52:42 -0600 asked a question boost::bind errors in subscriber callback

boost::bind errors in subscriber callback Hello. New to ROS, Boost, and if I'm quite honest, C++ in general. Basically,

2017-12-03 14:52:41 -0600 asked a question boost::bind errors in subscriber callback

boost::bind errors in subscriber callback Hello. New to ROS, Boost, and if I'm quite honest, C++ in general. Basically,