Main Content

Current Time

Retrieve current ROS time or system time

Since R2019b

  • Current Time block

ROS Toolbox / ROS


The Current Time block outputs the current ROS or system time. ROS Time is based on the system clock of your computer or the /clock topic being published on the ROS node.

Use this block to synchronize your simulation time with your connected ROS node.

If the use_sim_time ROS parameter is set to true, the block returns the simulation time published on the /clock topic. Otherwise, the block returns the system time of your machine.

Current time block workflow. Step 1. Node start. Step 2. Check whether /use_sim_time ROS parameter is true. Step 3. If true, subscribe to /clock topic and wait to receive time. If false, get system time. Step 4. Output the received time as the current time.



expand all

ROS time, returned as a bus signal or a scalar. The bus represents a rosgraph_msgs/Clock ROS message with Sec and NSec elements. The scalar is the ROS time in seconds. If no time has been received on the /clock topic, the block outputs 0.

Data Types: bus | double


expand all

Format of ROS Time output, specified as either bus or double.

Interval between outputs, specified as a numeric scalar.

For more information, see Specify Sample Time (Simulink).


  • To set the use_sim_time parameters and get time from a /clock topic:

    Connect to a ROS network, then use the Set Parameter block or set the parameter in the MATLAB® command window:

    ptree = rosparam;

    Usually, the ROS node that publishes on the /clock topic sets up the parameter.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2019b

See Also



External Websites