forked from autowarefoundation/autoware.universe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Barış Zeren <[email protected]>
- Loading branch information
1 parent
a3e4121
commit 4c5b9b3
Showing
7 changed files
with
446 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
map/map_loader/include/map_loader/lanelet2_differential_loader_module.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2022 The Autoware Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef MAP_LOADER_LANELET2_DIFFERENTIAL_LOADER_MODULE_HPP | ||
#define MAP_LOADER_LANELET2_DIFFERENTIAL_LOADER_MODULE_HPP | ||
|
||
#include "lanelet2_extension/io/autoware_multi_osm_parser.hpp" | ||
#include "map_loader/utils.hpp" | ||
|
||
#include <lanelet2_extension/io/autoware_osm_parser.hpp> | ||
#include <lanelet2_extension/projection/mgrs_projector.hpp> | ||
#include <lanelet2_extension/utility/message_conversion.hpp> | ||
#include <lanelet2_extension/utility/utilities.hpp> | ||
#include <pugixml.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include "autoware_map_msgs/srv/get_differential_lanelet2_map.hpp" | ||
#include <autoware_auto_mapping_msgs/msg/had_map_bin.hpp> | ||
#include <autoware_map_msgs/msg/lanelet_map_meta_data.hpp> | ||
|
||
#include <lanelet2_core/LaneletMap.h> | ||
#include <lanelet2_core/geometry/LineString.h> | ||
#include <lanelet2_io/Io.h> | ||
#include <lanelet2_projection/UTM.h> | ||
|
||
#include <filesystem> | ||
|
||
class Lanelet2DifferentialLoaderModule | ||
{ | ||
using GetDifferentialLanelet2Map = autoware_map_msgs::srv::GetDifferentialLanelet2Map; | ||
using HADMapBin = autoware_auto_mapping_msgs::msg::HADMapBin; | ||
|
||
public: | ||
explicit Lanelet2DifferentialLoaderModule( | ||
rclcpp::Node * node, | ||
const std::map<std::string, Lanelet2FileMetaData> & lanelet2_file_metadata_dict); | ||
|
||
private: | ||
rclcpp::Logger logger_; | ||
rclcpp::Clock::SharedPtr clock_; | ||
|
||
std::map<std::string, Lanelet2FileMetaData> lanelet2_file_metadata_dict_; | ||
|
||
rclcpp::Service<GetDifferentialLanelet2Map>::SharedPtr get_differential_lanelet2_maps_service_; | ||
|
||
rclcpp::Publisher<HADMapBin>::SharedPtr pub_map_bin_; | ||
rclcpp::Publisher<HADMapBin>::SharedPtr pub_map_bin_debug_; | ||
|
||
rclcpp::Publisher<autoware_map_msgs::msg::LaneletMapMetaData>::SharedPtr | ||
pub_lanelet_map_meta_data_; | ||
|
||
bool onServiceGetDifferentialLanelet2Map( | ||
GetDifferentialLanelet2Map::Request::SharedPtr req, | ||
GetDifferentialLanelet2Map::Response::SharedPtr res); | ||
|
||
bool differentialLanelet2Load( | ||
GetDifferentialLanelet2Map::Request::SharedPtr & request, | ||
GetDifferentialLanelet2Map::Response::SharedPtr & response); | ||
|
||
autoware_map_msgs::msg::LaneletMapMetaData getLaneletMapMetaDataMsg() const; | ||
|
||
private: | ||
// Lanelet Parser Functions | ||
}; | ||
|
||
#endif // MAP_LOADER_LANELET2_DIFFERENTIAL_LOADER_MODULE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2022 The Autoware Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef MAP_LOADER_UTILS_HPP | ||
#define MAP_LOADER_UTILS_HPP | ||
|
||
#include <yaml-cpp/yaml.h> | ||
|
||
#include <map> | ||
#include <string> | ||
#include <vector> | ||
|
||
struct Lanelet2FileMetaData | ||
{ | ||
int id; | ||
double origin_lat; | ||
double origin_lon; | ||
std::string mgrs_code; | ||
}; | ||
|
||
std::map<std::string, Lanelet2FileMetaData> loadLanelet2Metadata( | ||
const std::string & lanelet2_metadata_path); | ||
std::map<std::string, Lanelet2FileMetaData> replaceWithAbsolutePath( | ||
const std::map<std::string, Lanelet2FileMetaData> & lanelet2_metadata_path, | ||
const std::vector<std::string> & lanelet2_paths); | ||
|
||
#endif // MAP_LOADER_UTILS_HPP |
188 changes: 188 additions & 0 deletions
188
map/map_loader/src/lanelet2_map_loader/lanelet2_differential_loader_module.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
// Copyright 2022 The Autoware Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "map_loader/lanelet2_differential_loader_module.hpp" | ||
|
||
#include "map_loader/lanelet2_map_loader_node.hpp" | ||
|
||
Lanelet2DifferentialLoaderModule::Lanelet2DifferentialLoaderModule( | ||
rclcpp::Node * node, | ||
const std::map<std::string, Lanelet2FileMetaData> & lanelet2_file_metadata_dict) | ||
: logger_(node->get_logger()), | ||
clock_(node->get_clock()), | ||
lanelet2_file_metadata_dict_(lanelet2_file_metadata_dict) | ||
{ | ||
// Publish lanelet2 map meta data | ||
{ | ||
pub_lanelet_map_meta_data_ = node->create_publisher<autoware_map_msgs::msg::LaneletMapMetaData>( | ||
"/map/lanelet2_map_meta_data", rclcpp::QoS{1}.transient_local()); | ||
|
||
const auto msg = getLaneletMapMetaDataMsg(); | ||
|
||
pub_lanelet_map_meta_data_->publish(msg); | ||
} | ||
|
||
get_differential_lanelet2_maps_service_ = node->create_service<GetDifferentialLanelet2Map>( | ||
"/map/get_differential_lanelet2_map", | ||
std::bind( | ||
&Lanelet2DifferentialLoaderModule::onServiceGetDifferentialLanelet2Map, this, | ||
std::placeholders::_1, std::placeholders::_2)); | ||
|
||
pub_map_bin_ = node->create_publisher<HADMapBin>( | ||
"/map/differential_lanelet2_map_bin", rclcpp::QoS{1}.transient_local()); | ||
pub_map_bin_debug_ = | ||
node->create_publisher<HADMapBin>("/map/vector_map", rclcpp::QoS{1}.transient_local()); | ||
} | ||
|
||
bool Lanelet2DifferentialLoaderModule::onServiceGetDifferentialLanelet2Map( | ||
GetDifferentialLanelet2Map::Request::SharedPtr req, | ||
GetDifferentialLanelet2Map::Response::SharedPtr res) | ||
{ | ||
if (!differentialLanelet2Load(req, res)) { | ||
RCLCPP_ERROR(logger_, "Failed to load differential lanelet2 map"); | ||
return false; | ||
} | ||
res->header.stamp = clock_->now(); | ||
res->header.frame_id = "map"; | ||
|
||
return true; | ||
} | ||
|
||
bool Lanelet2DifferentialLoaderModule::differentialLanelet2Load( | ||
GetDifferentialLanelet2Map::Request::SharedPtr & request, | ||
GetDifferentialLanelet2Map::Response::SharedPtr & response) | ||
{ | ||
{ | ||
std::vector<std::string> lanelet2_paths; | ||
for (const auto & path : lanelet2_file_metadata_dict_) { | ||
if (!std::filesystem::exists(path.first)) { | ||
continue; | ||
} | ||
lanelet2_paths.push_back(path.first); | ||
} | ||
if (lanelet2_paths.empty()) { | ||
return false; | ||
} | ||
|
||
lanelet::ErrorMessages errors{}; | ||
lanelet::projection::MGRSProjector projector{}; | ||
lanelet::io_handlers::MultiOsmParser parser(projector, {}); | ||
lanelet::LaneletMapPtr map = parser.parse(lanelet2_paths, errors); | ||
|
||
for (lanelet::Point3d point : map->pointLayer) { | ||
if (point.hasAttribute("local_x")) { | ||
point.x() = point.attribute("local_x").asDouble().value(); | ||
} | ||
if (point.hasAttribute("local_y")) { | ||
point.y() = point.attribute("local_y").asDouble().value(); | ||
} | ||
} | ||
// realign lanelet borders using updated points | ||
for (lanelet::Lanelet lanelet : map->laneletLayer) { | ||
auto left = lanelet.leftBound(); | ||
auto right = lanelet.rightBound(); | ||
std::tie(left, right) = lanelet::geometry::align(left, right); | ||
lanelet.setLeftBound(left); | ||
lanelet.setRightBound(right); | ||
} | ||
// overwrite centerline | ||
lanelet::utils::overwriteLaneletsCenterline(map, 5.0, false); | ||
// convert map to binary message | ||
{ | ||
const auto map_bin_msg = | ||
Lanelet2MapLoaderNode::create_map_bin_msg(map, lanelet2_paths[0], rclcpp::Clock().now()); | ||
|
||
pub_map_bin_debug_->publish(map_bin_msg); | ||
} // convert map to binary message end | ||
} | ||
|
||
{ | ||
std::vector<std::string> lanelet2_paths; | ||
for (const auto & id : request->osm_file_ids) { | ||
auto it = std::find_if( | ||
lanelet2_file_metadata_dict_.begin(), lanelet2_file_metadata_dict_.end(), | ||
[&id](const auto & file) { return file.second.id == id; }); | ||
if (it == lanelet2_file_metadata_dict_.end()) { | ||
continue; | ||
} | ||
if (!std::filesystem::exists(it->first)) { | ||
continue; | ||
} | ||
lanelet2_paths.push_back(it->first); | ||
} | ||
if (lanelet2_paths.empty()) { | ||
return false; | ||
} | ||
|
||
lanelet::ErrorMessages errors{}; | ||
lanelet::projection::MGRSProjector projector{}; | ||
lanelet::io_handlers::MultiOsmParser parser(projector); | ||
lanelet::LaneletMapPtr map = parser.parse(lanelet2_paths, errors); | ||
|
||
for (lanelet::Point3d point : map->pointLayer) { | ||
if (point.hasAttribute("local_x")) { | ||
point.x() = point.attribute("local_x").asDouble().value(); | ||
} | ||
if (point.hasAttribute("local_y")) { | ||
point.y() = point.attribute("local_y").asDouble().value(); | ||
} | ||
} | ||
// realign lanelet borders using updated points | ||
for (lanelet::Lanelet lanelet : map->laneletLayer) { | ||
auto left = lanelet.leftBound(); | ||
auto right = lanelet.rightBound(); | ||
std::tie(left, right) = lanelet::geometry::align(left, right); | ||
lanelet.setLeftBound(left); | ||
lanelet.setRightBound(right); | ||
} | ||
// overwrite centerline | ||
lanelet::utils::overwriteLaneletsCenterline(map, 5.0, false); | ||
// convert map to binary message | ||
{ | ||
const auto map_bin_msg = | ||
Lanelet2MapLoaderNode::create_map_bin_msg(map, lanelet2_paths[0], rclcpp::Clock().now()); | ||
|
||
pub_map_bin_->publish(map_bin_msg); | ||
response->differential_map = map_bin_msg; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
autoware_map_msgs::msg::LaneletMapMetaData | ||
Lanelet2DifferentialLoaderModule::getLaneletMapMetaDataMsg() const | ||
{ | ||
autoware_map_msgs::msg::LaneletMapMetaData metadata; | ||
for (const auto & file : lanelet2_file_metadata_dict_) { | ||
std::cout << "----------------" << std::endl; | ||
std::cout << file.first << std::endl; | ||
std::cout << file.second.id << std::endl; | ||
|
||
autoware_map_msgs::msg::LaneletMapTileMetaData tile_msg; | ||
tile_msg.mgrs_code = file.second.mgrs_code; | ||
tile_msg.origin_lat = file.second.origin_lat; | ||
tile_msg.origin_lon = file.second.origin_lon; | ||
|
||
autoware_map_msgs::msg::LaneletMapTileMetaDataWithID tile_msg_with_id; | ||
tile_msg_with_id.metadata = tile_msg; | ||
tile_msg_with_id.tile_id = file.second.id; | ||
|
||
metadata.metadata_list.push_back(tile_msg_with_id); | ||
} | ||
metadata.header.frame_id = "map"; | ||
metadata.header.stamp = clock_->now(); | ||
|
||
return metadata; | ||
} |
Oops, something went wrong.