Ask Your Question

ROS Service Creation error

asked 2014-07-23 20:16:22 -0500

Yeshasvi Yeshi gravatar image

updated 2014-07-23 20:57:18 -0500

sai gravatar image


I am trying to write a ros service node with the fillowing code

 #include <ros/ros.h>
 #include <biclops/HomingSequence.h>
 #include <Biclops.h>
 #include <PMDUtils.h>

bool Homing(biclops::HomingSequence::Request &req){

ROS_INFO("Performing Homing Sequence");
return true;

  int main(int argc, char **argv)

       ros::init(argc, argv, "homing_sequence_server");
       ros::NodeHandle n("~");
       ros::ServiceServer service = n.advertiseService("homing_sequence", Homing);
       ROS_INFO("Ready for Homing Sequence");

       return 0;


But i am getting errors during bulid as advertiseService arguments are not right. I followed the ros tutorials for service creation. Kindly help me understand what i am missing

edit retag flag offensive close merge delete


Please provide the error message

sai gravatar image sai  ( 2014-07-23 20:57:41 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2014-07-23 21:06:48 -0500

kmhallen gravatar image

The service server function callback needs a request and response.

bool Homing(biclops::HomingSequence::Request &req, biclops::HomingSequence::Response &res);
edit flag offensive delete link more


Now I am tried to put the service server in the main node and launched the node but I cannot find the service through service list or in node info.

Yeshasvi Yeshi gravatar image Yeshasvi Yeshi  ( 2014-07-24 04:49:45 -0500 )edit

answered 2014-07-24 04:24:03 -0500

Yeshasvi Yeshi gravatar image

updated 2014-07-24 05:14:05 -0500

Thank you it worked. Now when I launch the server.cpp node I could able to see the service in rosnode info or service list but if i put the service inside the main node.cpp file I cannot see the service being advertised

#include <ros ros.h=""> #include <cstdio> // for FILE defn #include <iostream> // for cout, etc #include <time.h> // for clock_t and clock #include <list> #include <string> #include <cstring> #include <sensor_msgs jointstate.h=""> #include "turtlesim/Velocity.h" #include <biclops homingsequence.h="">

using namespace std; using namespace ros;

#include <biclops.h> #include <pmdutils.h>

// Defines which axes we want to use. int axisMask=Biclops::PanMask + Biclops::TiltMask;;

// Pointers to each axis (populated once controller is initialized). PMDAxisControl *panAxis = NULL; PMDAxisControl *tiltAxis = NULL;

// THE interface to Biclops Biclops biclops_obj;

ros::Subscriber key_sub; ros::Publisher joint_pub; sensor_msgs::JointState joint_state;

bool Homing(biclops::HomingSequence::Request &req, biclops::HomingSequence::Request &res){

ROS_INFO("Performing Homing Sequence");
return true;


//---------------------------------------------------------------------------- int main (int argc, char *argv[]) {

ros::init(argc,argv,"Biclops"); ROS_INFO("node creation"); ros::NodeHandle nh; ros::Rate loop_rate(10);

  // ROS_INFO("ARGV : %s ",argv[1]);

ROS_INFO( "\n\nBasic Biclops Running Example\n\n" );

    cout<<"Initialization Routine"<<biclops_obj.Initialize(argv[1])<<endl;

if (!biclops_obj.Initialize(argv[1]))

    ROS_INFO( "Failed to open Biclops Communication\n" );
    ROS_INFO( "Press Enter key to terminate...\n" );
    //return 0;
        ROS_INFO( "Succeed to open Biclops Communication\n" );

//Homing sequence Service
ros::ServiceServer service =nh.advertiseService("homing_sequence",Homing);

// Get shortcut references to each axis.
panAxis = biclops_o
while(ros::ok() ){




return 0;


What am I missing. I made the same changes as needed for the server.cpp file in the CMakeLists.txt. Please help me

edit flag offensive delete link more


I noticed that when I use the launch file the nodes are executed from devel space of catkin_ws but and in that case I cant see the service listed but if i source the devel/setup.bash in the package then i can see the service listed. can someone please explain what is happening

Yeshasvi Yeshi gravatar image Yeshasvi Yeshi  ( 2014-07-24 05:28:01 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-07-23 20:16:22 -0500

Seen: 308 times

Last updated: Jul 24 '14