Overview

OpenHiva provides a set of timer interfaces (Hive Timer), which are applicable to scenarios where a function needs to be periodically executed or a timer is required. The Hive Timer provides interfaces whose input parameters are the same as those of the native ROS Timer, including creating a timer, starting a timer, stopping a timer, setting a period (SetPeriod), and checking whether a timer is valid (IsValid). The native ROS Timer provides various interfaces for creating timers. The Hiva Timer provides only common interfaces for creating timers and does not provide interfaces for configuring timers by using TimerOptions.

The framework provides different timer interfaces for different clock sources. Currently, the following clock sources are supported:

  • Hiva clock: analog clock. You can enable or disable the clock by setting use_sim_time to True or False in the configuration file.
  • Wall clock: system clock, which can be modified and is usually consistent with the external time.
  • Steady clock: monotonic clock of the system. It refers to the time elapsed since the system starts. The time increases absolutely and cannot be modified. The time is reset when the system restarts.

The Hiva Timer provides the following timer interfaces.

  • Before invoking the timer interfaces, invoke OpenHiva::Init to complete initialization.
  • The timer task is susceptible to the system time. Therefore, do not change the system time when the timer task is in progress.
  • When the timer is started, specify whether to use the Hiva clock immediately to avoid clock source switchover. The timer is not notified of the clock source switchover. Therefore, after the clock source is switched, the timer still counts the time based on the clock source before the switchover. If the clock source is switched, you must restart the node to use the new clock source.
  • Based on product requirements, deterministic and non-deterministic timers are both required. Therefore, input parameters are used to specify whether a timer is a deterministic timer and the group name to which the timer belongs. For a deterministic timer, if a specific group needs to be specified to process timer callback, the group that processes the timer must be specified when the group is created so that timer-related processing can be performed in the working thread of the group.
  • CreateTimer
    • The clock source is configurable. The Hiva clock or wall clock is supported. The Hiva clock is preferentially used for interfaces. When the CreateTimer interface is invoked, the system reads the configuration file. If the use_sim_time parameter is set to True, the Hiva clock is used. Otherwise, the wall clock is used. For details about more parameters, see Configuration Management.
    • The implementation principle is the same as that of the original ROS timer. The created timer uses the timing wakeup mechanism of the operating system instead of the hardware timer.
  • CreateWallTimer
    • The clock source cannot be configured. Only the wall clock is supported.
    • Based on the hardware clock device provided by the system, the created timer directly uses the hardware timer and does not depend on the timing wakeup mechanism of the operating system. Therefore, the created timer can be used as a deterministic user-mode high-precision clock.
  • CreateSteadyTimer
    • The clock source cannot be configured. Only the system clock is supported.
    • Based on the hardware clock device provided by the system, the created timer directly uses the hardware timer and does not depend on the timing wakeup mechanism of the operating system. Therefore, the created timer can be used as a deterministic user-mode high-precision clock.