@@ -175,10 +175,8 @@ int main(int argc, char** argv)
175
175
176
176
double expected_cycle_time = 1.0 / (static_cast <double >(g_hw_interface->getControlFrequency ()));
177
177
178
- ros::Duration min_period = ros::Duration (0 );
179
- ros::Duration max_period = ros::Duration (0 );
180
- ros::Duration period_totals = ros::Duration (0 );
181
-
178
+ msgStats period_stats;
179
+ reset_msg_stats (period_stats);
182
180
msgStats read_stats;
183
181
reset_msg_stats (read_stats);
184
182
msgStats cm_update_stats;
@@ -229,7 +227,9 @@ int main(int argc, char** argv)
229
227
// Get current time and elapsed time since last read
230
228
timestamp = ros::Time::now ();
231
229
stopwatch_now = std::chrono::steady_clock::now ();
232
- period.fromSec (std::chrono::duration_cast<std::chrono::duration<double >>(stopwatch_now - stopwatch_last).count ());
230
+ const std::chrono::duration<double > period_chrono = stopwatch_now - stopwatch_last;
231
+ update_msg_stats (period_chrono, period_stats);
232
+ period.fromSec (period_chrono.count ());
233
233
stopwatch_last = stopwatch_now;
234
234
235
235
const std::chrono::steady_clock::time_point cm_update_start = std::chrono::steady_clock::now ();
@@ -242,9 +242,6 @@ int main(int argc, char** argv)
242
242
const std::chrono::duration<double > write_elapsed = std::chrono::steady_clock::now () - write_start;
243
243
update_msg_stats (write_elapsed, write_stats);
244
244
245
- if (min_period.isZero () || period < min_period) min_period = period;
246
- if (max_period.isZero () || period > max_period) max_period = period;
247
- period_totals += period;
248
245
++debug_loops;
249
246
250
247
// Check if it's time to print
@@ -266,19 +263,8 @@ int main(int argc, char** argv)
266
263
num_loops.key = " Number of loops" ;
267
264
num_loops.value = std::to_string (debug_loops);
268
265
robot_status.values .push_back (num_loops);
269
- diagnostic_msgs::KeyValue min_period_kv;
270
- min_period_kv.key = " min loop period (s)" ;
271
- min_period_kv.value = std::to_string (min_period.toSec ());
272
- robot_status.values .push_back (min_period_kv);
273
- diagnostic_msgs::KeyValue max_period_kv;
274
- max_period_kv.key = " max loop period (s)" ;
275
- max_period_kv.value = std::to_string (max_period.toSec ());
276
- robot_status.values .push_back (max_period_kv);
277
- diagnostic_msgs::KeyValue avg_period_kv;
278
- avg_period_kv.key = " avg loop period (s)" ;
279
- avg_period_kv.value = std::to_string (period_totals.toSec () / debug_loops);
280
- robot_status.values .push_back (avg_period_kv);
281
266
267
+ push_msg_stats (robot_status, " period loop" , period_stats, debug_loops);
282
268
push_msg_stats (robot_status, " read" , read_stats, debug_loops);
283
269
push_msg_stats (robot_status, " cm_update" , cm_update_stats, debug_loops);
284
270
push_msg_stats (robot_status, " write" , write_stats, debug_loops);
@@ -293,9 +279,7 @@ int main(int argc, char** argv)
293
279
dia_array.status .push_back (robot_status);
294
280
diagnostic_pub.publish (dia_array);
295
281
296
- min_period = ros::Duration (0 );
297
- max_period = ros::Duration (0 );
298
- period_totals = ros::Duration (0 );
282
+ reset_msg_stats (period_stats);
299
283
reset_msg_stats (read_stats);
300
284
reset_msg_stats (cm_update_stats);
301
285
reset_msg_stats (write_stats);
0 commit comments