Robotics StackExchange | Archived questions

throw 'no matching function for call ' compilation error when subscribe message

code :

void MotionCore::run(){
    std::cout << "start MotionCore run";

    // init subscriber  to todo:add callback function from subscibe msg and publishmsg
    _sub_object = _nh.subscribe("/perception/object",10,boost::bind(& MotionCore::_callback_from_perception_obstacle,this));

    // init publiser,the msg publisher rate depends on perception rate from wenbo.
    _pub_trajectory = _nh.advertise<trajectory::trajectory>("obstacle_trajectory",10);


    ROS_INFO_STREAM("start MotionCore run: "<< ros::Time());
    ros::spin();
}

the callback:

    void MotionCore::_callback_from_perception_obstacle(){
    set_current_state();
    set_need_pub_msg_true();
    gen_trajectory();
}

the error infomation:

 7:08:01: Running steps for project Enmodel...
17:08:01: Starting: "/usr/bin/cmake" --build . --target all
Scanning dependencies of target Enmodel_OTHER_FILES
[ 27%] Built target Enmodel_OTHER_FILES
Scanning dependencies of target final_trajectory
[ 33%] Building CXX object trajectory/CMakeFiles/final_trajectory.dir/nodes/final_trajectory.cpp.o
In file included from /home/westeast/git/enmodel/src/trajectory/nodes/final_trajectory.cpp:4:0:
/home/westeast/git/enmodel/src/trajectory/nodes/motion/MotionCore.cpp: In member function ‘void trajectory_prediction::MotionCore::run()’:
/home/westeast/git/enmodel/src/trajectory/nodes/motion/MotionCore.cpp:14:127: error: no matching function for call to ‘ros::NodeHandle::subscribe(const char [19], int, boost::_bi::bind_t<void, boost::_mfi::mf0<void, trajectory_prediction::MotionCore>, boost::_bi::list1<boost::_bi::value<trajectory_prediction::MotionCore*> > >)’
         _sub_object = _nh.subscribe("/perception/object",10,boost::bind(& MotionCore::_callback_from_perception_obstacle,this));
                                                                                                                               ^
/home/westeast/git/enmodel/src/trajectory/nodes/motion/MotionCore.cpp:14:127: note: candidates are:
In file included from /opt/ros/indigo/include/ros/ros.h:45:0,
                 from /home/westeast/git/enmodel/src/trajectory/nodes/final_trajectory.cpp:2:
