15 #ifndef RCLCPP__RATE_HPP_ 16 #define RCLCPP__RATE_HPP_ 36 virtual bool sleep() = 0;
38 virtual void reset() = 0;
45 template<
class Clock = std::chrono::high_resolution_clock>
56 : period_(period), last_interval_(Clock::now())
63 auto now = Clock::now();
65 auto next_interval = last_interval_ + period_;
67 if (now < last_interval_) {
69 next_interval = now + period_;
72 auto time_to_sleep = next_interval - now;
74 last_interval_ += period_;
80 if (now > next_interval + period_) {
81 last_interval_ = now + period_;
94 return Clock::is_steady;
100 last_interval_ = Clock::now();
122 #endif // RCLCPP__RATE_HPP_
virtual bool is_steady() const =0
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
Definition: allocator_common.hpp:24
T duration_cast(T... args)
std::chrono::nanoseconds period() const
Definition: rate.hpp:103
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
GenericRate(std::chrono::nanoseconds period)
Definition: rate.hpp:55
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...)
Definition: macros.hpp:51
bool sleep_for(const std::chrono::nanoseconds &nanoseconds)
Use the global condition variable to block for the specified amount of time.
virtual bool sleep()
Definition: rate.hpp:60
virtual bool is_steady() const
Definition: rate.hpp:92
virtual void reset()
Definition: rate.hpp:98