@@ -54,8 +54,7 @@ void InputStream::setObjects(
54
54
objects_que_.pop_front ();
55
55
}
56
56
57
- // RCLCPP_INFO(
58
- // node_.get_logger(), "InputStream::setObjects Que size: %zu", objects_que_.size());
57
+ RCLCPP_INFO (node_.get_logger (), " InputStream::setObjects Que size: %zu" , objects_que_.size ());
59
58
60
59
// Filter parameters
61
60
constexpr double gain = 0.05 ;
@@ -88,18 +87,43 @@ void InputStream::getObjectsOlderThan(
88
87
std::vector<autoware_auto_perception_msgs::msg::DetectedObjects> & objects)
89
88
{
90
89
objects.clear ();
90
+
91
+ // remove objects older than the specified duration
92
+ const rclcpp::Time old_limit = time - rclcpp::Duration::from_seconds (duration);
91
93
for (const auto & object : objects_que_) {
92
- // Skip if the object is older than the specified duration
93
94
const rclcpp::Time object_time = rclcpp::Time (object.header .stamp );
94
- const double time_diff = (object_time - time ).seconds ();
95
- if (time_diff > duration) {
96
- continue ;
95
+ if (object_time < old_limit) {
96
+ objects_que_.pop_front ();
97
+ } else {
98
+ break ;
97
99
}
100
+ }
101
+
102
+ for (const auto & object : objects_que_) {
103
+ // Skip if the object is older than the specified duration
104
+ const rclcpp::Time object_time = rclcpp::Time (object.header .stamp );
105
+ const double time_diff = (time - object_time).seconds ();
98
106
// Add the object if the object is older than the specified time
99
107
if (time_diff >= 0.0 ) {
100
108
objects.push_back (object);
109
+ // remove the object from the queue
110
+ objects_que_.pop_front ();
101
111
}
102
112
}
113
+ RCLCPP_INFO (
114
+ node_.get_logger (), " InputStream::getObjectsOlderThan %s gives %zu objects" , long_name_.c_str (),
115
+ objects.size ());
116
+
117
+ // // message to show the older limit, time, old objects in the queue, latest object in the queue
118
+ // if (objects_que_.empty()) {
119
+ // RCLCPP_INFO(
120
+ // node_.get_logger(), "InputStream::getObjectsOlderThan %s empty queue", long_name_.c_str());
121
+ // return;
122
+ // }
123
+ // RCLCPP_INFO(
124
+ // node_.get_logger(), "InputStream::getObjectsOlderThan %s older limit %f, time %f, %u, %u",
125
+ // long_name_.c_str(), old_limit.seconds(), time.seconds(),
126
+ // objects_que_.front().header.stamp.sec, objects_que_.back().header.stamp.sec);
103
127
}
104
128
105
129
InputManager::InputManager (rclcpp::Node & node) : node_(node)
@@ -132,7 +156,7 @@ void InputManager::init(
132
156
long_names.at (i).c_str (), input_topics.at (i).c_str ());
133
157
std::function<void (
134
158
const autoware_auto_perception_msgs::msg::DetectedObjects::ConstSharedPtr msg)>
135
- func = std::bind (&InputStream::setObjects, input_stream , std::placeholders::_1);
159
+ func = std::bind (&InputStream::setObjects, input_streams_. at (i) , std::placeholders::_1);
136
160
sub_objects_array_.at (i) =
137
161
node_.create_subscription <autoware_auto_perception_msgs::msg::DetectedObjects>(
138
162
input_topics.at (i), rclcpp::QoS{1 }, func);
0 commit comments