Skip to content

Commit e145b01

Browse files
committed
fix: reset times when jumps to past
1 parent c97630d commit e145b01

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

perception/multi_object_tracker/src/processor/input_manager.cpp

+30-4
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,18 @@ void InputStream::updateTimingStatus(const rclcpp::Time & now, const rclcpp::Tim
116116

117117
// Update time
118118
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+
}
121131

122132
// Update the initial count, count only first 32 messages
123133
if (initial_count_ < 32) {
@@ -314,11 +324,27 @@ bool InputManager::getObjects(const rclcpp::Time & now, ObjectsList & objects_li
314324
});
315325

316326
// Update the latest object time
317-
if (!objects_list.empty()) {
327+
bool is_any_object = !objects_list.empty();
328+
if (is_any_object) {
318329
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+
}
319345
}
320346

321-
return !objects_list.empty();
347+
return is_any_object;
322348
}
323349

324350
} // namespace multi_object_tracker

0 commit comments

Comments
 (0)