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
open_system("read_pose_log.slx");
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.db3
file and the associatedmetadata.yaml
file are attached to this example.Select the desired topic,
/odom
which containsnav_msgs/Odometry
messages.The Read Data block outputs the messages from the ROS 2 bag logfile.
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.
sim(gcs)