Main Content

Current Time

Retrieve current ROS 2 time or system time

Since R2022b

  • ROS 2 Current Time

Libraries:
ROS Toolbox / ROS 2

Description

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

If the use_sim_time ROS 2 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 starts. Step 2. Check if the /use_sim_time ROS parameter is true. Step 3. If true, subscribe to the /clock topic and wait to receive time. If false, get system time. Step 4. Output the received time as the current time.

Examples

Ports

Output

expand all

ROS 2 time, returned as a bus signal or a scalar. The Output format parameter determines the format of this output port. The bus represents a builtin_interfaces/Time ROS 2 message with sec and nanosec elements. The scalar is the ROS 2 time in seconds. If the block does not receive a time from the /clock topic, this output is 0.

Data Types: bus | double

Parameters

expand all

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

Interval between outputs, specified as a numeric scalar.

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

Extended Capabilities

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

Version History

Introduced in R2022b