@@ -151,34 +151,31 @@ int main(int argc, char ** argv)
151
151
{
152
152
cm->get_clock ()->sleep_until (current_time + period);
153
153
}
154
- else
154
+ else if (enable_overrun)
155
155
{
156
156
next_iteration_time += period;
157
157
158
- if (enable_overrun)
158
+ const auto time_now = std::chrono::steady_clock::now ();
159
+ if (next_iteration_time < time_now)
159
160
{
160
- const auto time_now = std::chrono::steady_clock::now ();
161
- if (next_iteration_time < time_now)
162
- {
163
- const double time_diff =
164
- static_cast <double >(std::chrono::duration_cast<std::chrono::nanoseconds>(
165
- time_now - next_iteration_time)
166
- .count ()) /
167
- 1 .e6 ;
168
- const double cm_period = 1 .e3 / static_cast <double >(cm->get_update_rate ());
169
- const int overrun_count = static_cast <int >(std::ceil (time_diff / cm_period));
170
-
171
- RCLCPP_WARN_THROTTLE (
172
- cm->get_logger (), *cm->get_clock (), 1000 ,
173
- " Overrun detected! The controller manager missed its desired rate of %d Hz. The "
174
- " loop "
175
- " took %f ms (missed cycles : %d)." ,
176
- cm->get_update_rate (), time_diff + cm_period, overrun_count + 1 );
177
-
178
- next_iteration_time += (overrun_count * period);
179
- }
161
+ const double time_diff =
162
+ static_cast <double >(std::chrono::duration_cast<std::chrono::nanoseconds>(
163
+ time_now - next_iteration_time)
164
+ .count ()) /
165
+ 1 .e6 ;
166
+ const double cm_period = 1 .e3 / static_cast <double >(cm->get_update_rate ());
167
+ const int overrun_count = static_cast <int >(std::ceil (time_diff / cm_period));
168
+
169
+ RCLCPP_WARN_THROTTLE (
170
+ cm->get_logger (), *cm->get_clock (), 1000 ,
171
+ " Overrun detected! The controller manager missed its desired rate of %d Hz. The "
172
+ " loop "
173
+ " took %f ms (missed cycles : %d)." ,
174
+ cm->get_update_rate (), time_diff + cm_period, overrun_count + 1 );
175
+
176
+ next_iteration_time += (overrun_count * period);
180
177
}
181
-
178
+
182
179
std::this_thread::sleep_until (next_iteration_time);
183
180
}
184
181
}
0 commit comments