@@ -82,6 +82,8 @@ MessageType stringToMessageType(const std::string & input)
82
82
{
83
83
if (input == " autoware_auto_control_msgs::msg::AckermannControlCommand" ) {
84
84
return MessageType::AckermannControlCommand;
85
+ } else if (input == " autoware_auto_planning_msgs::msg::Trajectory" ) {
86
+ return MessageType::Trajectory;
85
87
} else {
86
88
return MessageType::Unknown;
87
89
}
@@ -305,6 +307,28 @@ void ReactionAnalyzerNode::onTimer()
305
307
mutex_.unlock ();
306
308
}
307
309
}
310
+ } else if (auto * message = std::get_if<PlanningBuffer>(&variant)) {
311
+ if (!message->second ) {
312
+ all_topics_reacted_ = false ;
313
+ const auto nearest_idx = motion_utils::findNearestIndex (
314
+ message->first .points , current_odometry_ptr->pose .pose .position );
315
+ //
316
+ // constexpr double lookahead_distance = 15.0;
317
+ // const auto destination_idx = motion_utils::calcLongitudinalOffsetPoint(
318
+ // message->first.points, nearest_idx, lookahead_distance);
319
+ const auto zero_vel_idx = motion_utils::searchZeroVelocityIndex (
320
+ message->first .points , nearest_idx, message->first .points .size () - 1 );
321
+
322
+ if (zero_vel_idx) {
323
+ std::cout << key << " found: nearest_idx: " << nearest_idx
324
+ << " zero_vel_idx: " << zero_vel_idx.value ()
325
+ << " size: " << message->first .points .size () << " stamp: " << message->first .header .stamp .nanosec << std::endl;
326
+ mutex_.lock ();
327
+ auto * tmp = std::get_if<PlanningBuffer>(&messageBuffers_[key]);
328
+ if (tmp) tmp->second = message->first ;
329
+ mutex_.unlock ();
330
+ }
331
+ }
308
332
}
309
333
// Add similar blocks for other types
310
334
}
@@ -317,6 +341,10 @@ void ReactionAnalyzerNode::onTimer()
317
341
if (message->second ) {
318
342
reaction_times.emplace_back (key, rclcpp::Time (message->second ->stamp ));
319
343
}
344
+ } else if (auto * message = std::get_if<PlanningBuffer>(&variant)) {
345
+ if (message->second ) {
346
+ reaction_times.emplace_back (key, rclcpp::Time (message->second ->header .stamp ));
347
+ }
320
348
}
321
349
}
322
350
@@ -450,6 +478,20 @@ void ReactionAnalyzerNode::controlCommandOutputCallback(
450
478
setControlCommandToBuffer (std::get<ControlBuffer>(variant).first , *msg_ptr);
451
479
}
452
480
481
+ void ReactionAnalyzerNode::planningOutputCallback (
482
+ const std::string & node_name, const Trajectory::ConstSharedPtr msg_ptr)
483
+ {
484
+ std::lock_guard<std::mutex> lock (mutex_);
485
+ auto & variant = messageBuffers_[node_name];
486
+ if (!std::holds_alternative<PlanningBuffer>(variant)) {
487
+ // If the variant doesn't hold a vector of AckermannControlCommand yet, initialize it
488
+ PlanningBuffer buffer (*msg_ptr, std::nullopt);
489
+ variant = buffer;
490
+ } else {
491
+ std::get<PlanningBuffer>(variant).first = *msg_ptr;
492
+ }
493
+ }
494
+
453
495
void ReactionAnalyzerNode::initObservers (const reaction_analyzer::ChainModules & modules)
454
496
{
455
497
for (const auto & module : modules) {
@@ -463,6 +505,15 @@ void ReactionAnalyzerNode::initObservers(const reaction_analyzer::ChainModules &
463
505
subscribers_.push_back (subscriber);
464
506
break ;
465
507
}
508
+ case MessageType::Trajectory: {
509
+ auto callback = [this , module](const Trajectory::ConstSharedPtr msg) {
510
+ this ->planningOutputCallback (module.node_name , msg);
511
+ };
512
+ auto subscriber = this ->create_subscription <Trajectory>(
513
+ module.topic_address , 1 , callback, createSubscriptionOptions (this ));
514
+ subscribers_.push_back (subscriber);
515
+ break ;
516
+ }
466
517
case MessageType::Unknown:
467
518
RCLCPP_WARN (
468
519
this ->get_logger (), " Unknown message type for topic: %s" , module.topic_address .c_str ());
0 commit comments