Main Content

Play Back Data from ROS 2 Bag Logfile in Simulink®

Use the Read Data block to play back data from a ROS 2 bag logfile.

Load Model


Set up Model

  1. Open the Read Data block mask to load a ROS 2 bag logfile (.db3).

  2. Click the Load logfile data link.

  3. Browse for the logfile and specify a time offset or limited duration if needed. The ros2_bag.db3 file and the associated metadata.yaml file are attached to this example.

  4. Select the desired topic, /odom which contains nav_msgs/Odometry messages.

  5. The Read Data block outputs the messages from the ROS 2 bag logfile.

  6. A bus selector extracts the xy-position from the nav_msgs/Odometry messages.

Run Model

The block plays back data in sync with the simulation time. The Record plot displays the robot position over time.