ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
2

pass additional arguments into advertiseService

asked 2012-10-25 05:07:27 -0500

bajo gravatar image

updated 2014-01-28 17:14:03 -0500

ngrennan gravatar image

Hi,

is there a way to pass additional arguments into advertiseService ? When i use a Subscriber i can use boost::bind to pass arguments to the callback function. Like this:

ros::Subscriber sub = nh.subscribe<cob_people_detection::Commands> ("/tuw_acin_eva/voice_commands", 1, boost::bind(commandCallback, _1, &sensor_message_gateway_open_client));

Can i adapt this approach to make it work with advertiseService ? I tried it with this

ros::ServiceServer service = nh.advertiseService<tuw_acin_eva::VoiceCommands> ("process_voice_commands", boost::bind(processVoiceCommands, _1, &sensor_message_gateway_open_client));

but it does not work.


Edit: 1

Sorry for not including the complete error message. Here it is now.

[ rosmake ] Last 40 linesw_acin_eva: 4.6 sec ]                    [ 1 Active 50/51 Complete ]
{-------------------------------------------------------------------------------
  [ 57%] [ 57%] Built target rospack_gensrv_all
  Built target rosbuild_precompile
  make[3]: Entering directory `/home/bajo/workspace/tuw_acin_eva/build'
  make[3]: Entering directory `/home/bajo/workspace/tuw_acin_eva/build'
  make[3]: Entering directory `/home/bajo/workspace/tuw_acin_eva/build'
  make[3]: Leaving directory `/home/bajo/workspace/tuw_acin_eva/build'
  make[3]: Leaving directory `/home/bajo/workspace/tuw_acin_eva/build'
  [ 85%] [ 85%] Built target tuw_acin_eva_main
  Built target tuw_acin_eva_facefollower
  Scanning dependencies of target tuw_acin_eva_cob_control
  make[3]: Leaving directory `/home/bajo/workspace/tuw_acin_eva/build'
  make[3]: Entering directory `/home/bajo/workspace/tuw_acin_eva/build'
  [100%] Building CXX object CMakeFiles/tuw_acin_eva_cob_control.dir/nodes/tuw_acin_eva_people/src/tuw_acin_eva_cob_control.o
  In file included from /opt/ros/fuerte/include/ros/ros.h:45:0,
               from /home/bajo/workspace/tuw_acin_eva/nodes/tuw_acin_eva_people/src/tuw_acin_eva_cob_control.cpp:13:
  /opt/ros/fuerte/include/ros/node_handle.h: In member function ‘ros::ServiceServer ros::NodeHandle::advertiseService(const string&, const boost::function<bool(S&)>&, const VoidConstPtr&) [with S = tuw_acin_eva::VoiceCommands, std::string = std::basic_string<char>, ros::VoidConstPtr = boost::shared_ptr<const void>]’:
  /home/bajo/workspace/tuw_acin_eva/nodes/tuw_acin_eva_people/src/tuw_acin_eva_cob_control.cpp:288:181:   instantiated from here
  /opt/ros/fuerte/include/ros/node_handle.h:1087:5: error: no matching function for call to ‘ros::AdvertiseServiceOptions::initBySpecType(const string&, const boost::function<bool(tuw_acin_eva::VoiceCommands&)>&)’
  /opt/ros/fuerte/include/ros/node_handle.h:1087:5: note: candidate is:
  /opt/ros/fuerte/include/ros/advertise_service_options.h:104:8: note: template<class Spec> void ros::AdvertiseServiceOptions::initBySpecType(const string&, const typename Spec::CallbackType&)
  In file included from /usr/include/boost/bind.hpp:22:0,
               from /opt/ros/fuerte/include/ros/publisher.h:35,
               from /opt/ros/fuerte/include/ros/node_handle.h:32,
               from /opt/ros/fuerte/include/ros/ros.h:45,
               from /home/bajo/workspace/tuw_acin_eva/nodes/tuw_acin_eva_people/src/tuw_acin_eva_cob_control.cpp:13:
  /usr/include/boost/bind/bind.hpp: In member function ‘R boost::_bi::list2<A1, A2>::operator()(boost::_bi::type<R>, F&, A&, long int) [with R = bool, F = bool (*)(tuw_acin_eva::VoiceCommandsRequest_<std::allocator<void> >&, tuw_acin_eva::VoiceCommandsResponse_<std::allocator<void> >&), A = boost::_bi::list1<tuw_acin_eva::VoiceCommands&>, A1 = boost::arg<1>, A2 = boost::_bi::value<ros::ServiceClient*>]’:
  /usr/include/boost/bind/bind_template.hpp:32:59:   instantiated from ‘boost::_bi::bind_t<R, F, L>::result_type boost::_bi::bind_t<R, F, L>::operator()(A1&) [with A1 = tuw_acin_eva::VoiceCommands, R = bool, F = bool (*)(tuw_acin_eva::VoiceCommandsRequest_<std::allocator<void> >&, tuw_acin_eva::VoiceCommandsResponse_<std::allocator<void> >&), L = boost::_bi::list2<boost::arg<1>, boost::_bi::value<ros::ServiceClient*> >, boost ...
(more)
edit retag flag offensive close merge delete

Comments

It should work. Please be more specific. Can you show us the complete error message? Make sure you have a look at http://ros.org/wiki/Support

Lorenz gravatar image Lorenz  ( 2012-10-26 01:59:11 -0500 )edit

Thank you for your comment. I posted the complete error down below.

bajo gravatar image bajo  ( 2012-10-29 00:36:27 -0500 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2012-10-29 00:10:34 -0500

bajo gravatar image

updated 2012-10-29 01:11:45 -0500

I think i found my problems. I had a few of them. :)

First i had to add the Request and Response to my Service. So i changed it from

ros::ServiceServer service = nh.advertiseService<tuw_acin_eva::VoiceCommands> ("process_voice_commands", boost::bind(processVoiceCommands, _1, &sensor_message_gateway_open_client));

to

ros::ServiceServer service = nh.advertiseService<tuw_acin_eva::VoiceCommands::Request, tuw_acin_eva::VoiceCommands::Response>("process_voice_commands", boost::bind(processVoiceCommands, _1, _2, &sensor_message_gateway_open_client));

Then i had a typo in another line, which may have been a problem too. Now it compiles, i still have to write the rest so i can test it. But for now thanks for the help.

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

Stats

Asked: 2012-10-25 05:07:27 -0500

Seen: 2,165 times

Last updated: Oct 29 '12