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

ROS Service Creation error

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

Yeshasvi Yeshi gravatar image

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

sai gravatar image

Hello,

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");
//biclops.Initialize(path);
return true;
}


  int main(int argc, char **argv)
{

       ros::init(argc, argv, "homing_sequence_server");
       ros::NodeHandle n("~");
       argv[1]="/home/yeshi/catkin_ws/src/biclops/BiclopsDefault.cfg";
       ros::ServiceServer service = n.advertiseService("homing_sequence", Homing);
       ROS_INFO("Ready for Homing Sequence");
       ros::spin();

       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

Comments

Please provide the error message

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

2 Answers

Sort by ยป oldest newest most voted
3

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

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

Comments

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 -0600 )edit
-1

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

Yeshasvi Yeshi gravatar image

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

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");
//biclops.Initialize(&req.path);
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]);
argv[1]="/home/yeshi/catkin_ws/src/biclops/BiclopsDefault.cfg";

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

    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" );
    getchar();
    //return 0;
}
else
        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() ){

spin();


loop_rate.sleep();

}


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

Comments

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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 804 times

Last updated: Jul 24 '14