Skip to content

Commit 392a83c

Browse files
committed
Keep timeout only
Signed-off-by: anhnv3991 <anh.nguyen.2@tier4.jp>
1 parent c0f09e1 commit 392a83c

File tree

3 files changed

+3
-96
lines changed

3 files changed

+3
-96
lines changed

localization/ndt_scan_matcher/include/ndt_scan_matcher/map_update_module.hpp

-7
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ class MapUpdateModule
6060
[[nodiscard]] bool should_update_map(const geometry_msgs::msg::Point & position);
6161
void publish_partial_pcd_map();
6262

63-
// Looking for PCDs in the vicinity of the specified location
64-
void query_pcds(
65-
double px, double py, double radius, std::unordered_set<std::string> & maps_to_add,
66-
std::unordered_set<std::string> & maps_to_remove);
67-
// Compute distance between an origin and a pcd segment
68-
double dist(double px, double py, int idx, int idy);
69-
7063
rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr loaded_pcd_pub_;
7164

7265
rclcpp::Client<autoware_map_msgs::srv::GetDifferentialPointCloudMap>::SharedPtr

localization/ndt_scan_matcher/src/map_update_module.cpp

+3-71
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,8 @@ bool MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, Ndt
146146
request,
147147
[](rclcpp::Client<autoware_map_msgs::srv::GetDifferentialPointCloudMap>::SharedFuture) {})};
148148

149-
// While waiting for the requested pcds, look for indices of the candidate pcds
150-
std::unordered_set<std::string> pcds_to_remove, pcds_to_add;
151-
152-
query_pcds(position.x, position.y, param_.map_radius, pcds_to_add, pcds_to_remove);
153-
154-
// Wait for maximum 20 milliseconds
155-
std::chrono::milliseconds timeout(20);
149+
// Wait for maximum 10 milliseconds
150+
std::chrono::milliseconds timeout(10);
156151
auto start = std::chrono::system_clock::now();
157152

