Skip to content

Commit

Permalink
Explicitly casting the duration to fix compile on osx.
Browse files Browse the repository at this point in the history
Fixes #181
  • Loading branch information
tfoote committed Dec 16, 2015
1 parent d622956 commit ca229a1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rclcpp/include/rclcpp/rate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::chrono::microseconds>(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<std::chrono::microseconds>(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<std::chrono::microseconds>(period_)) {
last_interval_ = now + std::chrono::duration_cast<std::chrono::microseconds>(period_);
}
// Either way do not sleep and return false
return false;
Expand Down

0 comments on commit ca229a1

Please sign in to comment.