Skip to content

Commit 194745d

Browse files
committed
Optimizing radiusSearch speed
Signed-off-by: anhnv3991 <anh.nguyen.2@tier4.jp>
1 parent caa454e commit 194745d

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

localization/ndt_scan_matcher/include/ndt_scan_matcher/ndt_scan_matcher_core.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ class NDTScanMatcher : public rclcpp::Node
198198
std::unique_ptr<tier4_autoware_utils::LoggerLevelConfigure> logger_configure_;
199199

200200
HyperParameters param_;
201+
202+
// For debug
203+
std::ofstream exe_log_file_;
201204
};
202205

206+
#ifndef timeDiff
207+
#define timeDiff(start, end) ((end.tv_sec - start.tv_sec) * 1000000 + end.tv_usec - start.tv_usec)
208+
#endif
209+
203210
#endif // NDT_SCAN_MATCHER__NDT_SCAN_MATCHER_CORE_HPP_

localization/ndt_scan_matcher/src/map_update_module.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ bool MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, Ndt
151151
return false; // No update
152152
}
153153

154+
// For debug
155+
std::ofstream test_file("/home/anh/Work/autoware/exe_time.csv", std::ios::app);
156+
154157
const auto exe_start_time = std::chrono::system_clock::now();
155158
// Perform heavy processing outside of the lock scope
156159

@@ -174,6 +177,8 @@ bool MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, Ndt
174177
std::chrono::duration_cast<std::chrono::microseconds>(exe_end_time - exe_start_time).count();
175178
const auto exe_time = static_cast<double>(duration_micro_sec) / 1000.0;
176179
RCLCPP_INFO(logger_, "Time duration for creating new ndt_ptr: %lf [ms]", exe_time);
180+
181+
test_file << exe_time << std::endl;
177182
return true; // Updated
178183
}
179184

localization/ndt_scan_matcher/src/ndt_scan_matcher_core.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ NDTScanMatcher::NDTScanMatcher()
185185
std::make_unique<MapUpdateModule>(this, &ndt_ptr_mtx_, ndt_ptr_, param_.dynamic_map_loading);
186186

187187
logger_configure_ = std::make_unique<tier4_autoware_utils::LoggerLevelConfigure>(this);
188+
189+
// For debug
190+
exe_log_file_.open("/home/anh/Work/autoware/align_cost.csv");
188191
}
189192

190193
void NDTScanMatcher::publish_diagnostic()
@@ -330,11 +333,13 @@ void NDTScanMatcher::callback_sensor_points(
330333
// return;
331334
}
332335

336+
// Put the time counter here to measure the actual processing time
337+
// = time of waiting for unlock + time of align
338+
const auto exe_start_time = std::chrono::system_clock::now();
339+
333340
// mutex ndt_ptr_
334341
std::lock_guard<std::mutex> lock(ndt_ptr_mtx_);
335342

336-
const auto exe_start_time = std::chrono::system_clock::now();
337-
338343
// preprocess input pointcloud
339344
pcl::shared_ptr<pcl::PointCloud<PointSource>> sensor_points_in_sensor_frame(
340345
new pcl::PointCloud<PointSource>);
@@ -425,6 +430,10 @@ void NDTScanMatcher::callback_sensor_points(
425430
std::chrono::duration_cast<std::chrono::microseconds>(exe_end_time - exe_start_time).count();
426431
const auto exe_time = static_cast<float>(duration_micro_sec) / 1000.0f;
427432

433+
// For debug
434+
exe_log_file_ << exe_time << "," << ndt_result.iteration_num << std::endl;
435+
// End
436+
428437
// publish
429438
initial_pose_with_covariance_pub_->publish(interpolation_result.interpolated_pose);
430439
exe_time_pub_->publish(make_float32_stamped(sensor_ros_time, exe_time));

0 commit comments

Comments
 (0)