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(geography_utils): add projection in geography_utils #4833

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
49645d8
feat(gnss_poser): Subscribe map_projector_info
kminoda Aug 18, 2023
5cc24be
style(pre-commit): autofix
pre-commit-ci[bot] Aug 18, 2023
36bb470
update readme
kminoda Aug 18, 2023
59bceb5
style(pre-commit): autofix
pre-commit-ci[bot] Aug 18, 2023
d03ba1b
Merge branch 'main' into feat/gnss_poser/subscribe_map_projector_info
kminoda Aug 22, 2023
fd945d3
small fix
kminoda Aug 22, 2023
a87052e
update commetn
kminoda Aug 22, 2023
1e8baec
style(pre-commit): autofix
pre-commit-ci[bot] Aug 22, 2023
cd1cc72
add local cartesian
kminoda Aug 22, 2023
0c9cf23
update launch file
kminoda Aug 22, 2023
513d80d
update
kminoda Aug 29, 2023
f0f9bb3
style(pre-commit): autofix
pre-commit-ci[bot] Aug 29, 2023
8b53bbc
fix
kminoda Aug 29, 2023
9a7655b
create new function for conversion of height
kminoda Aug 29, 2023
2fb5d4e
minor update
kminoda Aug 29, 2023
bd5f31c
style(pre-commit): autofix
pre-commit-ci[bot] Aug 29, 2023
5113d16
update
kminoda Aug 29, 2023
2d7c420
Merge branch 'main' into feat/gnss_poser/subscribe_map_projector_info
kminoda Aug 29, 2023
562c1b5
Merge branch 'main' into feat/gnss_poser/subscribe_map_projector_info
kminoda Aug 30, 2023
8b6bca0
rename
kminoda Aug 30, 2023
8a5c2b8
remove unnecessary include
kminoda Aug 30, 2023
3363af0
add projection in geography_utils
kminoda Aug 31, 2023
98c5df3
Merge remote-tracking branch 'origin' into feat/gnss_poser/use_lanele…
kminoda Aug 31, 2023
cd3771e
update projection.cpp
kminoda Aug 31, 2023
4c51b73
use projection in default_ad_api
kminoda Aug 31, 2023
13356fe
style(pre-commit): autofix
pre-commit-ci[bot] Aug 31, 2023
fe4ec41
Feat/gnss poser/subscribe map projector info (#24)
kminoda Sep 1, 2023
0bbba34
use projection.cpp in gnss_poser
kminoda Sep 1, 2023
f6a4b3b
style(pre-commit): autofix
pre-commit-ci[bot] Sep 1, 2023
a9a59e4
remove unnecessary files
kminoda Sep 1, 2023
eb57761
remove unnecessary parts
kminoda Sep 1, 2023
ffb17f9
remove lanelet2 dependency from default_ad_api
kminoda Sep 1, 2023
051517e
remove geography_utils.hpp
kminoda Sep 1, 2023
2b1eec3
add get_lanelet2_projector and use that in whole system
kminoda Sep 1, 2023
1596e7b
style(pre-commit): autofix
pre-commit-ci[bot] Sep 1, 2023
bded3ba
remove unnecessary parts
kminoda Sep 1, 2023
cad1da5
revert using Point
kminoda Sep 1, 2023
8b1b03b
style(pre-commit): autofix
pre-commit-ci[bot] Sep 1, 2023
a1b2055
resolve conflict
kminoda Sep 1, 2023
34b5235
remove unnecessary files
kminoda Sep 1, 2023
a50be5a
Merge branch 'main' into feat/gnss_poser/use_lanelet2_projector
kminoda Sep 4, 2023
4fb44b6
update test
kminoda Sep 4, 2023
7dd3fc9
update comment
kminoda Sep 4, 2023
f6ec88e
style(pre-commit): autofix
pre-commit-ci[bot] Sep 4, 2023
21e0765
style(pre-commit): autofix
pre-commit-ci[bot] Sep 4, 2023
095e27d
use constant string instead
kminoda Sep 4, 2023
b011a47
Merge branch 'main' into feat/gnss_poser/use_lanelet2_projector
kminoda Sep 4, 2023
efbe26e
use reference
kminoda Sep 4, 2023
4cedde7
fix test name
kminoda Sep 4, 2023
2097712
Merge branch 'main' into feat/gnss_poser/use_lanelet2_projector
YamatoAndo Sep 4, 2023
34273a8
fix bug
kminoda Sep 4, 2023
a952c87
Merge branch 'main' into feat/gnss_poser/use_lanelet2_projector
kminoda Sep 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/geography_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ find_library(GeographicLib_LIBRARIES NAMES Geographic)

ament_auto_add_library(geography_utils SHARED
src/height.cpp
src/projection.cpp
src/lanelet2_projector.cpp
)

Expand Down
3 changes: 0 additions & 3 deletions common/geography_utils/include/geography_utils/height.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
#ifndef GEOGRAPHY_UTILS__HEIGHT_HPP_
#define GEOGRAPHY_UTILS__HEIGHT_HPP_

#include <map>
#include <stdexcept>
#include <string>
#include <utility>

namespace geography_utils
{
Expand Down
33 changes: 33 additions & 0 deletions common/geography_utils/include/geography_utils/projection.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2023 TIER IV, Inc.
//
// 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 GEOGRAPHY_UTILS__PROJECTION_HPP_
#define GEOGRAPHY_UTILS__PROJECTION_HPP_

#include <geographic_msgs/msg/geo_point.hpp>
#include <geometry_msgs/msg/point.hpp>
#include <tier4_map_msgs/msg/map_projector_info.hpp>

namespace geography_utils
{
using MapProjectorInfo = tier4_map_msgs::msg::MapProjectorInfo;
using GeoPoint = geographic_msgs::msg::GeoPoint;
using LocalPoint = geometry_msgs::msg::Point;

LocalPoint project_forward(const GeoPoint & geo_point, const MapProjectorInfo & projector_info);
GeoPoint project_reverse(const LocalPoint & local_point, const MapProjectorInfo & projector_info);

} // namespace geography_utils

#endif // GEOGRAPHY_UTILS__PROJECTION_HPP_
2 changes: 2 additions & 0 deletions common/geography_utils/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>geographic_msgs</depend>
<depend>geographiclib</depend>
<depend>geometry_msgs</depend>
<depend>lanelet2_extension</depend>
<depend>lanelet2_io</depend>
<depend>tier4_map_msgs</depend>
Expand Down
95 changes: 95 additions & 0 deletions common/geography_utils/src/projection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2023 TIER IV, Inc.
//
// 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 <GeographicLib/Geoid.hpp>
#include <geography_utils/lanelet2_projector.hpp>
#include <geography_utils/projection.hpp>
#include <lanelet2_extension/projection/mgrs_projector.hpp>
kminoda marked this conversation as resolved.
Show resolved Hide resolved

namespace geography_utils
{

Eigen::Vector3d to_basic_point_3d_pt(const LocalPoint src)
{
Eigen::Vector3d dst;
dst.x() = src.x;
dst.y() = src.y;
dst.z() = src.z;
return dst;
}

LocalPoint project_forward(const GeoPoint & geo_point, const MapProjectorInfo & projector_info)
{
std::unique_ptr<lanelet::Projector> projector = get_lanelet2_projector(projector_info);
lanelet::GPSPoint position{geo_point.latitude, geo_point.longitude, geo_point.altitude};

lanelet::BasicPoint3d projected_local_point;
if (projector_info.projector_type == MapProjectorInfo::MGRS) {
const int mgrs_precision = 9; // set precision as 100 micro meter
const auto mgrs_projector = dynamic_cast<lanelet::projection::MGRSProjector *>(projector.get());

// project x and y using projector
// note that the altitude is ignored in MGRS projection conventionally
projected_local_point = mgrs_projector->forward(position, mgrs_precision);
} else {
// project x and y using projector
// note that the original projector such as UTM projector does not compensate for the altitude
// offset
projected_local_point = projector->forward(position);

// correct z based on the map origin
// note that the converted altitude in local point is in the same vertical datum as the geo
// point
projected_local_point.z() = geo_point.altitude - projector_info.map_origin.altitude;
}

LocalPoint local_point;
local_point.x = projected_local_point.x();
local_point.y = projected_local_point.y();
local_point.z = projected_local_point.z();

return local_point;
}

GeoPoint project_reverse(const LocalPoint & local_point, const MapProjectorInfo & projector_info)
{
std::unique_ptr<lanelet::Projector> projector = get_lanelet2_projector(projector_info);

lanelet::GPSPoint projected_gps_point;
if (projector_info.projector_type == MapProjectorInfo::MGRS) {
const auto mgrs_projector = dynamic_cast<lanelet::projection::MGRSProjector *>(projector.get());
// project latitude and longitude using projector
// note that the z is ignored in MGRS projection conventionally
projected_gps_point =
mgrs_projector->reverse(to_basic_point_3d_pt(local_point), projector_info.mgrs_grid);
} else {
// project latitude and longitude using projector
// note that the original projector such as UTM projector does not compensate for the altitude
// offset
projected_gps_point = projector->reverse(to_basic_point_3d_pt(local_point));

// correct altitude based on the map origin
// note that the converted altitude in local point is in the same vertical datum as the geo
// point
projected_gps_point.ele = local_point.z + projector_info.map_origin.altitude;
}

GeoPoint geo_point;
geo_point.latitude = projected_gps_point.lat;
geo_point.longitude = projected_gps_point.lon;
geo_point.altitude = projected_gps_point.ele;
return geo_point;
}

} // namespace geography_utils
kminoda marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tier IV, Inc.
// Copyright 2023 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -11,38 +11,16 @@
// 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 GNSS_POSER__GNSS_STAT_HPP_
#define GNSS_POSER__GNSS_STAT_HPP_

#include <string>
#include "geography_utils/height.hpp"
#include "geography_utils/lanelet2_projector.hpp"
#include "geography_utils/projection.hpp"

kminoda marked this conversation as resolved.
Show resolved Hide resolved
namespace gnss_poser
{
struct GNSSStat
{
GNSSStat()
: east_north_up(true),
zone(0),
mgrs_zone(""),
x(0),
y(0),
z(0),
latitude(0),
longitude(0),
altitude(0)
{
}
#include <gtest/gtest.h>

bool east_north_up;
int zone;
std::string mgrs_zone;
double x;
double y;
double z;
double latitude;
double longitude;
double altitude;
};
} // namespace gnss_poser

#endif // GNSS_POSER__GNSS_STAT_HPP_
int main(int argc, char * argv[])
{
testing::InitGoogleTest(&argc, argv);
bool result = RUN_ALL_TESTS();
return result;
}
kminoda marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 5 additions & 11 deletions common/geography_utils/test/test_height.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <string>

// Test case to verify if same source and target datums return original height
TEST(Tier4GeographyUtils, SameSourceTargetDatum)
TEST(GeographyUtils, SameSourceTargetDatum)
{
const double height = 10.0;
const double latitude = 35.0;
Expand All @@ -34,7 +34,7 @@ TEST(Tier4GeographyUtils, SameSourceTargetDatum)
}

// Test case to verify valid source and target datums
TEST(Tier4GeographyUtils, ValidSourceTargetDatum)
TEST(GeographyUtils, ValidSourceTargetDatum)
{
// Calculated with
// https://www.unavco.org/software/geodetic-utilities/geoid-height-calculator/geoid-height-calculator.html
Expand All @@ -50,7 +50,7 @@ TEST(Tier4GeographyUtils, ValidSourceTargetDatum)
}

// Test case to verify invalid source and target datums
TEST(Tier4GeographyUtils, InvalidSourceTargetDatum)
TEST(GeographyUtils, InvalidSourceTargetDatum)
{
const double height = 10.0;
const double latitude = 35.0;
Expand All @@ -62,7 +62,7 @@ TEST(Tier4GeographyUtils, InvalidSourceTargetDatum)
}

// Test case to verify invalid source datums
TEST(Tier4GeographyUtils, InvalidSourceDatum)
TEST(GeographyUtils, InvalidSourceDatum)
{
const double height = 10.0;
const double latitude = 35.0;
Expand All @@ -74,7 +74,7 @@ TEST(Tier4GeographyUtils, InvalidSourceDatum)
}

// Test case to verify invalid target datums
TEST(Tier4GeographyUtils, InvalidTargetDatum)
TEST(GeographyUtils, InvalidTargetDatum)
{
const double height = 10.0;
const double latitude = 35.0;
Expand All @@ -84,9 +84,3 @@ TEST(Tier4GeographyUtils, InvalidTargetDatum)
geography_utils::convert_height(height, latitude, longitude, "WGS84", "INVALID2"),
std::invalid_argument);
}

int main(int argc, char ** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Loading
Loading