MATLAB Answers

Co-simulation between Simulink and Gazebo runs slowly

13 views (last 30 days)
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!

Accepted Answer

Gaurav Bhosale
Gaurav Bhosale on 8 Feb 2021
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.
  3 Comments
Gaurav Bhosale
Gaurav Bhosale on 22 Feb 2021
Hi Haruki,
When you launch Gazebo, it runs faster as it is Play mode. But, Gazebo Co-Simulation provides lock stepping and synchronization between Simulink and Gazebo, which need Gazebo single step call ( world->Step() ). So, the single stepping in Gazebo is takes more time as it is 'Play' - 'Pause' mode. Further, it will be more costly if the Simulation invloves senosor like camera, lidar. i.e. sensor simulation in Gazebo. on other hand, the message exchange adds few seconds but the major processing time is needed for Gazebo stepping.
Therefore, increasing specs of PC will help you at some extend but the incrasing sample time or decreasing sensor update rate can help you more for fast simulation.
Thanks

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!