@@ -175,6 +175,31 @@ void ReactionAnalyzerNode::predictedObjectsOutputCallback(
175
175
mutex_.unlock ();
176
176
}
177
177
178
+ void ReactionAnalyzerNode::detectedObjectsOutputCallback (
179
+ const std::string & node_name, const DetectedObjects::ConstSharedPtr msg_ptr)
180
+ {
181
+ mutex_.lock ();
182
+ auto variant = message_buffers_[node_name];
183
+ // const auto is_spawned = spawn_cmd_time_;
184
+ mutex_.unlock ();
185
+
186
+ if (!std::holds_alternative<DetectedObjectsBuffer>(variant)) {
187
+ // If the variant doesn't hold a Trajectory message yet, initialize it
188
+ DetectedObjectsBuffer buffer (std::nullopt);
189
+ variant = buffer;
190
+ } else if (std::get<DetectedObjectsBuffer>(variant).has_value ()) {
191
+ // reacted
192
+ return ;
193
+ }
194
+ if (searchDetectedObjectsNearEntity (*msg_ptr)) {
195
+ std::get<DetectedObjectsBuffer>(variant) = *msg_ptr;
196
+ }
197
+ // if (!is_spawned) return;
198
+ mutex_.lock ();
199
+ message_buffers_[node_name] = variant;
200
+ mutex_.unlock ();
201
+ }
202
+
178
203
void ReactionAnalyzerNode::operationModeCallback (const OperationModeState::ConstSharedPtr msg_ptr)
179
204
{
180
205
std::lock_guard<std::mutex> lock (mutex_);
@@ -320,7 +345,6 @@ void ReactionAnalyzerNode::onTimer()
320
345
void ReactionAnalyzerNode::spawnObstacle (
321
346
const geometry_msgs::msg::Point & ego_pose, std::optional<rclcpp::Time> & spawn_cmd_time)
322
347
{
323
-
324
348
if (
325
349
tier4_autoware_utils::calcDistance3d (ego_pose, entity_pose_.position ) >=
326
350
node_params_.spawn_distance_threshold ) {
@@ -410,6 +434,13 @@ void ReactionAnalyzerNode::printResults(
410
434
} else {
411
435
all_reacted = false ;
412
436
}
437
+ } else if (auto * detected_objects_message = std::get_if<DetectedObjectsBuffer>(&variant)) {
438
+ if (detected_objects_message->has_value ()) {
439
+ reaction_times.emplace_back (
440
+ key, rclcpp::Time (detected_objects_message->value ().header .stamp ));
441
+ } else {
442
+ all_reacted = false ;
443
+ }
413
444
}
414
445
}
415
446
@@ -460,6 +491,8 @@ bool ReactionAnalyzerNode::loadChainModules()
460
491
return MessageType::PointCloud2;
461
492
} else if (input == " autoware_auto_perception_msgs::msg::PredictedObjects" ) {
462
493
return MessageType::PredictedObjects;
494
+ } else if (input == " autoware_auto_perception_msgs::msg::DetectedObjects" ) {
495
+ return MessageType::DetectedObjects;
463
496
} else {
464
497
return MessageType::Unknown;
465
498
}
@@ -625,6 +658,15 @@ bool ReactionAnalyzerNode::initObservers(const reaction_analyzer::ChainModules &
625
658
subscribers_.push_back (subscriber);
626
659
break ;
627
660
}
661
+ case MessageType::DetectedObjects: {
662
+ auto callback = [this , module](const DetectedObjects::ConstSharedPtr msg) {
663
+ this ->detectedObjectsOutputCallback (module.node_name , msg);
664
+ };
665
+ auto subscriber = this ->create_subscription <DetectedObjects>(
666
+ module.topic_address , rclcpp::SensorDataQoS (), callback, createSubscriptionOptions ());
667
+ subscribers_.push_back (subscriber);
668
+ break ;
669
+ }
628
670
case MessageType::Unknown:
629
671
RCLCPP_WARN (
630
672
this ->get_logger (), " Unknown message type for module name: %s, skipping.." ,
@@ -849,6 +891,22 @@ bool ReactionAnalyzerNode::searchPredictedObjectsNearEntity(
849
891
return false ;
850
892
}
851
893
894
+ bool ReactionAnalyzerNode::searchDetectedObjectsNearEntity (const DetectedObjects & detected_objects)
895
+ {
896
+ bool isAnyObjectWithinRadius = std::any_of (
897
+ detected_objects.objects .begin (), detected_objects.objects .end (),
898
+ [this ](const DetectedObject & object) {
899
+ return tier4_autoware_utils::calcDistance3d (
900
+ entity_pose_.position , object.kinematics .pose_with_covariance .pose .position ) <=
901
+ entity_search_radius_;
902
+ });
903
+
904
+ if (isAnyObjectWithinRadius) {
905
+ return true ;
906
+ }
907
+ return false ;
908
+ }
909
+
852
910
} // namespace reaction_analyzer
853
911
854
912
#include < rclcpp_components/register_node_macro.hpp>
0 commit comments