How Gazebo Simulation for Robotics System Toolbox Works
Robotics System Toolbox™ provides a co-simulation framework that enables you to use robotics algorithms in MATLAB® and Simulink® and visualize their performance in a virtual simulation environment. This environment uses the Gazebo Simulator.
Understanding how this simulation environment works can help you troubleshoot issues and customize your models.
Communication with 3-D Simulation Environment
When you use Robotics System Toolbox to run your algorithms, MATLAB or Simulink co-simulates the algorithms in the simulation environment.
On the host computer, Simulink or MATLAB sends actuation data and set commands to the Gazebo Co-Simulation Plugin on the target Linux machine. The plugin passes this information to the Gazebo Simulator, which returns sensor data and model information through the plugin to Simulink or MATLAB on the host computer.
The diagram summarizes the communication between MATLAB or Simulink and the simulation environment.
Time Synchronization
During co-simulation, you can pause Simulink and the Gazebo Simulator at any time using Pause. Gazebo pauses one time step ahead of the simulation.
The gap is due to the co-simulation time sequence:
Sensor data and actuation commands are exchanged at the correct time step. The execution steps Gazebo first, then Simulink. When paused, simulation execution is still at the time step executed by Gazebo, but Simulink remains on the previous step time until you resume the model.
Recommendation to Improve Performance
Real-Time Factor — Increase the real-time factor (for the Gazebo GUI or .world file) to greater than
1
if accuracy is not a requirement.Simulink Sample Time — Increase the sample time (in the Gazebo Simulink block) greater than
1
msec to get a faster simulation.Use Custom Messages to Improve Performance with Simulink Block Reduction — If several Gazebo Read or Gazebo Apply blocks are doing similar tasks, then reduce the number of blocks by combining them into one or a few Subscribe and Publish blocks using custom messages.
Run MATLAB and Gazebo on Same Machine — To improve simulation performance, run MATLAB and Gazebo on the same machine.