Main Content

Log ROS Messages from Simulink to a Rosbag Logfile

This example enables you to save ROS message data from Simulink® to a rosbag file.

A rosbag or bag is a file format in ROS for storing message data. These bags are often created by subscribing to one or more ROS topics, and storing the received message data in an efficient file structure. Using the ROS Logger app, you can log ROS messages from Simulink® models to rosbag files.

Open the Simulink model. This model is configured for ROS Simulation. To configure a new model for ROS simulation, under Apps, select Robot Operating System (ROS) and specify the appropriate ROS network configuration parameters.


To open the ROS Logger app dialog, under Simulation tab, from Prepare section, select ROS Logger.

Follow these steps to configure the signals to be logged and the rosbag file parameters:

  • Ensure that Enable ROS signal logging to ROS Bag file is checked.

  • Select the signals to be logged in the rosbag file by checking their respective checkboxes under the Enable column.

  • The default name of the generated rosbag file will be modelName_mmddyy_hh_mm_ss.bag. To provide a custom name, from the Logfile name dropdown, select Custom. Then specify the desired File name.

  • Specify the Compression format to be uncompressed, bz2 or lz4.

  • Specify the desired chunk size for writing, in bytes.

Initialize the ROS network.

Launching ROS Core...
......Done in 7.0793 seconds.
Initializing ROS master on
Initializing global node /matlab_global_node_26159 with NodeURI http://ah-avijayar:49405/ and MasterURI http://localhost:51228.

Simulate the model.

Simulation Complete. Start logging ROS bag file...
Successfully logged ROS bag file to logROSMessagesFromSimulinkExampleModel_061622_15_56_22.bag.

After simulation, logging messages to rosbag file begins and completes with the success message on the Diagnostic Viewer.