MATLAB Answers

Long delay calling ROS service

30 ビュー (過去 30 日間)
Bryce King
Bryce King 2021 年 9 月 20 日 13:28
コメント済み: Bryce King 2021 年 10 月 7 日 8:06
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?

回答 (1 件)

Cam Salzberger
Cam Salzberger 2021 年 9 月 27 日 13:55
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 件のコメント
Bryce King
Bryce King 2021 年 10 月 7 日 8:06
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.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by