Long delay calling ROS service

9 views (last 30 days)
Bryce King
Bryce King on 20 Sep 2021
Commented: Bryce King on 7 Oct 2021
Hello, I've been having some issues with Matlab's ROS service caller since upgrading from release 2020a to 2021a. I have a robot running in Gazebo and I'm trying to make a call on the '/gazebo/apply_body_wrench' service in Matlab, but it consistantly takes 7-8 seconds for the client to receive a response from the server. When making the same service call natively in ROS via the service caller plugin in rqt_gui, there is no response delay. What can be done to reduce the long delay while calling the service from Matlab?

Answers (1)

Cam Salzberger
Cam Salzberger on 27 Sep 2021
Hello Bryce,
I wasn't able to reproduce this on my machine with R2021a and the standard Melodic VM. I tested with both the PR2 simulator and the Gazebo Empty worlds, and both returned immediately to my service call, whether it was successful or not. Setting different start times or durations for applying the wrench didn't matter either.
The only suggestions I can give you are general ones then:
  • Try creating the service client in MATLAB using DataFormat-struct. This feature was implemented specifically to improve performance, though using object messages would not be responsible for the 7-8 second delay you are seeing, so expect improvement to be marginal.
  • Ensure that your VM has sufficient resources. Increase the amount of RAM, cores, and memory it is allowed to use, as Gazebo can be quite resource-intensive.
  • Try calling the service with the profiler running (profile on; call(client, msg); profile off; profile viewer) to see where the delay is occurring. If it's in "waiting" method, then the slow-down is on the external side of things.
  • Check if you encounter the same issue with all services. Shut down Gazebo, start a new Core, and just try running in a Melodic terminal:
rosrun roscpp_tutorials add_two_ints_server
Then make a client and call that service from MATLAB.
client = rossvcclient('/add_two_ints');
msg = rosmessage(client);
msg.A = 1;
msg.B = 2;
call(client, msg)
If this also sees the delay, then the issue is probably with the network communication or the VM. If you do not see the slow down, then the issue is probably with Gazebo or that specific world/model/command.
-Cam
  1 Comment
Bryce King
Bryce King on 7 Oct 2021
Hello Cam, thanks for your detailed response. The delay did not occur in version 2020a with the same VM resource settings, so I'm inclined to believe that isn't the source of the problem. After updating from Matlab version 2021a Update 1 to version 2021a Update 5, it seems like the service is functioning properly again. I tested it on a computer running Ubuntu natively and the response time was faster, as expected, but even in the VM the response time seems fine to me now.

Sign in to comment.

Categories

Find more on Network Connection and Exploration in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!