15 #include "rclcpp/rate.hpp"
24 const double rate, Clock::SharedPtr clock)
25 : clock_(clock), period_(0, 0), last_interval_(clock_->now())
28 throw std::invalid_argument{
"rate must be greater than 0"};
30 period_ = Duration::from_seconds(1.0 / rate);
34 const Duration & period, Clock::SharedPtr clock)
35 : clock_(clock), period_(period), last_interval_(clock_->now())
37 if (period <= Duration(0, 0)) {
38 throw std::invalid_argument{
"period must be greater than 0"};
46 auto now = clock_->now();
48 auto next_interval = last_interval_ + period_;
50 if (now < last_interval_) {
52 next_interval = now + period_;
55 last_interval_ += period_;
57 if (next_interval <= now) {
61 if (now > next_interval + period_) {
62 last_interval_ = now + period_;
68 auto time_to_sleep = next_interval - now;
70 clock_->sleep_for(time_to_sleep);
75 Rate::get_type()
const
77 return clock_->get_clock_type();
83 last_interval_ = clock_->now();
86 std::chrono::nanoseconds
89 return std::chrono::nanoseconds(period_.nanoseconds());
92 WallRate::WallRate(
const double rate)
96 WallRate::WallRate(
const Duration & period)
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
enum rcl_clock_type_e rcl_clock_type_t
Time source type, used to indicate the source of a time measurement.
@ RCL_STEADY_TIME
Use a steady clock time.