Main Content

Time Stamp a ROS Message Using Current Time in Simulink

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

Connect to a ROS network.

rosinit
Launching ROS Core...
Done in 0.93448 seconds.
Initializing ROS master on http://172.30.144.24:52786.
Initializing global node /matlab_global_node_59435 with NodeURI http://dcc796195glnxa64:38671/ and MasterURI http://localhost:52786.

Open the Simulink model provided with this example. The model uses a Bus Assignment block to add the Current Time output to the Stamp field of the ROS message.

open_system('current_time_stamp_message.slx')

simulink pic.jpg

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

sim('current_time_stamp_message.slx')

Shut down the ROS network.

rosshutdown
Shutting down global node /matlab_global_node_59435 with NodeURI http://dcc796195glnxa64:38671/ and MasterURI http://localhost:52786.
Shutting down ROS master on http://172.30.144.24:52786.