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

open_system("read_pose_log.slx");Warning: While loading an object of class 'ros2bagreader': The folder path, C:\Users\echakrab\OneDrive - MathWorks\Documents\MATLAB\ExampleManager\echakrab.myBdoc.test\ros-ex06708927\ros2_bag.db3, is invalid or the folder does not exist.
Set Up Model
Open the Read Data block mask to load a ROS 2 bag logfile (
.db3) from the working folder.Click the Load logfile data link.
Browse for the logfile and specify a time offset or limited duration if needed. The
ros2_bag.db3file and the associatedmetadata.yamlfile are attached to this example.Select the desired topic,
/odomwhich containsnav_msgs/Odometrymessages.The Read Data block outputs the messages from the ROS 2 bag logfile.
A bus selector extracts the xy-position from the
nav_msgs/Odometrymessages.
Run Model
The block plays back data in sync with the simulation time. The Record plot displays the robot position over time.
sim(gcs)
