ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

no matching function for call to ‘ros::NodeHandle::advertiseService(const char [12], bool (Eddie::*)(), Eddie* const)’

asked 2012-11-21 11:53:08 -0600

kbedolla gravatar image

updated 2022-02-03 15:18:15 -0600

130s gravatar image

Hi I am getting the following error:

 **error: no matching function for call to ‘ros::NodeHandle::advertiseService(const char [12], bool (Eddie::*)(), Eddie* const)’**

Below is the code:

**This is my eddie.cpp class:**
include eddie.h
Eddie::Eddie(){


/ get_version_srv is a ros::ServiceServer declared in my .h file
// node_ is a ros::NodeHandle declared in my .h file
  get_version_srv = node_.advertiseService("get_version", &Eddie::get_board_version, this);

 node_handle_.param<std::string>("serial_port", port, port);
}
Eddie::~Eddie()

}


bool Eddie::get_board_version(parallax_eddie_robot::get_version::Request &req, parallax_eddie_robot::get_version::Response &res)


/DO STUFF

eturn true;

//MAIN FUNCTION

int main(int argc, char** argv)


OS_INFO("Initializing the robot's control board");

os::init(argc, argv, "parallax_board");

ddie eddie;

os::Rate loop_rate(10);

eturn 0;


*Here is my eddie.h file:**

fndef _EDDIE_H
define _EDDIE_H
include ros/ros.h
include fcntl.h
include termios.h
include semaphore.h
include string
include sstream
include map
class Eddie {
 public:
 Eddie();
 virtual ~Eddie();

private:
 sem_t mutex;
 struct termios tio;
 int tty_fd;
  ros::NodeHandle node_handle_;
  ros::ServiceServer get_version_srv_;
  bool get_board_version(parallax_eddie_robot::get_version::Request &req, parallax_eddie_robot::get_version::Response &res);
};
endif

*With the new changes described in the post below I get the following errors**
**Also modified above code (from original post) to reflect the new changes I have made**
/home/opslab/fuerte_workspace/sandbox/parallax_eddie_robot/include/eddie.h:36:26: error: ‘parallax_eddie_robot’ has not been declared
  /home/opslab/fuerte_workspace/sandbox/parallax_eddie_robot/include/eddie.h:36:69: error: expected ‘,’ or ‘...’ before ‘&’ token


 /home/opslab/fuerte_workspace/sandbox/parallax_eddie_robot/src/eddie.cpp:7:98: error: no matching function for call to ‘ros::NodeHandle::advertiseService(const char [12], bool (Eddie::*)(int), Eddie* const)’
 /home/opslab/fuerte_workspace/sandbox/parallax_eddie_robot/src/eddie.cpp:7:98: note: candidates are:
 /opt/ros/fuerte/include/ros/node_handle.h:821:17: note: template<class T, class MReq, class MRes> ros::ServiceServer ros::NodeHandle::advertiseService(const string&, bool (T::*)(MReq&, MRes&), T*)
 /opt/ros/fuerte/include/ros/node_handle.h:859:17: note: template<class T, class MReq, class MRes> ros::ServiceServer ros::NodeHandle::advertiseService(const string&, bool (T::*)(ros::ServiceEvent<MReq, MRes>&), T*)
 /opt/ros/fuerte/include/ros/node_handle.h:898:17: note: template<class T, class MReq, class MRes> ros::ServiceServer ros::NodeHandle::advertiseService(const string&, bool (T::*)(MReq&, MRes&), const boost::shared_ptr<X>&)
 /opt/ros/fuerte/include/ros/node_handle.h:938:17: note: template<class T, class MReq, class MRes> ros::ServiceServer ros::NodeHandle::advertiseService(const string&, bool (T::*)(ros::ServiceEvent<MReq, MRes>&), const boost::shared_ptr<X>&)
 /opt/ros/fuerte/include/ros/node_handle.h:975:17: note: template<class MReq, class MRes> ros::ServiceServer ros::NodeHandle::advertiseService(const string&, bool (*)(MReq&, MRes&))
 /opt/ros/fuerte/include/ros/node_handle.h:1011:17: note: template<class MReq, class MRes> ros::ServiceServer ros::NodeHandle::advertiseService(const string&, bool (*)(ros::ServiceEvent<MReq, MRes>&))
 /opt/ros/fuerte/include/ros/node_handle.h:1045:17: note: template<class MReq, class MRes> ros::ServiceServer ros::NodeHandle::advertiseService(const string&, const boost::function<bool(MReq&, MRes&)>&, const VoidConstPtr&)
 /opt/ros/fuerte/include/ros/node_handle.h:1083:17: note: template<class S> ros::ServiceServer ros::NodeHandle::advertiseService(const string&, const boost::function<bool(S&)>&, const ...
(more)
edit retag flag offensive close merge delete

Comments

I made the necessary changes and made my get_board_version function take in the necessary parameters so the function signature looks like the following: bool get_board_version(parallax_eddie_robot::get_version::Request &req, parallax_eddie_robot::get_version::Response &res);

kbedolla gravatar image kbedolla  ( 2012-11-21 13:12:44 -0600 )edit

However, I still get the same error along with new errors: I will put the list of errors above by editing the original post.

kbedolla gravatar image kbedolla  ( 2012-11-21 13:16:51 -0600 )edit

Thanks petermilani. However, I am still getting the "‘parallax_eddie_robot’ has not been declared" error. As well as "error: ‘bool Eddie::get_board_version’ is not a static member of ‘class Eddie'". Also an error saying that my parameters for the get_version_function 'was not declared in this scope'

kbedolla gravatar image kbedolla  ( 2012-11-22 12:24:46 -0600 )edit

3 Answers

Sort by » oldest newest most voted
1

answered 2012-11-24 10:44:23 -0600

kbedolla gravatar image

Fixed it! Long story short, I forgot to include the header for my service in my header file. Thanks for everyone's answers!

edit flag offensive delete link more
3

answered 2012-11-21 21:18:43 -0600

updated 2022-02-03 15:27:09 -0600

130s gravatar image

I think you cant intialise a ServiceServer in your header file as it isn't really called in your main code. Your function to be called can be in your header file, but try moving your

get_version_srv = node_.advertiseService("get_version", &Eddie::get_board_version, this);

plus any referencing of your node (it probably cant be declared in a header file) into your main code, and instead of using "this" as the last parameter, you need &eddie.

I had this same problem and it was do to an incorrect value in the third parameter.

so that your main code is:

int main(int argc, char** argv) {
    ROS_INFO("Initializing the robot's control board");
    ros::init(argc, argv, "parallax_board");
    Eddie eddie;
    //plus initialisation of _node
    get_version_srv = node_.advertiseService("get_version", &Eddie::get_board_version, &eddie);
    ros::Rate loop_rate(10);
    return 0;
}
edit flag offensive delete link more
3

answered 2012-11-21 12:04:11 -0600

Saphrosit gravatar image

updated 2012-11-21 12:04:34 -0600

Well your error message seems pretty clear: it simply says that you cannot call advertiseService with those parameters. In particular you are passing function Eddie::get_board_version, which accept no parameters, while the definition of advertiseService expects a function defined as bool(*)(ServiceEvent< MReq, MRes > &).

Check the documentation of ros::NodeHandle.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-11-21 11:53:08 -0600

Seen: 5,263 times

Last updated: Feb 03 '22