44 , expected_cycle_time_(1.0 / frequency)
45 , actual_cycle_time_(0.0)
48 Rate::Rate(
const Duration& d)
50 , expected_cycle_time_(d.sec, d.nsec)
51 , actual_cycle_time_(0.0)
56 Time expected_end = start_ + expected_cycle_time_;
58 Time actual_end = Time::now();
61 if (actual_end < start_)
63 expected_end = actual_end + expected_cycle_time_;
67 Duration sleep_time = expected_end - actual_end;
70 actual_cycle_time_ = actual_end - start_;
73 start_ = expected_end;
76 if(sleep_time <= Duration(0.0))
80 if (actual_end > expected_end + expected_cycle_time_)
88 return sleep_time.sleep();
96 Duration Rate::cycleTime()
const
98 return actual_cycle_time_;
101 WallRate::WallRate(
double frequency)
102 : start_(WallTime::now())
103 , expected_cycle_time_(1.0 / frequency)
104 , actual_cycle_time_(0.0)
108 : start_(WallTime::now())
109 , expected_cycle_time_(d.sec, d.nsec)
110 , actual_cycle_time_(0.0)
146 return sleep_time.
sleep();