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);
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.