@@ -35,7 +35,7 @@ void ReactionAnalyzerNode::routeStateCallback(RouteState::ConstSharedPtr msg_ptr
35
35
void ReactionAnalyzerNode::vehiclePoseCallback (Odometry::ConstSharedPtr msg_ptr)
36
36
{
37
37
std::lock_guard<std::mutex> lock (mutex_);
38
- odometry_ = msg_ptr;
38
+ odometry_ptr_ = msg_ptr;
39
39
}
40
40
41
41
void ReactionAnalyzerNode::initializationStateCallback (
@@ -45,6 +45,12 @@ void ReactionAnalyzerNode::initializationStateCallback(
45
45
initialization_state_ptr_ = std::move (msg_ptr);
46
46
}
47
47
48
+ void ReactionAnalyzerNode::groundTruthPoseCallback (PoseStamped::ConstSharedPtr msg_ptr)
49
+ {
50
+ std::lock_guard<std::mutex> lock (mutex_);
51
+ ground_truth_pose_ptr_ = std::move (msg_ptr);
52
+ }
53
+
48
54
ReactionAnalyzerNode::ReactionAnalyzerNode (rclcpp::NodeOptions options)
49
55
: Node(" reaction_analyzer_node" , options.automatically_declare_parameters_from_overrides(true ))
50
56
{
@@ -130,6 +136,7 @@ ReactionAnalyzerNode::ReactionAnalyzerNode(rclcpp::NodeOptions options)
130
136
// init dummy perception publisher
131
137
const auto period_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
132
138
std::chrono::duration<double >(node_params_.dummy_perception_publisher_period ));
139
+
133
140
dummy_perception_timer_ = rclcpp::create_timer (
134
141
this , get_clock (), period_ns,
135
142
std::bind (&ReactionAnalyzerNode::dummyPerceptionPublisher, this ));
@@ -138,12 +145,19 @@ ReactionAnalyzerNode::ReactionAnalyzerNode(rclcpp::NodeOptions options)
138
145
// Create topic publishers
139
146
topic_publisher_ptr_ =
140
147
std::make_shared<topic_publisher::TopicPublisher>(this , spawn_object_cmd_, spawn_cmd_time_);
148
+
149
+ // Subscribe to the ground truth position
150
+ sub_ground_truth_pose_ = create_subscription<PoseStamped>(
151
+ " input/ground_truth_pose" , rclcpp::QoS{1 },
152
+ std::bind (&ReactionAnalyzerNode::groundTruthPoseCallback, this , _1),
153
+ createSubscriptionOptions (this ));
141
154
}
142
155
143
156
// Load the subscriber to listen the topics for reactions
144
- odometry_ = std::make_shared<Odometry>(); // initialize the odometry before init the subscriber
145
- subscriber_ptr_ =
146
- std::make_unique<subscriber::SubscriberBase>(this , odometry_, entity_pose_, spawn_object_cmd_);
157
+ odometry_ptr_ =
158
+ std::make_shared<Odometry>(); // initialize the odometry before init the subscriber
159
+ subscriber_ptr_ = std::make_unique<subscriber::SubscriberBase>(
160
+ this , odometry_ptr_, entity_pose_, spawn_object_cmd_);
147
161
148
162
const auto period_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
149
163
std::chrono::duration<double >(node_params_.timer_period ));
@@ -154,16 +168,19 @@ ReactionAnalyzerNode::ReactionAnalyzerNode(rclcpp::NodeOptions options)
154
168
void ReactionAnalyzerNode::onTimer ()
155
169
{
156
170
mutex_.lock ();
157
- const auto current_odometry_ptr = odometry_ ;
171
+ const auto current_odometry_ptr = odometry_ptr_ ;
158
172
const auto initialization_state_ptr = initialization_state_ptr_;
159
173
const auto route_state_ptr = current_route_state_ptr_;
160
174
const auto operation_mode_ptr = operation_mode_ptr_;
175
+ const auto ground_truth_pose_ptr = ground_truth_pose_ptr_;
161
176
const auto spawn_cmd_time = spawn_cmd_time_;
162
177
mutex_.unlock ();
163
178
164
179
// Init the test environment
165
180
if (!test_environment_init_time_) {
166
- initEgoForTest (initialization_state_ptr, route_state_ptr, operation_mode_ptr);
181
+ initEgoForTest (
182
+ initialization_state_ptr, route_state_ptr, operation_mode_ptr, ground_truth_pose_ptr,
183
+ current_odometry_ptr);
167
184
return ;
168
185
}
169
186
@@ -437,11 +454,13 @@ void ReactionAnalyzerNode::initPredictedObjects()
437
454
void ReactionAnalyzerNode::initEgoForTest (
438
455
const LocalizationInitializationState::ConstSharedPtr & initialization_state_ptr,
439
456
const RouteState::ConstSharedPtr & route_state_ptr,
440
- const OperationModeState::ConstSharedPtr & operation_mode_ptr)
457
+ const OperationModeState::ConstSharedPtr & operation_mode_ptr,
458
+ const PoseStamped::ConstSharedPtr & ground_truth_pose_ptr,
459
+ const Odometry::ConstSharedPtr & odometry_ptr)
441
460
{
442
461
const auto current_time = this ->now ();
443
462
444
- // Initialize the vehicle
463
+ // Initialize the test environment
445
464
constexpr double initialize_call_period = 1.0 ; // sec
446
465
447
466
if (
@@ -450,6 +469,7 @@ void ReactionAnalyzerNode::initEgoForTest(
450
469
initialize_call_period) {
451
470
last_test_environment_init_request_time_ = current_time;
452
471
472
+ // Pose initialization of the ego
453
473
if (
454
474
initialization_state_ptr &&
455
475
(initialization_state_ptr->state != LocalizationInitializationState::INITIALIZED ||
@@ -466,6 +486,35 @@ void ReactionAnalyzerNode::initEgoForTest(
466
486
return ;
467
487
}
468
488
489
+ // Wait until odometry_ptr is initialized
490
+ if (!odometry_ptr) {
491
+ RCLCPP_WARN_ONCE (get_logger (), " Odometry is not received. Waiting for odometry..." );
492
+ return ;
493
+ }
494
+
495
+ // Check is position initialized accurately, if node is running PerceptionPlanning mode
496
+ if (node_running_mode_ == RunningMode::PerceptionPlanning) {
497
+ if (!ground_truth_pose_ptr) {
498
+ RCLCPP_WARN (
499
+ get_logger (), " Ground truth pose is not received. Waiting for Ground truth pose..." );
500
+ return ;
501
+ } else {
502
+ constexpr double deviation_threshold = 0.1 ;
503
+ const auto deviation = tier4_autoware_utils::calcPoseDeviation (
504
+ ground_truth_pose_ptr->pose , odometry_ptr->pose .pose );
505
+ if (
506
+ deviation.longitudinal > deviation_threshold || deviation.lateral > deviation_threshold ||
507
+ deviation.yaw > deviation_threshold) {
508
+ RCLCPP_ERROR (
509
+ get_logger (),
510
+ " Deviation between ground truth position and ego position is high. Node is shutting "
511
+ " down. Longitudinal deviation: %f, Lateral deviation: %f, Yaw deviation: %f" ,
512
+ deviation.longitudinal , deviation.lateral , deviation.yaw );
513
+ rclcpp::shutdown ();
514
+ }
515
+ }
516
+ }
517
+
469
518
if (route_state_ptr && (route_state_ptr->state != RouteState::SET || !is_route_set_)) {
470
519
if (route_state_ptr->state == RouteState::SET) {
471
520
is_route_set_ = true ;
@@ -477,6 +526,7 @@ void ReactionAnalyzerNode::initEgoForTest(
477
526
return ;
478
527
}
479
528
529
+ // if node is running PlanningControl mode, change ego to Autonomous mode.
480
530
if (node_running_mode_ == RunningMode::PlanningControl) {
481
531
// change to autonomous
482
532
if (operation_mode_ptr && operation_mode_ptr->mode != OperationModeState::AUTONOMOUS) {
0 commit comments