158153
std::future_status status = result.wait_for(std::chrono::seconds(0));
@@ -177,20 +172,7 @@ bool MapUpdateModule::update_ndt(const geometry_msgs::msg::Point & position, Ndt
177172
auto & maps_to_add = result.get()->new_pointcloud_with_ids;
178173
auto & map_ids_to_remove = result.get()->ids_to_remove;
179174

180-
// Check if there are any maps in the pcds_to_add not coming
181-
for (auto & name : pcds_to_add) {
182-
if (maps_to_add.find(name) == maps_to_add.end()) {
183-
RCLCPP_ERROR_STREAM_THROTTLE(logger_, *clock_, 1000, "File %s not coming.", name.c_str());
184-
}
185-
}
186-
187-
for (auto & name : pcds_to_remove) {
188-
if (map_ids_to_remove.find(name) == map_ids_to_remove.end()) {
189-
RCLCPP_ERROR_STREAM_THROTTLE(
190-
logger_, *clock_, 1000, "File %s should be removed but it was not.", name.c_str());
191-
}
192-
}
193-
175+
// Check
194176
RCLCPP_INFO(
195177
logger_, "Update map (Add: %lu, Remove: %lu)", maps_to_add.size(), map_ids_to_remove.size());
196178
if (maps_to_add.empty() && map_ids_to_remove.empty()) {
@@ -233,53 +215,3 @@ void MapUpdateModule::publish_partial_pcd_map()
233215

234216
loaded_pcd_pub_->publish(map_msg);
235217
}
236-
237-
void MapUpdateModuble::query_pcds(
238-
double px, double py, double radius, std::unordered_set<std::string> & maps_to_add,
239-
std::unordered_set<std::string> & maps_to_remove)
240-
{
241-
int lower_x = static_cast<int>(floor((px - radius) / pcd_res_x_));
242-
int lower_y = static_cast<int>(floor((py - radius) / pcd_res_y_));
243-
int upper_x = static_cast<int>(floor((px + radius) / pcd_res_x_));
244-
int upper_y = static_cast<int>(floor((py + radius) / pcd_res_y_));
245-
double rel_px = px - pcd_lower_x_, rel_py = py - pcd_lower_y_;
246-
std::unordered_set<std::string> nn_pcds;
247-
248-
for (int idx = lower_x; idx < upper_x; ++idx) {
249-
for (int idy = lower_y; idy < upper_y; ++idy) {
250-
// Skip if the pcd file is not within the query radius
251-
if (dist(rel_px, rel_py, idx, idy) > radius) {
252-
continue;
253-
}
254-
255-
// Generate name of the PCD file
256-
std::string name = pcd_tag_ + "_" + std::to_string(x) + "_" + std::to_string(y) + ".pcd";
257-
258-
if (cur_pcds_.find(name) == cur_pcds_.end()) {
259-
maps_to_add.insert(name);
260-
} else {
261-
nn_pcds.insert(name);
262-
}
263-
}
264-
}
265-
266-
// Compare with @cur_pcds_ to find out which pcds to remove
267-
for (auto & name : cur_pcds_) {
268-
if (nn_pcds.find(name) == nn_pcds.end()) {
269-
map_ids_to_remove.insert(name);
270-
}
271-
}
272-
}
273-
274-
double MapUpdateModule::dist(double px, double py, int idx, int idy)
275-
{
276-
double lx = idx * pcd_res_x_;
277-
double ly = idy * pcd_res_y_;
278-
double ux = lx + pcd_res_x_;
279-
double uy = ly + pcd_res_y_;
280-
281-
double dx = (px < lx) ? lx - px : ((px >= ux) ? px - ux : 0);
282-
double dy = (py < ly) ? ly - py : ((py >= uy) ? py - uy : 0);
283-
284-
return std::hypot(dx, dy);
285-
}

map/map_loader/src/pointcloud_map_loader/differential_map_loader_module.cpp

-18
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ void DifferentialMapLoaderModule::differentialAreaLoad(
2929
const autoware_map_msgs::msg::AreaInfo & area, const std::vector<std::string> & cached_ids,
3030
GetDifferentialPointCloudMap::Response::SharedPtr & response) const
3131
{
32-
// For debug
33-
std::ofstream test("/home/anh/Work/autoware/test.txt", std::ios::app);
34-
35-
test << __FILE__ << "::" << __LINE__ << "::" << __func__ << std::endl;
36-
// End
37-
3832
// iterate over all the available pcd map grids
3933
std::vector<bool> should_remove(static_cast<int>(cached_ids.size()), true);
4034
for (const auto & ele : all_pcd_file_metadata_dict_) {
@@ -73,12 +67,6 @@ bool DifferentialMapLoaderModule::onServiceGetDifferentialPointCloudMap(
7367
GetDifferentialPointCloudMap::Request::SharedPtr req,
7468
GetDifferentialPointCloudMap::Response::SharedPtr res)
7569
{
76-
// For debug
77-
std::ofstream test("/home/anh/Work/autoware/test.txt", std::ios::app);
78-
79-
test << __FILE__ << "::" << __LINE__ << "::" << __func__ << std::endl;
80-
// End
81-
8270
auto area = req->area;
8371
std::vector<std::string> cached_ids = req->cached_ids;
8472
differentialAreaLoad(area, cached_ids, res);
@@ -90,12 +78,6 @@ autoware_map_msgs::msg::PointCloudMapCellWithID
9078
DifferentialMapLoaderModule::loadPointCloudMapCellWithID(
9179
const std::string & path, const std::string & map_id) const
9280
{
93-
// For debug
94-
std::ofstream test("/home/anh/Work/autoware/test.txt", std::ios::app);
95-
96-
test << __FILE__ << "::" << __LINE__ << "::" << __func__ << std::endl;
97-
// End
98-
9981
sensor_msgs::msg::PointCloud2 pcd;
10082
if (pcl::io::loadPCDFile(path, pcd) == -1) {
10183
RCLCPP_ERROR_STREAM(logger_, "PCD load failed: " << path);

0 commit comments

Comments
 (0)