Main Content

Time Stamp a ROS 2 Message Using Current Time in Simulink

This example shows how to time stamp a ROS 2 message with the current system time of your computer. Use the Current Time block and assign its output to the stamp field of a std_msgs/Header message. Publish the message on a desired topic.

Open the model. The model uses a Bus Assignment block to add the Current Time output to the stamp field of the ROS 2 message.

open_system("current_time_ros2_example_model.slx")

Run the model. The Publish block should publish the Header message with the current system time.

sim("current_time_ros2_example_model.slx");