Skip to content

Commit 0134e4b

Browse files
Fixed update_ndt
Signed-off-by: Shintaro Sakoda <shintaro.sakoda@tier4.jp>
1 parent 4b784b4 commit 0134e4b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-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

+9-4
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ void MapUpdateModule::update_map(const geometry_msgs::msg::Point & position)
8787
// the main ndt_ptr_) overlap, the latency of updating/alignment reduces partly.
8888
// If the updating is done the main ndt_ptr_, either the update or the NDT
8989
// align will be blocked by the other.
90-
update_ndt(position, *secondary_ndt_ptr_);
90+
const bool updated = update_ndt(position, *secondary_ndt_ptr_);
91+
if (!updated) {
92+
last_update_position_ = position;
93+
return;
94+
}
9195

9296
ndt_ptr_mutex_->lock();
9397
auto input_source = ndt_ptr_->getInputSource();
@@ -106,7 +110,7 @@ void MapUpdateModule::update_map(const geometry_msgs::msg::Point & position)
106110
publish_partial_pcd_map();
107111
}
108112

109-
void MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, NdtType & ndt)
113+
bool MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, NdtType & ndt)
110114
{
111115
auto request = std::make_shared<autoware_map_msgs::srv::GetDifferentialPointCloudMap::Request>();
112116

@@ -128,7 +132,7 @@ void MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, Ndt
128132
while (status != std::future_status::ready) {
129133
RCLCPP_INFO(logger_, "waiting response");
130134
if (!rclcpp::ok()) {
131-
return;
135+
return false; // No update
132136
}
133137
status = result.wait_for(std::chrono::seconds(1));
134138
}
@@ -140,7 +144,7 @@ void MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, Ndt
140144
logger_, "Update map (Add: %lu, Remove: %lu)", maps_to_add.size(), map_ids_to_remove.size());
141145
if (maps_to_add.empty() && map_ids_to_remove.empty()) {
142146
RCLCPP_INFO(logger_, "Skip map update");
143-
return;
147+
return false; // No update
144148
}
145149

146150
const auto exe_start_time = std::chrono::system_clock::now();
@@ -170,6 +174,7 @@ void MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, Ndt
170174
std::chrono::duration_cast<std::chrono::microseconds>(exe_end_time - exe_start_time).count();
171175
const auto exe_time = static_cast<double>(duration_micro_sec) / 1000.0;
172176
RCLCPP_INFO(logger_, "Time duration for creating new ndt_ptr: %lf [ms]", exe_time);
177+
return true; // Updated
173178
}
174179

175180
void MapUpdateModule::publish_partial_pcd_map()

0 commit comments

Comments
 (0)