23
23
24
24
#include < algorithm>
25
25
#include < cmath>
26
- #include < utility>
27
26
28
27
namespace trt_mtr
29
28
{
@@ -182,7 +181,7 @@ MTRNode::MTRNode(const rclcpp::NodeOptions & node_options)
182
181
declare_parameter<std::string>(" intention_point_filepath" );
183
182
const auto num_intention_point_cluster =
184
183
static_cast <size_t >(declare_parameter<int >(" num_intention_point_cluster" ));
185
- config_ptr_ = std::make_unique<MtrConfig >(
184
+ config_ptr_ = std::make_unique<MTRConfig >(
186
185
target_labels, num_past, num_mode, num_future, max_num_polyline, max_num_point,
187
186
point_break_distance, offset_xy, intention_point_filepath, num_intention_point_cluster);
188
187
model_ptr_ = std::make_unique<TrtMTR>(model_path, precision, *config_ptr_.get ());
@@ -210,7 +209,7 @@ void MTRNode::callback(const TrackedObjects::ConstSharedPtr object_msg)
210
209
return ; // No polyline
211
210
}
212
211
213
- const auto current_time = rclcpp::Time (object_msg->header .stamp ).seconds ();
212
+ const auto current_time = static_cast < float >( rclcpp::Time (object_msg->header .stamp ).seconds () );
214
213
215
214
timestamps_.emplace_back (current_time);
216
215
// TODO(ktro2828): update timestamps
@@ -289,7 +288,30 @@ void MTRNode::onMap(const HADMapBin::ConstSharedPtr map_msg)
289
288
290
289
void MTRNode::onEgo (const Odometry::ConstSharedPtr ego_msg)
291
290
{
292
- RCLCPP_INFO_STREAM (get_logger (), " Ego msg is received: " << ego_msg->header .frame_id );
291
+ const auto current_time = static_cast <float >(rclcpp::Time (ego_msg->header .stamp ).seconds ());
292
+ const auto & position = ego_msg->pose .pose .position ;
293
+ const auto & twist = ego_msg->twist .twist ;
294
+ const auto yaw = static_cast <float >(tf2::getYaw (ego_msg->pose .pose .orientation ));
295
+ float ax = 0 .0f , ay = 0 .0f ;
296
+ if (!ego_states_.empty ()) {
297
+ const auto & latest_state = ego_states_.back ();
298
+ const auto time_diff = current_time - latest_state.first ;
299
+ ax = (static_cast <float >(twist.linear .x ) - latest_state.second .vx ()) / (time_diff + 1e-10f );
300
+ ay = static_cast <float >(twist.linear .y ) - latest_state.second .vy () / (time_diff + 1e-10f );
301
+ }
302
+
303
+ // TODO(ktro2828): use received ego size topic
304
+ ego_states_.emplace_back (std::make_pair (
305
+ current_time,
306
+ AgentState (
307
+ static_cast <float >(position.x ), static_cast <float >(position.y ),
308
+ static_cast <float >(position.z ), EGO_LENGTH, EGO_WIDTH, EGO_HEIGHT, yaw,
309
+ static_cast <float >(twist.linear .x ), static_cast <float >(twist.linear .y ), ax, ay, true )));
310
+
311
+ constexpr size_t max_buffer_size = 100 ;
312
+ if (max_buffer_size < ego_states_.size ()) {
313
+ ego_states_.erase (ego_states_.begin (), ego_states_.begin ());
314
+ }
293
315
}
294
316
295
317
bool MTRNode::convertLaneletToPolyline ()
@@ -362,19 +384,24 @@ bool MTRNode::convertLaneletToPolyline()
362
384
void MTRNode::removeAncientAgentHistory (
363
385
const float current_time, const TrackedObjects::ConstSharedPtr objects_msg)
364
386
{
365
- // TODO(ktro2828): use ego info
387
+ constexpr float time_threshold = 1 . 0f ; // TODO(ktro2828): use parameter
366
388
for (const auto & object : objects_msg->objects ) {
367
389
const auto & object_id = tier4_autoware_utils::toHexString (object.object_id );
368
390
if (agent_history_map_.count (object_id) == 0 ) {
369
391
continue ;
370
392
}
371
393
372
- constexpr float time_threshold = 1 .0f ; // TODO(ktro2828): use parameter
373
394
const auto & history = agent_history_map_.at (object_id);
374
395
if (history.is_ancient (current_time, time_threshold)) {
375
396
agent_history_map_.erase (object_id);
376
397
}
377
398
}
399
+
400
+ if (
401
+ agent_history_map_.count (EGO_ID) != 0 &&
402
+ agent_history_map_.at (EGO_ID).is_ancient (current_time, time_threshold)) {
403
+ agent_history_map_.erase (EGO_ID);
404
+ }
378
405
}
379
406
380
407
void MTRNode::updateAgentHistory (
@@ -402,6 +429,15 @@ void MTRNode::updateAgentHistory(
402
429
}
403
430
}
404
431
432
+ auto ego_state = extractNearestEgo (current_time);
433
+ if (agent_history_map_.count (EGO_ID) == 0 ) {
434
+ AgentHistory history (EGO_ID, AgentLabel::VEHICLE, config_ptr_->num_past );
435
+ history.update (current_time, ego_state);
436
+ } else {
437
+ agent_history_map_.at (EGO_ID).update (current_time, ego_state);
438
+ }
439
+ observed_ids.emplace_back (EGO_ID);
440
+
405
441
// update unobserved histories with empty
406
442
for (auto & [object_id, history] : agent_history_map_) {
407
443
if (std::find (observed_ids.cbegin (), observed_ids.cend (), object_id) != observed_ids.cend ()) {
@@ -411,6 +447,15 @@ void MTRNode::updateAgentHistory(
411
447
}
412
448
}
413
449
450
+ AgentState MTRNode::extractNearestEgo (const float current_time) const
451
+ {
452
+ auto state = std::min_element (
453
+ ego_states_.cbegin (), ego_states_.cend (), [&](const auto & s1, const auto & s2) {
454
+ return std::abs (s1.first - current_time) < std::abs (s2.first - current_time);
455
+ });
456
+ return state->second ;
457
+ }
458
+
414
459
std::vector<size_t > MTRNode::extractTargetAgent (const std::vector<AgentHistory> & histories)
415
460
{
416
461
std::vector<std::pair<size_t , float >> distances;
0 commit comments