@@ -70,6 +70,7 @@ void MapUpdateModule::update_map(const geometry_msgs::msg::Point & position)
70
70
// lock and rebuild ndt_ptr_
71
71
if (need_rebuild_) {
72
72
ndt_ptr_mutex_->lock ();
73
+
73
74
auto param = ndt_ptr_->getParams ();
74
75
75
76
ndt_ptr_.reset (new NdtType);
@@ -85,13 +86,20 @@ void MapUpdateModule::update_map(const geometry_msgs::msg::Point & position)
85
86
// the main ndt_ptr_) overlap, the latency of updating/alignment reduces partly.
86
87
// If the updating is done the main ndt_ptr_, either the update or the NDT
87
88
// 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
+ }
89
94
90
95
ndt_ptr_mutex_->lock ();
96
+ auto dummy_ptr = ndt_ptr_;
91
97
auto input_source = ndt_ptr_->getInputSource ();
92
98
ndt_ptr_ = secondary_ndt_ptr_;
93
99
ndt_ptr_->setInputSource (input_source);
94
100
ndt_ptr_mutex_->unlock ();
101
+
102
+ dummy_ptr.reset ();
95
103
}
96
104
97
105
secondary_ndt_ptr_.reset (new NdtType);
@@ -104,7 +112,7 @@ void MapUpdateModule::update_map(const geometry_msgs::msg::Point & position)
104
112
publish_partial_pcd_map ();
105
113
}
106
114
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)
108
116
{
109
117
auto request = std::make_shared<autoware_map_msgs::srv::GetDifferentialPointCloudMap::Request>();
110
118
@@ -126,7 +134,7 @@ void MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, Ndt
126
134
while (status != std::future_status::ready) {
127
135
RCLCPP_INFO (logger_, " waiting response" );
128
136
if (!rclcpp::ok ()) {
129
- return ;
137
+ return false ; // No update
130
138
}
131
139
status = result.wait_for (std::chrono::seconds (1 ));
132
140
}
@@ -138,7 +146,7 @@ void MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, Ndt
138
146
logger_, " Update map (Add: %lu, Remove: %lu)" , maps_to_add.size (), map_ids_to_remove.size ());
139
147
if (maps_to_add.empty () && map_ids_to_remove.empty ()) {
140
148
RCLCPP_INFO (logger_, " Skip map update" );
141
- return ;
149
+ return false ; // No update
142
150
}
143
151
144
152
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
168
176
std::chrono::duration_cast<std::chrono::microseconds>(exe_end_time - exe_start_time).count ();
169
177
const auto exe_time = static_cast <double >(duration_micro_sec) / 1000.0 ;
170
178
RCLCPP_INFO (logger_, " Time duration for creating new ndt_ptr: %lf [ms]" , exe_time);
179
+ return true ; // Updated
171
180
}
172
181
173
182
void MapUpdateModule::publish_partial_pcd_map ()
0 commit comments