@@ -116,8 +116,18 @@ void InputStream::updateTimingStatus(const rclcpp::Time & now, const rclcpp::Tim
116
116
117
117
// Update time
118
118
latest_message_time_ = now;
119
- latest_measurement_time_ =
120
- latest_measurement_time_ < objects_time ? objects_time : latest_measurement_time_;
119
+ if (std::abs ((latest_measurement_time_ - objects_time).seconds ()) > 3.0 ) {
120
+ // Reset the latest measurement time if the time difference is too large
121
+ latest_measurement_time_ = objects_time;
122
+ RCLCPP_WARN (
123
+ node_.get_logger (),
124
+ " InputManager::updateTimingStatus %s: Resetting the latest measurement time to %f" ,
125
+ long_name_.c_str (), objects_time.seconds ());
126
+ } else {
127
+ // Aware reversed message arrival
128
+ latest_measurement_time_ =
129
+ latest_measurement_time_ < objects_time ? objects_time : latest_measurement_time_;
130
+ }
121
131
122
132
// Update the initial count, count only first 32 messages
123
133
if (initial_count_ < 32 ) {
@@ -314,11 +324,27 @@ bool InputManager::getObjects(const rclcpp::Time & now, ObjectsList & objects_li
314
324
});
315
325
316
326
// Update the latest object time
317
- if (!objects_list.empty ()) {
327
+ bool is_any_object = !objects_list.empty ();
328
+ if (is_any_object) {
318
329
latest_object_time_ = rclcpp::Time (objects_list.back ().second .header .stamp );
330
+ } else {
331
+ // check time jump
332
+ if ((now - latest_object_time_).seconds () < 0.0 ) {
333
+ RCLCPP_WARN (
334
+ node_.get_logger (),
335
+ " InputManager::getObjects Time jump detected, now: %f, latest_object_time_: %f" ,
336
+ now.seconds (), latest_object_time_.seconds ());
337
+ latest_object_time_ =
338
+ now - rclcpp::Duration::from_seconds (3.0 ); // reset the latest object time to 3 seconds ago
339
+ } else {
340
+ RCLCPP_WARN (
341
+ node_.get_logger (),
342
+ " InputManager::getObjects No objects in the object list, object time band from %f to %f" ,
343
+ (now - object_oldest_time).seconds (), (now - object_latest_time).seconds ());
344
+ }
319
345
}
320
346
321
- return !objects_list. empty () ;
347
+ return is_any_object ;
322
348
}
323
349
324
350
} // namespace multi_object_tracker
0 commit comments