Unwanted timeout of ROS services , using as calling a service in a another service.

9 views (last 30 days)
Hello,
in our current project we try to send data to our more powerfull PC using as service. There the data is processed, which can take some time, but we do not want that the rest of the program contiues before the calculations are finished. At the end the data should be send to to several other PC ,all running ROS ,via a services. The problem that I have is that as the first call (and the calcuation behnid it) can take some time I get the following error if the calculation needs more than roughly 6s:
Error using ros.ServiceClient/call (line 260)
The service server returned an error: "A timeout occurred while waiting for a response of the
service server.".
I call all services without a timeout. To my understanding this would mean that the service could take as much time as it needs. But even if I define a timeout the same error occurs after those 6 or 8 econds, regardless of the timeout defined.
Is there some internal timeout in the ROS toolbox or does my problem has perhaps something to do with the fact that I call a service in a service.
Any hint would be useful.
Thanks in advance
  1 Comment
Christian Kaiser
Christian Kaiser on 2 Apr 2020
Edited: Christian Kaiser on 2 Apr 2020
It seems like there is an internal timeout. I used this basic simple callback function
function resp = test_timenout(~,~,resp)
tic
pause(10)
disp('A service client is calling');
toc
end
And called the service with the following commands:
%Creating a service
testserver = rossvcserver('/test', 'std_srvs/Empty', @test_timenout)
%Creating a client
testclient = rossvcclient('/test')
%Creating a message for the service
testreq = rosmessage(testclient)
%Calling the service
testresp = call(testclient,testreq,'Timeout',7);
For the last line I get the expected error that a timeout occured
Error using ros.ServiceClient/call (line 254)
The service call timed out after waiting 7.00 seconds for a response. Try a longer timeout.
However if I increase the timeout (e. g. up to 20) or if I don't define it I get the following error:
Error using ros.ServiceClient/call (line 260)
The service server returned an error: "A timeout occurred while waiting for a response of the
service server.".
If I decrease the time that the callbackfunction waits to 9s (by replacing pause(10) by pause(9))the error disappears and everthing works fine. Sadly this is not a solution, for my problem

Sign in to comment.

Accepted Answer

Christian Kaiser
Christian Kaiser on 2 Apr 2020
I found a solution to my problem. Someone shown me this forum entry:ROS_answer
Stil I think this should be mentionned when you have to possiblity to choose a time. So without changing anything the maximum timeout you can have is roughly 8-10s, even if you define a higher number you get an error the error message.
For any longer timeout you have to change part of the code in the toolbox. So as mentioned in the link you have to change the code in <folder in which your Matlab installation is>\toolbox\ros\mlros\+ros. To do so you have to open MATLAB as an admin
Open the file ServiceServer.m
Searche for the following line:
obj.ResponseBuilder = com.mathworks.toolbox.ros.service.ServiceResponseBuilder;
For me (MATLAB2019b) it was in the line 173
Then add te line:
obj.ResponseBuilder.setTimeout(1200000);
The number represents the time in milliseconds that will be the maximum timeout, so make it as high as you see fit.
Save the file and execute
rehash toolboxcache
Restart MATLAB
This fixed my problem

More Answers (0)

Categories

Find more on Specialized Messages in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!