Skip to content

Commit 79f9c24

Browse files
committed
fix: routing error
Signed-off-by: Ryohsuke Mitsudome <ryohsuke.mitsudome@tier4.jp>
1 parent 22eed15 commit 79f9c24

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

map/autoware_map_loader/src/lanelet2_map_loader/lanelet2_differential_loader_module.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ bool Lanelet2DifferentialLoaderModule::onServiceGetDifferentialLanelet2Map(
4848
GetDifferentialLanelet2Map::Request::SharedPtr req,
4949
GetDifferentialLanelet2Map::Response::SharedPtr res)
5050
{
51+
if (!projector_info_) {
52+
RCLCPP_ERROR(logger_, "Projector info is not set");
53+
return false;
54+
}
55+
5156
// get the list of lanelet2 map paths from the requested cell_ids
5257
std::vector<std::string> lanelet2_paths;
5358
for (const auto & id : req->cell_ids) {
@@ -67,16 +72,23 @@ bool Lanelet2DifferentialLoaderModule::onServiceGetDifferentialLanelet2Map(
6772
return false;
6873
}
6974

70-
// load the lanelet2 maps
71-
lanelet::LaneletMapPtr map = std::make_shared<lanelet::LaneletMap>();
75+
// load lanelet2 map
76+
// We have to keep all loaded maps until publishing the map bin msg
77+
// because the loaded lanelets will be expired when map is destructed
78+
std::vector<lanelet::LaneletMapPtr> maps;
7279
for (const auto & path : lanelet2_paths) {
73-
auto map_tmp = utils::load_map(path, projector_info_.value());
80+
auto map_tmp = utils::load_map(path, *projector_info_);
7481
if (!map_tmp) {
75-
RCLCPP_ERROR(
76-
rclcpp::get_logger("map_loader"), "Failed to load lanelet2_map %s", path.c_str());
82+
RCLCPP_ERROR(logger_, "Failed to load lanelet2_map, %s", path.c_str());
7783
return false;
7884
}
79-
utils::merge_lanelet2_maps(*map, *map_tmp);
85+
maps.push_back(map_tmp);
86+
}
87+
88+
// merge all maps
89+
lanelet::LaneletMapPtr map = std::make_shared<lanelet::LaneletMap>();
90+
for (const auto & map_i : maps) {
91+
utils::merge_lanelet2_maps(*map, *map_i);
8092
}
8193

8294
// overwrite centerline

map/autoware_map_loader/src/lanelet2_map_loader/lanelet2_map_loader_node.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,22 @@ void Lanelet2MapLoaderNode::on_map_projector_info(
152152
}
153153

154154
// load lanelet2 map
155-
lanelet::LaneletMapPtr map = std::make_shared<lanelet::LaneletMap>();
155+
// We have to keep all loaded maps until publishing the map bin msg
156+
// because the loaded lanelets will be expired when map is destructed
157+
std::vector<lanelet::LaneletMapPtr> maps;
156158
for (const auto & path : lanelet2_paths) {
157159
auto map_tmp = utils::load_map(path, *msg);
158160
if (!map_tmp) {
159-
RCLCPP_ERROR(get_logger(), "Failed to load lanelet2_map. Not published.");
161+
RCLCPP_ERROR(get_logger(), "Failed to load lanelet2_map, %s", path.c_str());
160162
return;
161163
}
162-
utils::merge_lanelet2_maps(*map, *map_tmp);
164+
maps.push_back(map_tmp);
165+
}
166+
167+
// merge all maps
168+
lanelet::LaneletMapPtr map = std::make_shared<lanelet::LaneletMap>();
169+
for (const auto & map_i : maps) {
170+
utils::merge_lanelet2_maps(*map, *map_i);
163171
}
164172

165173
// we use first lanelet2 path to get format_version and map_version

map/autoware_map_loader/src/lanelet2_map_loader/lanelet2_map_loader_utils.cpp

+17-5
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,31 @@ void merge_lanelet2_maps(lanelet::LaneletMap & merge_target, lanelet::LaneletMap
141141
for (lanelet::Lanelet & lanelet : merge_source.laneletLayer) {
142142
merge_target.add(lanelet);
143143
}
144-
for (const auto & area : merge_source.areaLayer) {
144+
145+
for (lanelet::Area & area : merge_source.areaLayer) {
145146
merge_target.add(area);
146147
}
147-
for (const auto & regulatory_element : merge_source.regulatoryElementLayer) {
148+
149+
for (lanelet::RegulatoryElementPtr & regulatory_element : merge_source.regulatoryElementLayer) {
148150
merge_target.add(regulatory_element);
149151
}
150-
for (const auto & line_string : merge_source.lineStringLayer) {
152+
153+
for (lanelet::LineString3d & line_string : merge_source.lineStringLayer) {
154+
// we need a special handling for line_string to make sure that the points are not duplicated
155+
// Otherwise, we cannot calculate the relationship of succeeding lanelets correctly
156+
for (lanelet::Point3d & point : line_string) {
157+
if (merge_target.pointLayer.find(point.id()) != merge_target.pointLayer.end()) {
158+
point = merge_target.pointLayer.get(point.id());
159+
}
160+
}
151161
merge_target.add(line_string);
152162
}
153-
for (const auto & polygon : merge_source.polygonLayer) {
163+
164+
for (lanelet::Polygon3d & polygon : merge_source.polygonLayer) {
154165
merge_target.add(polygon);
155166
}
156-
for (const auto & point : merge_source.pointLayer) {
167+
168+
for (lanelet::Point3d & point : merge_source.pointLayer) {
157169
merge_target.add(point);
158170
}
159171
}

0 commit comments

Comments
 (0)