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(lanelet2_extension)!: remove dependency on autoware_utils #47

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions autoware_lanelet2_extension/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ cmake_minimum_required(VERSION 3.14)
project(autoware_lanelet2_extension)

find_package(autoware_cmake REQUIRED)

find_package(TinyXML2 CONFIG QUIET)
if(NOT TinyXML2_FOUND)
find_path(TINYXML2_INCLUDE_DIR NAMES tinyxml2.h)
find_library(TINYXML2_LIBRARY tinyxml2)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(TinyXML2 DEFAULT_MSG TINYXML2_LIBRARY TINYXML2_INCLUDE_DIR)
mark_as_advanced(TINYXML2_INCLUDE_DIR TINYXML2_LIBRARY)
if(NOT TARGET tinyxml2::tinyxml2)
add_library(tinyxml2::tinyxml2 UNKNOWN IMPORTED)
set_property(TARGET tinyxml2::tinyxml2 PROPERTY IMPORTED_LOCATION ${TINYXML2_LIBRARY})
set_property(TARGET tinyxml2::tinyxml2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${TINYXML2_INCLUDE_DIR})
list(APPEND TinyXML2_TARGETS tinyxml2::tinyxml2)
endif()
endif()

autoware_package()

ament_auto_add_library(${PROJECT_NAME}_lib SHARED
Expand Down Expand Up @@ -53,6 +69,8 @@ if(BUILD_TESTING)
target_link_libraries(utilities-test ${PROJECT_NAME}_lib)
ament_add_ros_isolated_gtest(route-test test/src/test_route_checker.cpp)
target_link_libraries(route-test ${PROJECT_NAME}_lib)
ament_add_ros_isolated_gtest(normalize-radian test/src/test_normalize_radian.cpp)
target_link_libraries(normalize-radian ${PROJECT_NAME}_lib)
endif()

ament_auto_package()
38 changes: 38 additions & 0 deletions autoware_lanelet2_extension/lib/normalize_radian.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2025 Autoware Foundation
//
// 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 <cmath>
#include <utility>

#ifndef AUTOWARE_LANELET2_EXTENSION__LIB__NORMALIZE_RADIAN_HPP_
#define AUTOWARE_LANELET2_EXTENSION__LIB__NORMALIZE_RADIAN_HPP_

namespace lanelet::utils::impl
{
inline double normalize_radian(const double rad)
{
constexpr double pi = 3.14159265358979323846; // To be replaced by std::numbers::pi in C++20
constexpr double min_rad = -pi;
const auto max_rad = min_rad + 2 * pi;

const auto value = std::fmod(rad, 2 * pi);
if (min_rad <= value && value < max_rad) {
return value;
}

return value - std::copysign(2 * pi, value);
}
} // namespace lanelet::utils::impl

#endif // AUTOWARE_LANELET2_EXTENSION__LIB__NORMALIZE_RADIAN_HPP_
9 changes: 4 additions & 5 deletions autoware_lanelet2_extension/lib/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
#include "autoware_lanelet2_extension/utility/message_conversion.hpp"
#include "autoware_lanelet2_extension/utility/utilities.hpp"

#include <Eigen/Eigen>
#include <autoware_utils/autoware_utils.hpp>

#include <lanelet2_core/LaneletMap.h>
#include <lanelet2_core/geometry/Lanelet.h>
#include <lanelet2_core/primitives/Lanelet.h>
Expand All @@ -45,6 +42,8 @@
#include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
#endif

#include "./normalize_radian.hpp"

#include <deque>
#include <limits>
#include <memory>
Expand Down Expand Up @@ -934,7 +933,7 @@ bool query::getClosestLanelet(
if (!segment.empty()) {
double segment_angle = std::atan2(
segment.back().y() - segment.front().y(), segment.back().x() - segment.front().x());
angle_diff = std::abs(autoware_utils::normalize_radian(segment_angle - pose_yaw));
angle_diff = std::abs(impl::normalize_radian(segment_angle - pose_yaw));
}
if (angle_diff < min_angle) {
min_angle = angle_diff;
Expand Down Expand Up @@ -996,7 +995,7 @@ bool query::getClosestLaneletWithConstrains(
const auto & distance = llt_pair.second;

double lanelet_angle = getLaneletAngle(llt_pair.first, search_pose.position);
double angle_diff = std::abs(autoware_utils::normalize_radian(lanelet_angle - pose_yaw));
double angle_diff = std::abs(impl::normalize_radian(lanelet_angle - pose_yaw));

if (angle_diff > std::abs(yaw_threshold)) continue;
if (min_distance < distance) break;
Expand Down
2 changes: 1 addition & 1 deletion autoware_lanelet2_extension/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

<depend>autoware_map_msgs</depend>
<depend>autoware_planning_msgs</depend>
<depend>autoware_utils</depend>
<depend>geographiclib</depend>
<depend>geometry_msgs</depend>
<depend>lanelet2_core</depend>
Expand All @@ -32,6 +31,7 @@
<depend>rclcpp</depend>
<depend>tf2</depend>
<depend>tf2_geometry_msgs</depend>
<depend>tinyxml2_vendor</depend>
<depend>visualization_msgs</depend>

<test_depend>ament_cmake_ros</test_depend>
Expand Down
32 changes: 32 additions & 0 deletions autoware_lanelet2_extension/test/src/test_normalize_radian.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2025 Autoware Foundation
//
// 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.

// NOLINTBEGIN(readability-identifier-naming)

#include "../../lib/normalize_radian.hpp"

#include <gtest/gtest.h>

TEST(normalize_radian, normalize_radian_test)
{
EXPECT_FLOAT_EQ(lanelet::utils::impl::normalize_radian(M_PI * 1.5), M_PI * (-0.5));
}

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

// NOLINTEND(readability-identifier-naming)
Loading