|
20 | 20 |
|
21 | 21 | #include <yaml-cpp/yaml.h>
|
22 | 22 |
|
| 23 | +#include <filesystem> |
23 | 24 | #include <fstream>
|
24 | 25 |
|
25 | 26 | 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
|
55 | 56 | return msg;
|
56 | 57 | }
|
57 | 58 |
|
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) |
59 | 61 | {
|
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 |
| - |
64 | 62 | tier4_map_msgs::msg::MapProjectorInfo msg;
|
65 | 63 |
|
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; |
69 | 66 | 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; |
78 | 76 | 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"); |
79 | 81 | }
|
| 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); |
80 | 93 |
|
81 | 94 | // Publish the message
|
82 | 95 | const auto adaptor = component_interface_utils::NodeAdaptor(this);
|
|
0 commit comments