Ask Your Question
0

Why the ROS client could fail!

asked 2011-08-30 01:00:28 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I have implemented a new server and client. The server can work very well but the client always failed!! The errors are shown below:

The srv file is as follows:

float32 cpg1
float32 cpg2
float32 cpg3
float32 cpg4
---
float32 input1
float32 input2
float32 input3
float32 input4

And the crucial part of the client is:

ros::init(argc, argv, "Cpgvalue");

ros::NodeHandle node;
ros::ServiceClient crawling = node.serviceClient<Crawlers::Cpg>("Cpgdata");
Crawlers::Cpg crawlingdata;
std::vector<float> res;
res.resize(4);
ros::Rate loop_rate(1000);

while(ros::ok())
{
crawlingcpg.CpgNetworkCalculation(feedback);
crawlingdata.request.cpg1 = crawlingcpg.CpgResult[0];
crawlingdata.request.cpg2 = crawlingcpg.CpgResult[1];
crawlingdata.request.cpg3 = crawlingcpg.CpgResult[2];
crawlingdata.request.cpg4 = crawlingcpg.CpgResult[3];

    res[0] = crawlingdata.response.input1;
    res[1] = crawlingdata.response.input2;
    res[2] = crawlingdata.response.input3;
    res[3] = crawlingdata.response.input4;

loop_rate.sleep();

ROS_INFO("Cpg1:[%f]", crawlingcpg.CpgResult[0]); ROS_INFO("Cpg2:[%f]", crawlingcpg.CpgResult[1]);   
if (crawling.call(crawlingdata))
    {      
      ROS_INFO("suceeded!");
    }
    else{
      ROS_INFO("client failed" );
      return 1;     
    }

    ros::spin();
}
return 0;

Whatever I modified, I always got the same error:

[ INFO] [1314708828.730975843]: client failed

Can somebody figure out what is the problem?

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
1

answered 2011-08-30 04:16:29 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Your service callback needs to have the line

return true;

at the end. If it returns false, the service call is considered as failed. If you don't return anything, I believe the behavior is undefined. You actually should get a compiler warning that the function doesn't return a value.

edit flag offensive delete link more

Comments

Yes. Thank you! I suddenly find All my clients cannot work anymore. The roscore is warning it cannot write into the ROS_LOG_DIR, it needs reset! I do not know why? I just updated my ROS sometimes when it needs me to.
Gauss Lee gravatar image Gauss Lee  ( 2011-08-30 04:20:55 -0500 )edit
Yes. Thank you! I suddenly find All my clients cannot work anymore. The roscore is warning it cannot write into the ROS_LOG_DIR, it needs reset! I do not know why? I just updated my ROS sometimes when it needs me to.
Gauss Lee gravatar image Gauss Lee  ( 2011-08-30 04:20:55 -0500 )edit
1

answered 2011-08-30 01:46:48 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I can't see an obvious problem in the client code, given that the server is up an running, when you execute the code. Can you also give the server code for comparison and/or test with the rosservice tool manually?

