18.ROS2 time related API

 

The time-related APIs of ros2 include Rate, Time, Duration, Time and Duration operations, etc., which are explained below.

 

2. Rate

In addition to timers, ROS2 also provides the Rate class, through which the running frequency of the program can also be controlled;

The Rate object in rclpy can be created through nodes. The sleep() function of the Rate object needs to be executed in a child thread, otherwise it will block the program.

Example: Periodically output a piece of text.

 

3.Time

Example: Create a Time object and call its functions.

 

4.Duration

Example: Create a Duration object and call its function.

 

5. Time and Duration operations

Example:Time and Duration related operations.