Ask Your Question
0

Providing arguments to subscriber callback function

asked 2016-07-13 07:25:57 -0600

basbursen gravatar image

Hello,

I am trying to register same callback for different topics.What I am trying to do is distinguishing the message origin.

I am trying to provide argument to callback function to achieve this.I am using boost::bind.

Here is the signature of my callback function:

void CommandDone_received(const uav::Done &msg, std::string uav_name)

Here is the code that I use to instantiate the subscriber:

std::string uav_name = uav.get_name();
ros::Subscriber subscriber = nh.subscribe<uav::done>(uav.get_name() + "/CommandDone", 1000, boost::bind(&CommandDone_received, _1, uav_name));

This is the error that I got when I run "catkin_make"

In file included from /usr/include/boost/bind.hpp:22:0,
                 from /opt/ros/indigo/include/ros/publisher.h:35,
                 from /opt/ros/indigo/include/ros/node_handle.h:32,
                 from /opt/ros/indigo/include/ros/ros.h:45,
                 from /home/baskin/KOVAN/src/uav/uav_src/uav_master.cpp:1:
/usr/include/boost/bind/bind.hpp: In instantiation of ‘void boost::_bi::list2<a1, a2="">::operator()(boost::_bi::type<void>, F&, A&, int) [with F = void (*)(const uav::Done_<std::allocator<void> >&, std::basic_string<char>); A = boost::_bi::list1<const boost::shared_ptr<const="" uav::done_<std::allocator<void=""> > >&>; A1 = boost::arg<1>; A2 = boost::_bi::value<std::basic_string<char> >]’:
/usr/include/boost/bind/bind_template.hpp:47:59:   required from ‘boost::_bi::bind_t<r, f,="" l="">::result_type boost::_bi::bind_t<r, f,="" l="">::operator()(const A1&) [with A1 = boost::shared_ptr<const uav::done_<std::allocator<void=""> > >; R = void; F = void (*)(const uav::Done_<std::allocator<void> >&, std::basic_string<char>); L = boost::_bi::list2<boost::arg<1>, boost::_bi::value<std::basic_string<char> > >; boost::_bi::bind_t<r, f,="" l="">::result_type = void]’
/usr/include/boost/function/function_template.hpp:153:11:   required from ‘static void boost::detail::function::void_function_obj_invoker1<functionobj, r,="" t0="">::invoke(boost::detail::function::function_buffer&, T0) [with FunctionObj = boost::_bi::bind_t<void, void="" (*)(const="" uav::done_<std::allocator<void=""> >&, std::basic_string<char>), boost::_bi::list2<boost::arg<1>, boost::_bi::value<std::basic_string<char> > > >; R = void; T0 = const boost::shared_ptr<const uav::done_<std::allocator<void=""> > >&]’
/usr/include/boost/function/function_template.hpp:934:38:   required from ‘void boost::function1<r, t1="">::assign_to(Functor) [with Functor = boost::_bi::bind_t<void, void="" (*)(const="" uav::done_<std::allocator<void=""> >&, std::basic_string<char>), boost::_bi::list2<boost::arg<1>, boost::_bi::value<std::basic_string<char> > > >; R = void; T0 = const boost::shared_ptr<const uav::done_<std::allocator<void=""> > >&]’
/usr/include/boost/function/function_template.hpp:722:7:   required from ‘boost::function1<r, t1="">::function1(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<void, void="" (*)(const="" uav::done_<std::allocator<void=""> >&, std::basic_string<char>), boost::_bi::list2<boost::arg<1>, boost::_bi::value<std::basic_string<char> > > >; R = void; T0 = const boost::shared_ptr<const uav::done_<std::allocator<void=""> > >&; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<functor>::value>::value, int>::type = int]’
/usr/include/boost/function/function_template.hpp:1069:16:   required from ‘boost::function<r(t0)>::function(Functor, typename boost::enable_if_c ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2016-07-13 07:42:32 -0600

basbursen gravatar image

Changing

void CommandDone_received(const uav::Done &msg, std::string uav_name)
to
void CommandDone_received(const uav::Done::ConstPtr &msg, std::string uav_name)
solved the problem.I think the problem was that boost::bind provides references as shared pointers, which cannot be assigned to regular references.

Used roehling's answer to this question: http://answers.ros.org/question/12183...

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-07-13 07:25:57 -0600

Seen: 908 times

Last updated: Jul 13 '16