0
$\begingroup$

Rosanswers logo

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.


Originally posted by kotoko on ROS Answers with karma: 122 on 2016-08-03

Post score: 0

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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.


Originally posted by kotoko with karma: 122 on 2016-08-04

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by yijiangh on 2017-05-14:
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"?

$\endgroup$
0
$\begingroup$

Rosanswers logo

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.


Originally posted by yijiangh with karma: 131 on 2017-05-14

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.