0
$\begingroup$

Rosanswers logo

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.subscribeuav::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::operator()(boost::_bi::type, F&, A&, int) [with F = void (*)(const uav::Done_ >&, std::basic_string); A = boost::_bi::list1 > >&>; A1 = boost::arg; A2 = boost::_bi::value >]’:
/usr/include/boost/bind/bind_template.hpp:47:59:   required from ‘boost::_bi::bind_t::result_type boost::_bi::bind_t::operator()(const A1&) [with A1 = boost::shared_ptr > >; R = void; F = void (*)(const uav::Done_ >&, std::basic_string); L = boost::_bi::list2, boost::_bi::value > >; boost::_bi::bind_t::result_type = void]’
/usr/include/boost/function/function_template.hpp:153:11:   required from ‘static void boost::detail::function::void_function_obj_invoker1::invoke(boost::detail::function::function_buffer&, T0) [with FunctionObj = boost::_bi::bind_t >&, std::basic_string), boost::_bi::list2, boost::_bi::value > > >; R = void; T0 = const boost::shared_ptr > >&]’
/usr/include/boost/function/function_template.hpp:934:38:   required from ‘void boost::function1::assign_to(Functor) [with Functor = boost::_bi::bind_t >&, std::basic_string), boost::_bi::list2, boost::_bi::value > > >; R = void; T0 = const boost::shared_ptr > >&]’
/usr/include/boost/function/function_template.hpp:722:7:   required from ‘boost::function1::function1(Functor, typename boost::enable_if_c::value>::value, int>::type) [with Functor = boost::_bi::bind_t >&, std::basic_string), boost::_bi::list2, boost::_bi::value > > >; R = void; T0 = const boost::shared_ptr > >&; typename boost::enable_if_c::value>::value, int>::type = int]’
/usr/include/boost/function/function_template.hpp:1069:16:   required from ‘boost::function::function(Functor, typename boost::enable_if_c::value>::value, int>::type) [with Functor = boost::_bi::bind_t >&, std::basic_string), boost::_bi::list2, boost::_bi::value > > >; R = void; T0 = const boost::shared_ptr > >&; typename boost::enable_if_c::value>::value, int>::type = int]’
/home/baskin/KOVAN/src/uav/uav_src/uav_master.cpp:354:142:   required from here
/usr/include/boost/bind/bind.hpp:313:34: error: invalid initialization of reference of type ‘const uav::Done_ >&’ from expression of type ‘const boost::shared_ptr > >’
         unwrapper::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);
                                  ^
make[2]: *** [uav/CMakeFiles/uav_master.dir/uav_src/uav_master.cpp.o] Error 1
make[1]: *** [uav/CMakeFiles/uav_master.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

Can anyone assist me to find the problem?

Thanks a lot.


Originally posted by basbursen on ROS Answers with karma: 53 on 2016-07-13

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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/121831/boostbind-errors-in-subscriber-callback-functions/


Originally posted by basbursen with karma: 53 on 2016-07-13

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.