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

Service client C++ tutorial simple question

asked 2015-07-31 14:42:07 -0500

OmoNaija gravatar image

I have a question about the code:

if (client.call(srv))
 {
   ROS_INFO("Sum: %ld", (long int)srv.response.sum);
 }
 else
 {
   ROS_ERROR("Failed to call service add_two_ints");
   return 1;
 }

Why is there a return value of 1? Is a return value just always required when calling a service?

edit retag flag offensive close merge delete

Comments

You removed the function around your snippet, so we can only guess what the return value means. Is it the return value of your program?

NEngelhard gravatar image NEngelhard  ( 2015-08-01 04:33:14 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-08-01 10:05:39 -0500

The return value of client.call(srv)?

Then the return value is always 1 (true - boolean) when the service succeeded in calling it. If for example the node for the service would have been stopped for any reason, the service would fail to call, because it does not exist, then you should get a 0 (false).


The return value of the else statement?

The return value of the else statement would be for your node or a function, anything else than 1 would indicate another process/calling function checking your programs/functions return and see if it is not 0 that something went wrong with it.

0 normally indicates, all right, sometimes it is the other way round ...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-07-31 14:42:07 -0500

Seen: 818 times

Last updated: Aug 01 '15