@@ -110,16 +110,19 @@ void ReactionAnalyzerNode::pointcloud2OutputCallback(
110
110
const auto current_odometry_ptr = odometry_;
111
111
// const auto is_spawned = spawn_cmd_time_;
112
112
mutex_.unlock ();
113
- if (!current_odometry_ptr) return ;
114
113
115
114
if (!std::holds_alternative<PointCloud2Buffer>(variant)) {
116
115
// If the variant doesn't hold a Trajectory message yet, initialize it
117
116
PointCloud2Buffer buffer (std::nullopt);
118
117
variant = buffer;
118
+ mutex_.lock ();
119
+ message_buffers_[node_name] = variant;
120
+ mutex_.unlock ();
119
121
} else if (std::get<PointCloud2Buffer>(variant).has_value ()) {
120
122
// reacted
121
123
return ;
122
124
}
125
+ if (!current_odometry_ptr) return ;
123
126
124
127
// transform pointcloud
125
128
geometry_msgs::msg::TransformStamped transform_stamped{};
@@ -156,17 +159,23 @@ void ReactionAnalyzerNode::predictedObjectsOutputCallback(
156
159
{
157
160
mutex_.lock ();
158
161
auto variant = message_buffers_[node_name];
162
+ const auto current_odometry_ptr = odometry_;
159
163
// const auto is_spawned = spawn_cmd_time_;
160
164
mutex_.unlock ();
161
165
162
166
if (!std::holds_alternative<PredictedObjectsBuffer>(variant)) {
163
167
// If the variant doesn't hold a Trajectory message yet, initialize it
164
168
PredictedObjectsBuffer buffer (std::nullopt);
165
169
variant = buffer;
170
+ mutex_.lock ();
171
+ message_buffers_[node_name] = variant;
172
+ mutex_.unlock ();
166
173
} else if (std::get<PredictedObjectsBuffer>(variant).has_value ()) {
167
174
// reacted
168
175
return ;
169
176
}
177
+ if (!current_odometry_ptr || msg_ptr->objects .empty ()) return ;
178
+
170
179
if (searchPredictedObjectsNearEntity (*msg_ptr)) {
171
180
std::get<PredictedObjectsBuffer>(variant) = *msg_ptr;
172
181
std::cout << " Reacted " << node_name << std::endl;
@@ -182,19 +191,45 @@ void ReactionAnalyzerNode::detectedObjectsOutputCallback(
182
191
{
183
192
mutex_.lock ();
184
193
auto variant = message_buffers_[node_name];
194
+ const auto current_odometry_ptr = odometry_;
185
195
// const auto is_spawned = spawn_cmd_time_;
186
196
mutex_.unlock ();
187
197
188
198
if (!std::holds_alternative<DetectedObjectsBuffer>(variant)) {
189
199
// If the variant doesn't hold a Trajectory message yet, initialize it
190
200
DetectedObjectsBuffer buffer (std::nullopt);
191
201
variant = buffer;
202
+ mutex_.lock ();
203
+ message_buffers_[node_name] = variant;
204
+ mutex_.unlock ();
192
205
} else if (std::get<DetectedObjectsBuffer>(variant).has_value ()) {
193
206
// reacted
194
207
return ;
195
208
}
196
- if (searchDetectedObjectsNearEntity (*msg_ptr)) {
209
+
210
+ if (!current_odometry_ptr || msg_ptr->objects .empty ()) return ;
211
+
212
+ // transform pointcloud
213
+ geometry_msgs::msg::TransformStamped transform_stamped{};
214
+ try {
215
+ transform_stamped = tf_buffer_.lookupTransform (
216
+ " map" , msg_ptr->header .frame_id , this ->now (), rclcpp::Duration::from_seconds (0.5 ));
217
+ } catch (tf2::TransformException & ex) {
218
+ RCLCPP_ERROR_STREAM (
219
+ get_logger (), " Failed to look up transform from " << msg_ptr->header .frame_id << " to map" );
220
+ return ;
221
+ }
222
+ DetectedObjects output_objs;
223
+ output_objs = *msg_ptr;
224
+ for (auto & obj : output_objs.objects ) {
225
+ geometry_msgs::msg::PoseStamped output_stamped, input_stamped;
226
+ input_stamped.pose = obj.kinematics .pose_with_covariance .pose ;
227
+ tf2::doTransform (input_stamped, output_stamped, transform_stamped);
228
+ obj.kinematics .pose_with_covariance .pose = output_stamped.pose ;
229
+ }
230
+ if (searchDetectedObjectsNearEntity (output_objs)) {
197
231
std::get<DetectedObjectsBuffer>(variant) = *msg_ptr;
232
+ std::cout << " Reacted " << node_name << std::endl;
198
233
}
199
234
// if (!is_spawned) return;
200
235
mutex_.lock ();
@@ -241,6 +276,9 @@ ReactionAnalyzerNode::ReactionAnalyzerNode(rclcpp::NodeOptions options)
241
276
get_parameter (" observer.min_jerk_for_brake_cmd" ).as_double ();
242
277
node_params_.min_number_descending_order_control_cmd =
243
278
get_parameter (" observer.min_number_descending_order_control_cmd" ).as_int ();
279
+ node_params_.run_from_bag =
280
+ get_parameter (" run_from_bag" ).as_bool ();
281
+
244
282
245
283
// prepare the object which will be spawned
246
284
entity_params_.x = get_parameter (" test_manager.entity.x" ).as_double ();
@@ -295,15 +333,15 @@ ReactionAnalyzerNode::ReactionAnalyzerNode(rclcpp::NodeOptions options)
295
333
pub_initial_pose_ = create_publisher<geometry_msgs::msg::PoseWithCovarianceStamped>(
296
334
" output/initialpose" , rclcpp::QoS (1 ));
297
335
pub_goal_pose_ = create_publisher<geometry_msgs::msg::PoseStamped>(" output/goal" , rclcpp::QoS (1 ));
298
- if (!run_from_bag_ ) {
336
+ if (!node_params_. run_from_bag ) {
299
337
pub_pointcloud_ = create_publisher<PointCloud2>(
300
338
" /perception/obstacle_segmentation/pointcloud" , rclcpp::SensorDataQoS ());
301
339
}
302
340
303
341
pub_predicted_objects_ = create_publisher<PredictedObjects>(" output/objects" , rclcpp::QoS (1 ));
304
342
305
343
client_change_to_autonomous_ = create_client<ChangeOperationMode>(" service/change_to_autonomous" );
306
- if (run_from_bag_ ) {
344
+ if (node_params_. run_from_bag ) {
307
345
// init pointcloud in bags
308
346
const std::string path_bag_without_object =
309
347
get_parameter (" path_bag_without_object" ).as_string ();
@@ -408,7 +446,7 @@ void ReactionAnalyzerNode::onTimer()
408
446
const auto message_buffers = message_buffers_;
409
447
auto spawn_cmd_time = spawn_cmd_time_;
410
448
mutex_.unlock ();
411
- if (!run_from_bag_ ) {
449
+ if (!node_params_. run_from_bag ) {
412
450
if (!is_test_environment_created_) {
413
451
initEgoForTest (initialization_state_ptr, route_state_ptr);
414
452
return ;
@@ -451,7 +489,7 @@ void ReactionAnalyzerNode::onTimer()
451
489
return ;
452
490
} else {
453
491
rclcpp::Duration time_diff = this ->now () - last_test_environment_init_time_.value ();
454
- if (time_diff > rclcpp::Duration::from_seconds (10 .0 )) {
492
+ if (time_diff > rclcpp::Duration::from_seconds (50 .0 )) {
455
493
if (!spawn_cmd_time) {
456
494
spawn_cmd_time = this ->now ();
457
495
mutex_.lock ();
@@ -591,18 +629,18 @@ void ReactionAnalyzerNode::printResults(
591
629
const std::pair<std::string, rclcpp::Time> & b) { return a.second < b.second ; });
592
630
593
631
// first print spawn_cmd_time to first reaction
594
- std::cout << " spawn_cmd_time to " << reaction_times.begin ()->first << " : "
595
- << createDurationMs (spawn_cmd_time_.value (), reaction_times.begin ()->second )
596
- << std::endl;
632
+ // std::cout << "spawn_cmd_time to " << reaction_times.begin()->first << ": "
633
+ // << createDurationMs(spawn_cmd_time_.value(), reaction_times.begin()->second)
634
+ // << std::endl;
597
635
598
- if (reaction_times.size () < 2 ) return ;
636
+ // if (reaction_times.size() < 2) return;
599
637
600
- for (size_t i = 0 ; i < reaction_times.size () - 1 ; i++) {
638
+ for (size_t i = 0 ; i < reaction_times.size (); i++) {
601
639
const auto & first_reaction = reaction_times.at (i);
602
- const auto & second_reaction = reaction_times.at (i + 1 );
640
+ // const auto & second_reaction = reaction_times.at(i + 1);
603
641
604
- std::cout << first_reaction. first << " to " << second_reaction .first << " : "
605
- << createDurationMs (first_reaction. second , second_reaction .second ) << std::endl;
642
+ std::cout << " spawn_cmd_time to " << first_reaction .first << " : "
643
+ << createDurationMs (spawn_cmd_time_. value (), first_reaction .second ) << std::endl;
606
644
}
607
645
is_output_printed_ = true ;
608
646
}
@@ -1049,4 +1087,5 @@ bool ReactionAnalyzerNode::searchDetectedObjectsNearEntity(const DetectedObjects
1049
1087
#include < rclcpp_components/register_node_macro.hpp>
1050
1088
1051
1089
#include < utility>
1090
+
1052
1091
RCLCPP_COMPONENTS_REGISTER_NODE (reaction_analyzer::ReactionAnalyzerNode)
0 commit comments