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

Service call returning false

asked 2016-08-03 05:28:22 -0500

kotoko gravatar image

Hello,

I'm trying to make a service call that keeps returning false using c++ code but works fine in the command line.
Can't find much information on reasons for the call function to return to or failure causes.

Here is the command line call:

rosservice call /service/url "request: '1.0'"

Outcome:

[Cheery success message from server]

And the cpp code:

bool ExampleListener::send(const std::string& _request, std::string& _resp) {
  namespace__::ss::Request rosRequest;
  rosRequest.request = _request;
  namespace__::ss::Response rosResponse;

  if(client.call(rosRequest, rosResponse)) {
      _resp = rosResponse.response;
      return true;
  }else {
      ROS_ERROR("Call to server failed, because of reasons.");
      return false;
  }
}

// some other place in code
std::string _resp;
send("1.0", _resp);

The service is defined as follows:

string request
---
string response

Outcome:

[ERROR] [1470218877.683985359, 8.242000000]: Call to server failed, because of reasons.

Any info would be greatly appreciated.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-08-04 07:40:59 -0500

kotoko gravatar image

In case this helps anybody, what I did to make it work was to create the server as temporary (which I'm assuming is what is done in the command line call).

Why this works, I have no idea. If anyone figures it out please share.

edit flag offensive delete link more

Comments

Hi kotoko,

I encountered the same problem.

My case is that I was holding the service server in a standalone server and have service call in a qt-pushbutton slot function, but the service client failed to connect the service. Could you specify more on how do you "create the server as temporary"?

yijiangh gravatar image yijiangh  ( 2017-05-14 13:21:22 -0500 )edit
1

answered 2017-05-14 14:17:39 -0500

In my scenario, the problem is that my serviceClient is initialized before my service server node is launched. For RvizPanel UI service request for a standalone node, please check this amazing discussion (and code!) from Victor L.

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2016-08-03 05:28:22 -0500

Seen: 3,034 times

Last updated: May 14 '17