/opt/ros/indigo/include/ros/node_handle.h:401:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(M), T*, const ros::TransportHints&)
   Subscriber subscribe(const std::string& topic, uint32_t queue_size, void(T::*fp)(M), T* obj, 
              ^
/opt/ros/indigo/include/ros/node_handle.h:401:14: note:   template argument deduction/substitution failed:
In file included from /home/westeast/git/enmodel/src/trajectory/nodes/final_trajectory.cpp:4:0:
/home/westeast/git/enmodel/src/trajectory/nodes/motion/MotionCore.cpp:14:127: note:   mismatched types ‘void (T::*)(M)’ and ‘boost::_bi::bind_t<void, boost::_mfi::mf0<void, trajectory_prediction::MotionCore>, boost::_bi::list1<boost::_bi::value<trajectory_prediction::MotionCore*> > >’
         _sub_object = _nh.subscribe("/perception/object",10,boost::bind(& MotionCore::_callback_from_perception_obstacle,this));
                                                                                                                               ^
In file included from /opt/ros/indigo/include/ros/ros.h:45:0,
                 from /home/westeast/git/enmodel/src/trajectory/nodes/final_trajectory.cpp:2:
/opt/ros/indigo/include/ros/node_handle.h:412:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(M)const, T*, const ros::TransportHints&)
   Subscriber subscribe(const std::string& topic, uint32_t queue_size, void(T::*fp)(M) const, T* obj, 
              ^
/opt/ros/indigo/include/ros/node_handle.h:412:14: note:   template argument deduction/substitution failed:
In file included from /home/westeast/git/enmodel/src/trajectory/nodes/final_trajectory.cpp:4:0:
/home/westeast/git/enmodel/src/trajectory/nodes/motion/MotionCore.cpp:14:127: note:   mismatched types ‘void (T::*)(M)const’ and ‘boost::_bi::bind_t<void, boost::_mfi::mf0<void, trajectory_prediction::MotionCore>, boost::_bi::list1<boost::_bi::value<trajectory_prediction::MotionCore*> > >’
         _sub_object = _nh.subscribe("/perception/object",10,boost::bind(& MotionCore::_callback_from_perception_obstacle,this));
                                                                                                                               ^
In file included from /opt/ros/indigo/include/ros/ros.h:45:0,
                 from /home/westeast/git/enmodel/src/trajectory/nodes/final_trajectory.cpp:2:
/opt/ros/indigo/include/ros/node_handle.h:464:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(const boost::shared_ptr<const M>&), T*, const ros::TransportHints&)
   Subscriber subscribe(const std::string& topic, uint32_t queue_size, 
              ^
/opt/ros/indigo/include/ros/node_handle.h:464:14: note:   template argument deduction/substitution failed:
In file included from /home/westeast/git/enmodel/src/trajectory/nodes/final_trajectory.cpp:4:0:
/home/westeast/git/enmodel/src/trajectory/nodes/motion/MotionCore.cpp:14:127: note:   mismatched types ‘void (T::*)(const boost::shared_ptr<const M>&)’ and ‘boost::_bi::bind_t<void, boost::_mfi::mf0<void, trajectory_prediction::MotionCore>, boost::_bi::list1<boost::_bi::value<trajectory_prediction::MotionCore*> > >’
         _sub_object = _nh.subscribe("/perception/object",10,boost::bind(& MotionCore::_callback_from_perception_obstacle,this));
                                                                                                                               ^
In file included from /opt/ros/indigo/include/ros/ros.h:45:0,
                 from /home/westeast/git/enmodel/src/trajectory/nodes/final_trajectory.cpp:2:
/opt/ros/indigo/include/ros/node_handle.h:474:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(const boost::shared_ptr<const M>&)const, T*, const ros::TransportHints&)
   Subscriber subscribe(const std::string& topic, uint32_t queue_size, 
              ^
/opt/ros/indigo/include/ros/node_handle.h:474:14: note:   template argument deduction/substitution failed:
In file included from /home/westeast/git/enmodel/src/trajectory/nodes/final_trajectory.cpp:4:0:
/home/westeast/git/enmodel/src/trajectory/nodes/motion/MotionCore.cpp:14:127: note:   mismatched types ‘void (T::*)(const boost::shared_ptr<const M>&)const’ and ‘boost::_bi::bind_t<void, boost::_mfi::mf0<void, trajectory_prediction::MotionCore>, boost::_bi::list1<boost::_bi::value<trajectory_prediction::MotionCore*> > >’
         _sub_object = _nh.subscribe("/perception/object",10,boost::bind(& MotionCore::_callback_from_perception_obstacle,this));
                                                                                                                           ^

I search this error and then I modify the code to the following:

_sub_object = _nh.subscribe("/perception/object",10,&MotionCore::_callback_from_perception_obstacle,this);

but I have another error:

    17:12:35: Running steps for project Enmodel...
17:12:35: Starting: "/usr/bin/cmake" --build . --target all
Scanning dependencies of target Enmodel_OTHER_FILES
[ 27%] Built target Enmodel_OTHER_FILES
Scanning dependencies of target final_trajectory
[ 33%] Building CXX object trajectory/CMakeFiles/final_trajectory.dir/nodes/final_trajectory.cpp.o
In file included from /home/westeast/git/enmodel/src/trajectory/nodes/final_trajectory.cpp:4:0:
/home/westeast/git/enmodel/src/trajectory/nodes/motion/MotionCore.cpp: In member function ‘void trajectory_prediction::MotionCore::run()’:
/home/westeast/git/enmodel/src/trajectory/nodes/motion/MotionCore.cpp:14:113: error: no matching function for call to ‘ros::NodeHandle::subscribe(const char [19], int, void (trajectory_prediction::MotionCore::*)(), trajectory_prediction::MotionCore* const)’
         _sub_object = _nh.subscribe("/perception/object",10,&MotionCore::_callback_from_perception_obstacle,this);
                                                                                                                 ^
/home/westeast/git/enmodel/src/trajectory/nodes/motion/MotionCore.cpp:14:113: note: candidates are:
In file included from /opt/ros/indigo/include/ros/ros.h:45:0,
                 from /home/westeast/git/enmodel/src/trajectory/nodes/final_trajectory.cpp:2:
/opt/ros/indigo/include/ros/node_handle.h:401:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(M), T*, const ros::TransportHints&)
   Subscriber subscribe(const std::string& topic, uint32_t queue_size, void(T::*fp)(M), T* obj, 
              ^
/opt/ros/indigo/include/ros/node_handle.h:401:14: note:   template argument deduction/substitution failed:
In file included from /home/westeast/git/enmodel/src/trajectory/nodes/final_trajectory.cpp:4:0:
/home/westeast/git/enmodel/src/trajectory/nodes/motion/MotionCore.cpp:14:113: note:   candidate expects 2 arguments, 1 provided

Asked by westeast on 2017-05-13 04:15:42 UTC

Comments

Answers

I solve the problem by add param to callbak function

void MotionCore::_callback_from_perception_obstacle(const std_msgs::StringConstPtr &msg){
    set_current_state();
    set_need_pub_msg_true();
    gen_trajectory();
}

Asked by westeast on 2017-05-13 04:41:30 UTC

Comments