Skip to content

Commit

Permalink
refactor(map_projection_loader): make important part a library (#5992)
Browse files Browse the repository at this point in the history
* refactor(map_projection_loader): make important part a library

Signed-off-by: kminoda <[email protected]>

* style(pre-commit): autofix

* fix: add const

Signed-off-by: kminoda <[email protected]>

* fix: fix function arguments

Signed-off-by: kminoda <[email protected]>

* style(pre-commit): autofix

---------

Signed-off-by: kminoda <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
kminoda and pre-commit-ci[bot] authored Jan 9, 2024
1 parent 599aea0 commit f693b04
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <string>

tier4_map_msgs::msg::MapProjectorInfo load_info_from_yaml(const std::string & filename);
tier4_map_msgs::msg::MapProjectorInfo load_map_projector_info(
const std::string & yaml_filename, const std::string & lanelet2_map_filename);

class MapProjectionLoader : public rclcpp::Node
{
Expand Down
45 changes: 29 additions & 16 deletions map/map_projection_loader/src/map_projection_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <yaml-cpp/yaml.h>

#include <filesystem>
#include <fstream>

tier4_map_msgs::msg::MapProjectorInfo load_info_from_yaml(const std::string & filename)
Expand Down Expand Up @@ -55,28 +56,40 @@ tier4_map_msgs::msg::MapProjectorInfo load_info_from_yaml(const std::string & fi
return msg;
}

MapProjectionLoader::MapProjectionLoader() : Node("map_projection_loader")
tier4_map_msgs::msg::MapProjectorInfo load_map_projector_info(
const std::string & yaml_filename, const std::string & lanelet2_map_filename)
{
std::string yaml_filename = this->declare_parameter<std::string>("map_projector_info_path");
std::string lanelet2_map_filename = this->declare_parameter<std::string>("lanelet2_map_path");
std::ifstream file(yaml_filename);

tier4_map_msgs::msg::MapProjectorInfo msg;

bool use_yaml_file = file.is_open();
if (use_yaml_file) {
RCLCPP_INFO(this->get_logger(), "Load %s", yaml_filename.c_str());
if (std::filesystem::exists(yaml_filename)) {
std::cout << "Load " << yaml_filename << std::endl;
msg = load_info_from_yaml(yaml_filename);
} else {
RCLCPP_INFO(this->get_logger(), "Load %s", lanelet2_map_filename.c_str());
RCLCPP_WARN(
this->get_logger(),
"DEPRECATED WARNING: Loading map projection info from lanelet2 map may soon be deleted. "
"Please use map_projector_info.yaml instead. For more info, visit "
"https://github.com/autowarefoundation/autoware.universe/blob/main/map/map_projection_loader/"
"README.md");
} else if (std::filesystem::exists(lanelet2_map_filename)) {
std::cout << "Load " << lanelet2_map_filename << std::endl;
std::cout
<< "DEPRECATED WARNING: Loading map projection info from lanelet2 map may soon be deleted. "
"Please use map_projector_info.yaml instead. For more info, visit "
"https://github.com/autowarefoundation/autoware.universe/blob/main/map/"
"map_projection_loader/"
"README.md"
<< std::endl;
msg = load_info_from_lanelet2_map(lanelet2_map_filename);
} else {
throw std::runtime_error(
"No map projector info files found. Please provide either "
"map_projector_info.yaml or lanelet2_map.osm");
}
return msg;
}

MapProjectionLoader::MapProjectionLoader() : Node("map_projection_loader")
{
const std::string yaml_filename = this->declare_parameter<std::string>("map_projector_info_path");
const std::string lanelet2_map_filename =
this->declare_parameter<std::string>("lanelet2_map_path");

const tier4_map_msgs::msg::MapProjectorInfo msg =
load_map_projector_info(yaml_filename, lanelet2_map_filename);

// Publish the message
const auto adaptor = component_interface_utils::NodeAdaptor(this);
Expand Down

0 comments on commit f693b04

Please sign in to comment.