MATLAB: Co-simulation between Simulink and Gazebo runs slowly

co-simulationgazeboRobotics System Toolboxsimulink

Hello.
I want to use Gazebo and Simulink to simulate a robot, so I tried this example first. Gazebo runs on a virtual machine on wondiws, and it works as shown in the example.
However, if I set the sampling time to subscribe to the IMU or image to be shorter than the default (e.g. 0.001[s]), the simulation takes a very long time. I am having trouble because I want to subscribe IMUs and images with a sampling time of about 0.001[s].
I don't think it is a lack of PC performance that causes the simulation to take so long. When I look at the resources of my PC, I see that the CPU is the most highly used, only about 80%. The virtual machine that Gazebo is running on also uses 80% of the CPU.
Do you have any ideas on how to reduce the simulation time?
Thank you!

Best Answer

Hi Haruki,
You changed sampling time from 0.01 to 0.001 in the Gazebo Simulink block, which is correct. Currently, this is the way to change sample time.
I think, your concern is more about why Gazebo-Simulink runs slower after changing sample time.
If so, then the sample time is related to simulation step size. If you keep sample time equal to to 0.01 then each simulation step is of 10 msec. While, 0.001 sample time means each simulation step is of 1 msec. Thus, to finish 1 sec simulation with sample time of 0.001 will take longer time ( 1000 steps) than 0.01 ( 100 steps).
Further, the Gazebo Co-Simulation provides synchronized behavior between Gazebo and Simulink blocks. To maintian synchronization, Simulation is carried-out with step-by-step approach, which further add overhead and slow down simulation.
Thanks.