Skip to content

Commit 5d0ac56

Browse files
Merge pull request #1161 from tier4/beta/v0.23.0+hotfix_localization_ndt_scan_matcher
fix(ndt_scan_matcher): fixed an issue where processing speed was slow when using a single map
2 parents 94e5f48 + 9161649 commit 5d0ac56

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

localization/ndt_scan_matcher/include/ndt_scan_matcher/map_update_module.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class MapUpdateModule
5555
friend class NDTScanMatcher;
5656

5757
// Update the specified NDT
58-
void update_ndt(const geometry_msgs::msg::Point & position, NdtType & ndt);
58+
bool update_ndt(const geometry_msgs::msg::Point & position, NdtType & ndt);
5959
void update_map(const geometry_msgs::msg::Point & position);
6060
[[nodiscard]] bool should_update_map(const geometry_msgs::msg::Point & position);
6161
void publish_partial_pcd_map();

localization/ndt_scan_matcher/src/map_update_module.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ void MapUpdateModule::update_map(const geometry_msgs::msg::Point & position)
7070
// lock and rebuild ndt_ptr_
7171
if (need_rebuild_) {
7272
ndt_ptr_mutex_->lock();
73+
7374
auto param = ndt_ptr_->getParams();
7475

7576
ndt_ptr_.reset(new NdtType);
@@ -85,13 +86,20 @@ void MapUpdateModule::update_map(const geometry_msgs::msg::Point & position)
8586
// the main ndt_ptr_) overlap, the latency of updating/alignment reduces partly.
8687
// If the updating is done the main ndt_ptr_, either the update or the NDT
8788
// align will be blocked by the other.
88-
update_ndt(position, *secondary_ndt_ptr_);
89+
const bool updated = update_ndt(position, *secondary_ndt_ptr_);
90+
if (!updated) {
91+
last_update_position_ = position;
92+
return;
93+
}
8994

9095
ndt_ptr_mutex_->lock();
96+
auto dummy_ptr = ndt_ptr_;
9197
auto input_source = ndt_ptr_->getInputSource();
9298
ndt_ptr_ = secondary_ndt_ptr_;
9399
ndt_ptr_->setInputSource(input_source);
94100
ndt_ptr_mutex_->unlock();
101+
102+
dummy_ptr.reset();
95103
}
96104

97105
secondary_ndt_ptr_.reset(new NdtType);
@@ -104,7 +112,7 @@ void MapUpdateModule::update_map(const geometry_msgs::msg::Point & position)
104112
publish_partial_pcd_map();
105113
}
106114

107-
void MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, NdtType & ndt)
115+
bool MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, NdtType & ndt)
108116
{
109117
auto request = std::make_shared<autoware_map_msgs::srv::GetDifferentialPointCloudMap::Request>();
110118

@@ -126,7 +134,7 @@ void MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, Ndt
126134
while (status != std::future_status::ready) {
127135
RCLCPP_INFO(logger_, "waiting response");
128136
if (!rclcpp::ok()) {
129-
return;
137+
return false; // No update
130138
}
131139
status = result.wait_for(std::chrono::seconds(1));
132140
}
@@ -138,7 +146,7 @@ void MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, Ndt
138146
logger_, "Update map (Add: %lu, Remove: %lu)", maps_to_add.size(), map_ids_to_remove.size());
139147
if (maps_to_add.empty() && map_ids_to_remove.empty()) {
140148
RCLCPP_INFO(logger_, "Skip map update");
141-
return;
149+
return false; // No update
142150
}
143151

144152
const auto exe_start_time = std::chrono::system_clock::now();
@@ -168,6 +176,7 @@ void MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, Ndt
168176
std::chrono::duration_cast<std::chrono::microseconds>(exe_end_time - exe_start_time).count();
169177
const auto exe_time = static_cast<double>(duration_micro_sec) / 1000.0;
170178
RCLCPP_INFO(logger_, "Time duration for creating new ndt_ptr: %lf [ms]", exe_time);
179+
return true; // Updated
171180
}
172181

173182
void MapUpdateModule::publish_partial_pcd_map()

0 commit comments

Comments
 (0)