Skip to content

Commit b6c4765

Browse files
kminodapre-commit-ci[bot]
authored andcommitted
refactor(map_projection_loader): make important part a library (autowarefoundation#5992)
* refactor(map_projection_loader): make important part a library Signed-off-by: kminoda <koji.minoda@tier4.jp> * style(pre-commit): autofix * fix: add const Signed-off-by: kminoda <koji.minoda@tier4.jp> * fix: fix function arguments Signed-off-by: kminoda <koji.minoda@tier4.jp> * style(pre-commit): autofix --------- Signed-off-by: kminoda <koji.minoda@tier4.jp> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 00aab65 commit b6c4765

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

map/map_projection_loader/include/map_projection_loader/map_projection_loader.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <string>
2424

2525
tier4_map_msgs::msg::MapProjectorInfo load_info_from_yaml(const std::string & filename);
26+
tier4_map_msgs::msg::MapProjectorInfo load_map_projector_info(
27+
const std::string & yaml_filename, const std::string & lanelet2_map_filename);
2628

2729
class MapProjectionLoader : public rclcpp::Node
2830
{

map/map_projection_loader/src/map_projection_loader.cpp

+29-16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <yaml-cpp/yaml.h>
2222

23+
#include <filesystem>
2324
#include <fstream>
2425

2526
tier4_map_msgs::msg::MapProjectorInfo load_info_from_yaml(const std::string & filename)
@@ -55,28 +56,40 @@ tier4_map_msgs::msg::MapProjectorInfo load_info_from_yaml(const std::string & fi
5556
return msg;
5657
}
5758

58-
MapProjectionLoader::MapProjectionLoader() : Node("map_projection_loader")
59+
tier4_map_msgs::msg::MapProjectorInfo load_map_projector_info(
60+
const std::string & yaml_filename, const std::string & lanelet2_map_filename)
5961
{
60-
std::string yaml_filename = this->declare_parameter<std::string>("map_projector_info_path");
61-
std::string lanelet2_map_filename = this->declare_parameter<std::string>("lanelet2_map_path");
62-
std::ifstream file(yaml_filename);
63-
6462
tier4_map_msgs::msg::MapProjectorInfo msg;
6563

66-
bool use_yaml_file = file.is_open();
67-
if (use_yaml_file) {
68-
RCLCPP_INFO(this->get_logger(), "Load %s", yaml_filename.c_str());
64+
if (std::filesystem::exists(yaml_filename)) {
65+
std::cout << "Load " << yaml_filename << std::endl;
6966
msg = load_info_from_yaml(yaml_filename);
70-
} else {
71-
RCLCPP_INFO(this->get_logger(), "Load %s", lanelet2_map_filename.c_str());
72-
RCLCPP_WARN(
73-
this->get_logger(),
74-
"DEPRECATED WARNING: Loading map projection info from lanelet2 map may soon be deleted. "
75-
"Please use map_projector_info.yaml instead. For more info, visit "
76-
"https://github.com/autowarefoundation/autoware.universe/blob/main/map/map_projection_loader/"
77-
"README.md");
67+
} else if (std::filesystem::exists(lanelet2_map_filename)) {
68+
std::cout << "Load " << lanelet2_map_filename << std::endl;
69+
std::cout
70+
<< "DEPRECATED WARNING: Loading map projection info from lanelet2 map may soon be deleted. "
71+
"Please use map_projector_info.yaml instead. For more info, visit "
72+
"https://github.com/autowarefoundation/autoware.universe/blob/main/map/"
73+
"map_projection_loader/"
74+
"README.md"
75+
<< std::endl;
7876
msg = load_info_from_lanelet2_map(lanelet2_map_filename);
77+
} else {
78+
throw std::runtime_error(
79+
"No map projector info files found. Please provide either "
80+
"map_projector_info.yaml or lanelet2_map.osm");
7981
}
82+
return msg;
83+
}
84+
85+
MapProjectionLoader::MapProjectionLoader() : Node("map_projection_loader")
86+
{
87+
const std::string yaml_filename = this->declare_parameter<std::string>("map_projector_info_path");
88+
const std::string lanelet2_map_filename =
89+
this->declare_parameter<std::string>("lanelet2_map_path");
90+
91+
const tier4_map_msgs::msg::MapProjectorInfo msg =
92+
load_map_projector_info(yaml_filename, lanelet2_map_filename);
8093

8194
// Publish the message
8295
const auto adaptor = component_interface_utils::NodeAdaptor(this);

0 commit comments

Comments
 (0)