ROS Service Creation error
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
Asked by Yeshasvi Yeshi on 2014-07-23 20:16:22 UTC
Answers
The service server function callback needs a request and response.
bool Homing(biclops::HomingSequence::Request &req, biclops::HomingSequence::Response &res);
Asked by kmhallen on 2014-07-23 21:06:48 UTC
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.
Asked by Yeshasvi Yeshi on 2014-07-24 04:49:45 UTC
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
include // for FILE defn
include // for cout, etc
include // for clock_t and clock
include
include
include
include
include "turtlesim/Velocity.h"
include
using namespace std; using namespace ros;
include
include
// 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
Asked by Yeshasvi Yeshi on 2014-07-24 04:24:03 UTC
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
Asked by Yeshasvi Yeshi on 2014-07-24 05:28:01 UTC
Comments
Please provide the error message
Asked by sai on 2014-07-23 20:57:41 UTC