diff --git a/rclcpp/include/rclcpp/rate.hpp b/rclcpp/include/rclcpp/rate.hpp index a098a043b1..4715b9eba6 100644 --- a/rclcpp/include/rclcpp/rate.hpp +++ b/rclcpp/include/rclcpp/rate.hpp @@ -66,19 +66,19 @@ class GenericRate : public RateBase // Detect backwards time flow if (now < last_interval_) { // Best thing to do is to set the next_interval to now + period - next_interval = now + period_; + next_interval = now + std::chrono::duration_cast(period_); } // Calculate the time to sleep auto time_to_sleep = next_interval - now; // Update the interval - last_interval_ += period_; + last_interval_ += std::chrono::duration_cast(period_); // If the time_to_sleep is negative or zero, don't sleep if (time_to_sleep <= std::chrono::seconds(0)) { // If an entire cycle was missed then reset next interval. // This might happen if the loop took more than a cycle. // Or if time jumps forward. - if (now > next_interval + period_) { - last_interval_ = now + period_; + if (now > next_interval + std::chrono::duration_cast(period_)) { + last_interval_ = now + std::chrono::duration_cast(period_); } // Either way do not sleep and return false return false;