Why isn't the response filled if my service returns false?
I have a service callback:
bool myServiceCallback(service_test::MyService::Request &req,
service_test::MyService::Response &res)
{
ROS_INFO_STREAM("Input string = " << req.input);
if (req.input.empty())
{
res.text_error = "";
return true;
}
else
{
res.text_error = "Not empty!";
return false;
}
}
It returns true if the request string is empty, false otherwise.
It also fills a text_error
string to indicate the user what happened in case the service returns false.
The client is like this:
ros::ServiceClient client = nh.serviceClient<service_test::MyService>("my_service");
bool return_value;
service_test::MyService srv;
srv.request.input = "bla";
return_value = client.call(srv);
ROS_INFO_STREAM("Return value = " << (return_value ? "True": "False"));
ROS_INFO_STREAM("Response text error = " << srv.response.text_error);
The terminal output of the client node is the following:
[ INFO] [1501836030.156100067]: Return value = False
[ INFO] [1501836030.156145499]: Response text error =
It feels like the response is not filled if a service returns false. Why is that? How can I return an error string indicating what was wrong?
Using an action instead might help me solve this issue, but I would like to keep the simplicity of a blocking service call.