The one thing that is wrong (but wouldn't change the error message) is that you read in the result before you call the service. That can only work after the service call, i.e. in the "succeeded" branch.

edit flag offensive delete link more

Comments

Thank you for your reply. I do not know how to test with ROSSERVICE TOOL. Could you give me a simple example?
Gauss Lee gravatar image Gauss Lee  ( 2011-08-30 03:24:14 -0500 )edit
rosservice is documented at http://www.ros.org/wiki/rosservice
tfoote gravatar image tfoote  ( 2011-08-30 03:35:02 -0500 )edit
0

answered 2011-08-30 04:26:15 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

It works! Thanks a lot, Lorenz!!!

edit flag offensive delete link more
0

answered 2011-08-30 03:36:53 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi, I upload my full version of codes of the server, hope somebody can find out the errors!

The server can work but the the client always failed!

do not why, quite annoying!

#include "ros/ros.h"
#include <cstdlib>
#include <string.h>
#include <math.h>
#include "Crawlers/Cpg.h"
#include "Crawlers/joint.h"

class Pub{
public:
ros::NodeHandle p;
ros::Publisher pub;
Crawlers::joint data;
std::vector<float> posture;
public:
Pub(ros::NodeHandle s);
bool callback1(Crawlers::Cpg::Request &req,
               Crawlers::Cpg::Response &res);

};
Pub::Pub(ros::NodeHandle s){

p=s;
posture.resize(26);
//head///////////////
posture[0] = 0.0f;
posture[1] = -0.7;
/////leftleg//////////
posture[2]=-0.4f;   //LHipYawPitch
    posture[3]=0.2437f;  //LHipRoll
    posture[4]=-0.925f;  //LHipPitch
    posture[5]=1.8f;   //LKneePitch
    posture[6]=0.75f;   //LAnklePitch
    posture[7]=0.68f;    //AnkleRoll
    /////rightleg/////////
    posture[8]=-0.4f;   //RHipYawPitch
    posture[9]=-0.2437f;  //RHipRoll
    posture[10]=-0.925f;  //RHipPitch
    posture[11]=1.8f;   //RKneePitch
    posture[12]=0.75f;   //RAnklePitch
    posture[13]=-0.68f;    //RAnkleRoll
    ////leftarm////////
    posture[14]= 0.44f;    //LShoulderPitch
    posture[15]=0.1f;         //LShoulderRoll
    posture[16]=-1.58f;         //LElbowYaw
    posture[17]=-0.1f;         //LElbowRoll
    posture[18]=0.0f;            //LWaistYaw
    posture[19]=0.0f;          //RHand
    ////rightarm//////
    posture[20]= 0.44f;           //RShoulderPitch
    posture[21]=-0.1f;         //RShoulderRoll
    posture[22]=1.58f;         //RElbowYaw
    posture[23]=0.1f;         //RElbowRoll
    posture[24]=0.0f;            //RWaistYaw
    posture[25]=0.0f;          //RHand
pub = p.advertise<Crawlers::joint>("jointvalue", 1000);
}




bool Pub::callback1(Crawlers::Cpg::Request &req,
                   Crawlers::Cpg::Response &res){
  ///head
  data.HeadYaw = posture[0];

  data.HeadPitch = posture[1];
  ///leftleg
  data.LHipYawPitch = posture[2];

  data.LHipRoll = posture[3] - 0.25f*req.cpg3;

  data.LHipPitch = posture[4] + 0.4f*req.cpg3;

  data.LKneePitch = posture[5] -0.02f*req.cpg3;

  data.LAnklePitch = posture[6];

  data.LAnkleRoll = posture[7]; 

  ///rightleg
  data.RHipYawPitch = posture[8];

  data.RHipRoll = posture[9] +0.25f*req.cpg4;

  data.RHipPitch = posture[10] + 0.4f*req.cpg4;

  data.RKneePitch = posture[11]-0.02f*req.cpg4;

  data.RAnklePitch = posture[12];

  data.RAnkleRoll = posture[13];

  ///leftarm
  data.LShoulderPitch = posture[14] + 0.4f*req.cpg1;

  data.LShoulderRoll = posture[15] + 0.1f*req.cpg1;

  data.LElbowYaw = posture[16];

  data.LElbowRoll = posture[17] +(-0.1f)*exp(-(( 0.4f*req.cpg1 )-sqrt(0.2))/2.0);


  data.LWristYaw = posture[18];

  data.LHand = posture[19];
  ///rightarm
  data.RShoulderPitch = posture[20] + 0.4f* req.cpg2;

  data.RShoulderRoll = posture[21] - 0.1f* req.cpg2;

  data.RElbowYaw = posture[22];

  data.RElbowRoll = posture[23] + 0.1f*exp(-(( 0.4f*req.cpg2 )-sqrt(0.2))/2.0);

  data.RWristYaw = posture[24];

  data.RHand = posture[25];            
  pub.publish(data);
  ROS_INFO("Cpg1:[%f]", req.cpg1); ROS_INFO("Cpg2:[%f]", req.cpg2);                


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

  ros::init(argc, argv, "jointout");
  ros::NodeHandle s;
  Pub Node(s);
  ros::ServiceServer jointserv = s.advertiseService("Cpgdata", &Pub::callback1, &Node);
  ROS_INFO("ready to send joint data!");
  ros::spin();

}
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: 2011-08-30 01:00:28 -0500

Seen: 310 times

Last updated: Aug 30 '11