Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(map_projection_loader): add backward compatibility for local map #4586

18 changes: 16 additions & 2 deletions map/map_projection_loader/src/load_info_from_lanelet2_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,22 @@ tier4_map_msgs::msg::MapProjectorInfo load_info_from_lanelet2_map(const std::str
throw std::runtime_error("Error occurred while loading lanelet2 map");
}

// Check if the map (lat, lon) is zero
kminoda marked this conversation as resolved.
Show resolved Hide resolved
bool is_local = true;
for (const auto & point : map->pointLayer) {
const auto gps_point = projector.reverse(point);
if (gps_point.lat != 0.0 || gps_point.lon != 0.0) {
is_local = false;
break;
}
}

tier4_map_msgs::msg::MapProjectorInfo msg;
msg.type = "MGRS";
msg.mgrs_grid = projector.getProjectedMGRSGrid();
if (is_local) {
msg.type = "local";
} else {
msg.type = "MGRS";
msg.mgrs_grid = projector.getProjectedMGRSGrid();
}
return msg;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <fstream>

void save_dummy_lanelet2_map(const std::string & mgrs_coord, const std::string & output_path)
void save_dummy_mgrs_lanelet2_map(const std::string & mgrs_coord, const std::string & output_path)
{
int zone = std::stoi(mgrs_coord.substr(0, 2));
bool is_north = false;
Expand All @@ -39,6 +39,10 @@ void save_dummy_lanelet2_map(const std::string & mgrs_coord, const std::string &
return;
}

// <?xml version="1.0"?>
// <osm version="0.6" generator="lanelet2">
// <node id="1" lat="LATITUDE" lon="LONGITUDE"/>
// </osm>⏎
file << "<?xml version=\"1.0\"?>\n";
file << "<osm version=\"0.6\" generator=\"lanelet2\">\n";
file << " <node id=\"1\" lat=\"" << lat << "\" lon=\"" << lon << "\"/>\n";
Expand All @@ -47,13 +51,37 @@ void save_dummy_lanelet2_map(const std::string & mgrs_coord, const std::string &
file.close();
}

void save_dummy_local_lanelet2_map(const std::string & output_path)
{
std::ofstream file(output_path);
if (!file) {
std::cerr << "Unable to open file.\n";
return;
}

// <?xml version="1.0"?>
// <osm version="0.6" generator="lanelet2">
// <node id="1" lat="" lon=""/>
// <node id="2" lat="" lon=""/>
// <node id="3" lat="" lon=""/>
// </osm>⏎
file << "<?xml version=\"1.0\"?>\n";
file << "<osm version=\"0.6\" generator=\"lanelet2\">\n";
file << " <node id=\"1\" lat=\"\" lon=\"\"/>\n";
file << " <node id=\"2\" lat=\"\" lon=\"\"/>\n";
file << " <node id=\"3\" lat=\"\" lon=\"\"/>\n";
file << "</osm>";

file.close();
}

TEST(TestLoadFromLanelet2Map, LoadMGRSGrid)
{
// Save dummy lanelet2 map
const std::string mgrs_grid = "54SUE";
const std::string mgrs_coord = mgrs_grid + "1000010000";
const std::string output_path = "/tmp/test_load_info_from_lanelet2_map.osm";
save_dummy_lanelet2_map(mgrs_coord, output_path);
save_dummy_mgrs_lanelet2_map(mgrs_coord, output_path);

// Test the function
const auto projector_info = load_info_from_lanelet2_map(output_path);
Expand All @@ -63,6 +91,19 @@ TEST(TestLoadFromLanelet2Map, LoadMGRSGrid)
EXPECT_EQ(projector_info.mgrs_grid, mgrs_grid);
}

TEST(TestLoadFromLanelet2Map, LoadLocalGrid)
{
// Save dummy lanelet2 map
const std::string output_path = "/tmp/test_load_info_from_lanelet2_map.osm";
save_dummy_local_lanelet2_map(output_path);

// Test the function
const auto projector_info = load_info_from_lanelet2_map(output_path);

// Check the result
EXPECT_EQ(projector_info.type, "local");
}

int main(int argc, char ** argv)
{
::testing::InitGoogleMock(&argc, argv);
Expand Down