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

Service Server refuses to advertise my service/function?

asked 2012-04-17 04:05:15 -0600

George B. gravatar image

updated 2014-01-28 17:11:59 -0600

ngrennan gravatar image

Hello I'm writing a server whose job is to offer a 6DOF pose estimation, but I'm having problems advertising it as it seems that I'm giving it a function with too manny argument, even tough I'm following the tutorial very closely.

This is the relevant part from the node's main:

 ros::init(argc, argv, "epsilon");
 ros::NodeHandle nh("~");
 PoseServer server;
 ros::ServiceServer service = nh.advertiseService("/epsilon/get_pose", server.compute_Pose);
 ROS_INFO("Ready to estimate pose.");
 ros::spin();
 return 0;

And this is how I implemented compute_Pose within the PoseServer class:

bool PoseServer::compute_Pose(epsilon::Pose::Request &req,
                          epsilon::Pose::Response &res)
 {
   //Here I calculate the pose and store it as a string for now
   res.pozitie = pose_string;
 }

And this is the Pose.srv as I've named my .srv file and the package's working name is epsilon, it's not really supposed to work with string but I wanted to start with something simple and try to advertise it first:

string A
---
string pozitie

The error I got is:

no matching function for call to ‘ros::NodeHandle::advertiseService(const char [18], <unresolved overloaded function type>)’
note: candidates are:
/opt/ros/electric/stacks/ros_comm/clients/cpp/roscpp/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*)
//And a whole list of other candidate templates
/ros/node_handle.h:1111:17: note:   candidate expects 1 argument, 2 provided

I think it's telling that I have to add something more than req and res or less but I don't think that's allowed or maybe to declare them in another fashion but I don't see exactly how.

Edited to add my cmakelist.txt

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

# Set the build type.  Options are:
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
#  Debug          : w/ debug symbols, w/o optimization
#  Release        : w/o debug symbols, w/ optimization
#  RelWithDebInfo : w/ debug symbols, w/ optimization
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)


rosbuild_init()

rosbuild_add_boost_directories()

#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

#uncomment if you have defined messages
rosbuild_genmsg()
#uncomment if you have defined services
rosbuild_gensrv()

rosbuild_add_executable(epsilon_node_1 src/epsilon_node_1.cpp)


#this is where I try to fix the boost bind problem the way you showed me
rosbuild_link_boost(epsilon_node_1 bind)
#How I solved it in the past
target_link_libraries(epsilon_node_1 ${Boost_FILESYSTEM_LIBRARY}    ${Boost_SYSTEM_LIBRARY} )

Maybe I'm reading the boost site wrong but I think bind should be in the bind library correct?

Edit: Now I'm not getting any more boost linking problems but it won't see the PoseServer constructor or computePose,even tough they're both clearly public, for either of the solutions this is how I advertise them in main:

//ros::ServiceServer service = nh.advertiseService("/epsilon ...
(more)
edit retag flag offensive close merge delete

Comments

Thank you Lorenz, both versions work and thank you for the tutorial it was exactly what I was looking for.

George B. gravatar image George B.  ( 2012-04-17 05:20:59 -0600 )edit

2 Answers

Sort by » oldest newest most voted
3

answered 2012-04-17 04:44:18 -0600

Lorenz gravatar image

The way you specify the pose callback is wrong. Have a look at this tutorial. Alternatively you can use boost::bind, e.g.:

ros::ServiceServer service = nh.advertiseService<epsilon::Pose::Request, epsilon::Pose::Response>("/epsilon/get_pose", boost::bind(&PoseServer::compute_Pose, server, _1, _2));

Your method compute_Pose needs to be public.

edit flag offensive delete link more
0

answered 2012-04-18 00:48:13 -0600

George B. gravatar image

updated 2012-04-18 04:48:35 -0600

Lorenz, I'm sorry but your answer both version of them are giving another error:

CMakeFiles/epsilon_node_1.dir/src/epsilon_node_1.o: undefined reference to symbol 'boost::system::system_category()'

I've already had problems with boost in this project, which I've solved according to the solution in that question and I've expanded it into:

target_link_libraries(epsilon_node_1 ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_BIND_LIBRARY})

But this doesn't solve the problem, do you know by any chance the name CMake needs for the bind to work?

edit flag offensive delete link more

Comments

It's hard to guess what's wrong without seeing your complete CMakeLists. But to link against boost, the best way is to use rosbuild_link_boost. http://ros.org/wiki/rosbuild/CMakeLists#rosbuild_link_boost Though, specifying the libraries by hand should work, too.

Lorenz gravatar image Lorenz  ( 2012-04-18 01:47:22 -0600 )edit

The strange thing is my colleagues who have installed ros for longer don't need to explicitly link boost, but me and my friend who have just started ros with ubuntu 11.10 and ros electric do. I've looked at the tutorial and rosbuild_add_boost_directories() unfortunately doesn't seem to help.

George B. gravatar image George B.  ( 2012-04-18 04:39:14 -0600 )edit

First, get rid of the boost entries in target_link_libraries. Remove bind from rosbuild_link_boost and add the other libraries: rosbuild_link_boost(epsilon_node_1 filesystem system). Google finds this link that might also help: http://ubuntuforums.org/showthread.php?t=1657777

Lorenz gravatar image Lorenz  ( 2012-04-18 05:43:06 -0600 )edit

This solved the boost linking problems, but unfortunately it has problems seeing the methods to advertise them again, if you could please look over the edit I id to the question where I added the lines were I advertise them and the errors that pop out at both styles of advertising.

George B. gravatar image George B.  ( 2012-04-18 07:06:44 -0600 )edit

Question Tools

Stats

Asked: 2012-04-17 04:05:15 -0600

Seen: 3,805 times

Last updated: Apr 18 '12