@@ -232,70 +232,69 @@ NDTScanMatcher::NDTScanMatcher()
232
232
&NDTScanMatcher::service_trigger_node, this , std::placeholders::_1, std::placeholders::_2),
233
233
rclcpp::ServicesQoS ().get_rmw_qos_profile (), main_callback_group);
234
234
235
- diagnostic_thread_ = std::thread (&NDTScanMatcher::timer_diagnostic, this );
236
- diagnostic_thread_.detach ();
237
-
238
235
tf2_listener_module_ = std::make_shared<Tf2ListenerModule>(this );
239
236
240
237
use_dynamic_map_loading_ = this ->declare_parameter <bool >(" use_dynamic_map_loading" );
241
238
if (use_dynamic_map_loading_) {
242
239
map_update_module_ = std::make_unique<MapUpdateModule>(
243
- this , &ndt_ptr_mtx_, ndt_ptr_, tf2_listener_module_, map_frame_, main_callback_group,
244
- state_ptr_);
240
+ this , &ndt_ptr_mtx_, ndt_ptr_, tf2_listener_module_, map_frame_, main_callback_group);
245
241
} else {
246
242
map_module_ = std::make_unique<MapModule>(this , &ndt_ptr_mtx_, ndt_ptr_, main_callback_group);
247
243
}
248
244
}
249
245
250
- void NDTScanMatcher::timer_diagnostic ()
246
+ void NDTScanMatcher::publish_diagnostic ()
251
247
{
252
- rclcpp::Rate rate (100 );
253
- while (rclcpp::ok ()) {
254
- diagnostic_msgs::msg::DiagnosticStatus diag_status_msg;
255
- diag_status_msg.name = " ndt_scan_matcher" ;
256
- diag_status_msg.hardware_id = " " ;
257
-
258
- for (const auto & key_value : (*state_ptr_)) {
259
- diagnostic_msgs::msg::KeyValue key_value_msg;
260
- key_value_msg.key = key_value.first ;
261
- key_value_msg.value = key_value.second ;
262
- diag_status_msg.values .push_back (key_value_msg);
263
- }
248
+ diagnostic_msgs::msg::DiagnosticStatus diag_status_msg;
249
+ diag_status_msg.name = " ndt_scan_matcher" ;
250
+ diag_status_msg.hardware_id = " " ;
251
+
252
+ for (const auto & key_value : (*state_ptr_)) {
253
+ diagnostic_msgs::msg::KeyValue key_value_msg;
254
+ key_value_msg.key = key_value.first ;
255
+ key_value_msg.value = key_value.second ;
256
+ diag_status_msg.values .push_back (key_value_msg);
257
+ }
264
258
259
+ diag_status_msg.level = diagnostic_msgs::msg::DiagnosticStatus::OK;
260
+ diag_status_msg.message = " " ;
261
+ if (state_ptr_->count (" state" ) && (*state_ptr_)[" state" ] == " Initializing" ) {
262
+ diag_status_msg.level = diagnostic_msgs::msg::DiagnosticStatus::WARN;
263
+ diag_status_msg.message += " Initializing State. " ;
264
+ }
265
+ if (
266
+ state_ptr_->count (" skipping_publish_num" ) &&
267
+ std::stoi ((*state_ptr_)[" skipping_publish_num" ]) > 1 &&
268
+ std::stoi ((*state_ptr_)[" skipping_publish_num" ]) < 5 ) {
269
+ diag_status_msg.level = diagnostic_msgs::msg::DiagnosticStatus::WARN;
270
+ diag_status_msg.message += " skipping_publish_num > 1. " ;
271
+ }
272
+ if (
273
+ state_ptr_->count (" skipping_publish_num" ) &&
274
+ std::stoi ((*state_ptr_)[" skipping_publish_num" ]) >= 5 ) {
275
+ diag_status_msg.level = diagnostic_msgs::msg::DiagnosticStatus::ERROR;
276
+ diag_status_msg.message += " skipping_publish_num exceed limit. " ;
277
+ }
278
+ if (
279
+ state_ptr_->count (" nearest_voxel_transformation_likelihood" ) &&
280
+ std::stod ((*state_ptr_)[" nearest_voxel_transformation_likelihood" ]) <
281
+ converged_param_nearest_voxel_transformation_likelihood_) {
282
+ diag_status_msg.level = diagnostic_msgs::msg::DiagnosticStatus::WARN;
283
+ diag_status_msg.message += " NDT score is unreliably low. " ;
284
+ }
285
+ // Ignore local optimal solution
286
+ if (
287
+ state_ptr_->count (" is_local_optimal_solution_oscillation" ) &&
288
+ std::stoi ((*state_ptr_)[" is_local_optimal_solution_oscillation" ])) {
265
289
diag_status_msg.level = diagnostic_msgs::msg::DiagnosticStatus::OK;
266
- diag_status_msg.message = " " ;
267
- if (state_ptr_->count (" state" ) && (*state_ptr_)[" state" ] == " Initializing" ) {
268
- diag_status_msg.level = diagnostic_msgs::msg::DiagnosticStatus::WARN;
269
- diag_status_msg.message += " Initializing State. " ;
270
- }
271
- if (
272
- state_ptr_->count (" skipping_publish_num" ) &&
273
- std::stoi ((*state_ptr_)[" skipping_publish_num" ]) > 1 ) {
274
- diag_status_msg.level = diagnostic_msgs::msg::DiagnosticStatus::WARN;
275
- diag_status_msg.message += " skipping_publish_num > 1. " ;
276
- }
277
- if (
278
- state_ptr_->count (" skipping_publish_num" ) &&
279
- std::stoi ((*state_ptr_)[" skipping_publish_num" ]) >= 5 ) {
280
- diag_status_msg.level = diagnostic_msgs::msg::DiagnosticStatus::ERROR;
281
- diag_status_msg.message += " skipping_publish_num exceed limit. " ;
282
- }
283
- // Ignore local optimal solution
284
- if (
285
- state_ptr_->count (" is_local_optimal_solution_oscillation" ) &&
286
- std::stoi ((*state_ptr_)[" is_local_optimal_solution_oscillation" ])) {
287
- diag_status_msg.level = diagnostic_msgs::msg::DiagnosticStatus::OK;
288
- diag_status_msg.message = " local optimal solution oscillation occurred" ;
289
- }
290
-
291
- diagnostic_msgs::msg::DiagnosticArray diag_msg;
292
- diag_msg.header .stamp = this ->now ();
293
- diag_msg.status .push_back (diag_status_msg);
290
+ diag_status_msg.message = " local optimal solution oscillation occurred" ;
291
+ }
294
292
295
- diagnostics_pub_->publish (diag_msg);
293
+ diagnostic_msgs::msg::DiagnosticArray diag_msg;
294
+ diag_msg.header .stamp = this ->now ();
295
+ diag_msg.status .push_back (diag_status_msg);
296
296
297
- rate.sleep ();
298
- }
297
+ diagnostics_pub_->publish (diag_msg);
299
298
}
300
299
301
300
void NDTScanMatcher::callback_initial_pose (
@@ -387,13 +386,11 @@ void NDTScanMatcher::callback_sensor_points(
387
386
}
388
387
389
388
// perform ndt scan matching
390
- (*state_ptr_)[" state" ] = " Aligning" ;
391
389
const Eigen::Matrix4f initial_pose_matrix =
392
390
pose_to_matrix4f (interpolator.get_current_pose ().pose .pose );
393
391
auto output_cloud = std::make_shared<pcl::PointCloud<PointSource>>();
394
392
ndt_ptr_->align (*output_cloud, initial_pose_matrix);
395
393
const pclomp::NdtResult ndt_result = ndt_ptr_->getResult ();
396
- (*state_ptr_)[" state" ] = " Sleeping" ;
397
394
398
395
const auto exe_end_time = std::chrono::system_clock::now ();
399
396
const auto duration_micro_sec =
@@ -488,6 +485,7 @@ void NDTScanMatcher::callback_sensor_points(
488
485
make_float32_stamped (sensor_ros_time, no_ground_nearest_voxel_transformation_likelihood));
489
486
}
490
487
488
+ (*state_ptr_)[" state" ] = " Aligned" ;
491
489
(*state_ptr_)[" transform_probability" ] = std::to_string (ndt_result.transform_probability );
492
490
(*state_ptr_)[" nearest_voxel_transformation_likelihood" ] =
493
491
std::to_string (ndt_result.nearest_voxel_transformation_likelihood );
@@ -498,6 +496,8 @@ void NDTScanMatcher::callback_sensor_points(
498
496
} else {
499
497
(*state_ptr_)[" is_local_optimal_solution_oscillation" ] = " 0" ;
500
498
}
499
+
500
+ publish_diagnostic ();
501
501
}
502
502
503
503
void NDTScanMatcher::transform_sensor_measurement (
@@ -694,8 +694,6 @@ void NDTScanMatcher::service_trigger_node(
694
694
if (is_activated_) {
695
695
std::lock_guard<std::mutex> initial_pose_array_lock (initial_pose_array_mtx_);
696
696
initial_pose_msg_ptr_array_.clear ();
697
- } else {
698
- (*state_ptr_)[" state" ] = " Initializing" ;
699
697
}
700
698
res->success = true ;
701
699
}
@@ -731,9 +729,7 @@ void NDTScanMatcher::service_ndt_align(
731
729
// mutex Map
732
730
std::lock_guard<std::mutex> lock (ndt_ptr_mtx_);
733
731
734
- (*state_ptr_)[" state" ] = " Aligning" ;
735
732
res->pose_with_covariance = align_using_monte_carlo (ndt_ptr_, initial_pose_msg_in_map_frame);
736
- (*state_ptr_)[" state" ] = " Sleeping" ;
737
733
res->success = true ;
738
734
res->pose_with_covariance .pose .covariance = req->pose_with_covariance .pose .covariance ;
739
735
}
0 commit comments