Skip to content

Commit 246cb4a

Browse files
committed
fix: callback object is fixed, tracker is working
Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp>
1 parent cf2874d commit 246cb4a

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

perception/multi_object_tracker/include/multi_object_tracker/processor/input_manager.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class InputStream
4545
std::string long_name_;
4646
std::string short_name_;
4747

48-
size_t que_size_{20};
48+
size_t que_size_{50};
4949
std::deque<autoware_auto_perception_msgs::msg::DetectedObjects> objects_que_;
5050

5151
bool is_time_initialized_{false};

perception/multi_object_tracker/src/multi_object_tracker_core.cpp

+6-26
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,15 @@ MultiObjectTracker::MultiObjectTracker(const rclcpp::NodeOptions & node_options)
102102

103103
// print input information
104104
for (size_t i = 0; i < input_topic_size_; i++) {
105-
RCLCPP_INFO(get_logger(), "Subscribing to %s %s %s", input_topic_names.at(i).c_str(), input_names_long.at(i).c_str(), input_names_short.at(i).c_str());
105+
RCLCPP_INFO(
106+
get_logger(), "Subscribing to %s %s %s", input_topic_names.at(i).c_str(),
107+
input_names_long.at(i).c_str(), input_names_short.at(i).c_str());
106108
}
107-
109+
110+
// Initialize input manager
108111
input_manager_ = std::make_unique<InputManager>(*this);
109112
input_manager_->init(input_topic_names, input_names_long, input_names_short);
110113

111-
// sub_objects_array_.resize(input_topic_size_);
112-
113-
// for (size_t i = 0; i < input_topic_size_; i++) {
114-
// RCLCPP_INFO(get_logger(), "Subscribing to %s", input_topic_names_.at(i).c_str());
115-
// std::function<void(const DetectedObjects::ConstSharedPtr msg)> func =
116-
// std::bind(&MultiObjectTracker::onData, this, std::placeholders::_1, i);
117-
// sub_objects_array_.at(i) =
118-
// create_subscription<DetectedObjects>(input_topic_names_.at(i), rclcpp::QoS{1}, func);
119-
// }
120-
121114
// Create tf timer
122115
auto cti = std::make_shared<tf2_ros::CreateTimerROS>(
123116
this->get_node_base_interface(), this->get_node_timers_interface());
@@ -232,27 +225,14 @@ void MultiObjectTracker::onTimer()
232225

233226
if (elapsed_time < maximum_publish_latency) return;
234227

235-
// // update trackers from accumulated input objects
236-
// if (objects_data_.empty()) return;
237-
238-
// // sort by time
239-
// sort(objects_data_.begin(), objects_data_.end(), [](const auto & a, const auto & b) {
240-
// return a.first.seconds() < b.first.seconds();
241-
// });
228+
// get objects from the input manager and run process
242229
std::vector<autoware_auto_perception_msgs::msg::DetectedObjects> objects_data;
243230
if (input_manager_->getObjects(current_time, objects_data)) {
244231
for (const auto & objects : objects_data) {
245232
runProcess(objects);
246233
}
247234
}
248235

249-
// // run onMeasurement for each queue
250-
// while (!objects_data_.empty()) {
251-
// const auto & pair = objects_data_.front();
252-
// runProcess(std::make_shared<DetectedObjects>(pair.second));
253-
// objects_data_.erase(objects_data_.begin());
254-
// }
255-
256236
// Publish
257237
checkAndPublish(current_time);
258238
}

perception/multi_object_tracker/src/processor/input_manager.cpp

+31-7
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ void InputStream::setObjects(
5454
objects_que_.pop_front();
5555
}
5656

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());
5958

6059
// Filter parameters
6160
constexpr double gain = 0.05;
@@ -88,18 +87,43 @@ void InputStream::getObjectsOlderThan(
8887
std::vector<autoware_auto_perception_msgs::msg::DetectedObjects> & objects)
8988
{
9089
objects.clear();
90+
91+
// remove objects older than the specified duration
92+
const rclcpp::Time old_limit = time - rclcpp::Duration::from_seconds(duration);
9193
for (const auto & object : objects_que_) {
92-
// Skip if the object is older than the specified duration
9394
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;
9799
}
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();
98106
// Add the object if the object is older than the specified time
99107
if (time_diff >= 0.0) {
100108
objects.push_back(object);
109+
// remove the object from the queue
110+
objects_que_.pop_front();
101111
}
102112
}
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);
103127
}
104128

105129
InputManager::InputManager(rclcpp::Node & node) : node_(node)
@@ -132,7 +156,7 @@ void InputManager::init(
132156
long_names.at(i).c_str(), input_topics.at(i).c_str());
133157
std::function<void(
134158
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);
136160
sub_objects_array_.at(i) =
137161
node_.create_subscription<autoware_auto_perception_msgs::msg::DetectedObjects>(
138162
input_topics.at(i), rclcpp::QoS{1}, func);

0 commit comments

Comments
 (0)