From 366b6dedfd95acbc4f4fdb40f1a42dfe48cc12aa Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 6 Aug 2024 13:10:11 +0000 Subject: [PATCH] Switch nav2_graceful_controller to modern CMake idioms. Signed-off-by: Chris Lalancette --- nav2_graceful_controller/CMakeLists.txt | 95 +++++++++++++------ .../ego_polar_coords.hpp | 4 +- nav2_graceful_controller/package.xml | 19 ++-- .../src/graceful_controller.cpp | 3 + nav2_graceful_controller/test/CMakeLists.txt | 20 ++-- 5 files changed, 94 insertions(+), 47 deletions(-) diff --git a/nav2_graceful_controller/CMakeLists.txt b/nav2_graceful_controller/CMakeLists.txt index 9cec5b9204..e79ea8d01f 100644 --- a/nav2_graceful_controller/CMakeLists.txt +++ b/nav2_graceful_controller/CMakeLists.txt @@ -2,44 +2,38 @@ cmake_minimum_required(VERSION 3.5) project(nav2_graceful_controller) find_package(ament_cmake REQUIRED) +find_package(angles REQUIRED) +find_package(geometry_msgs REQUIRED) find_package(nav2_common REQUIRED) find_package(nav2_core REQUIRED) find_package(nav2_costmap_2d REQUIRED) find_package(nav2_util REQUIRED) -find_package(rclcpp REQUIRED) -find_package(geometry_msgs REQUIRED) +find_package(nav_2d_utils REQUIRED) find_package(nav_msgs REQUIRED) find_package(pluginlib REQUIRED) +find_package(rclcpp REQUIRED) +find_package(rclcpp_lifecycle REQUIRED) +find_package(rcl_interfaces REQUIRED) find_package(tf2 REQUIRED) find_package(tf2_geometry_msgs REQUIRED) -find_package(nav_2d_utils REQUIRED) -find_package(angles REQUIRED) +find_package(tf2_ros REQUIRED) find_package(visualization_msgs REQUIRED) nav2_package() -include_directories( - include -) - -set(dependencies - rclcpp - geometry_msgs - nav2_costmap_2d - pluginlib - nav_msgs - nav2_util - nav2_core - tf2 - tf2_geometry_msgs - nav_2d_utils - angles - visualization_msgs -) - # Add Smooth Control Law as library add_library(smooth_control_law SHARED src/smooth_control_law.cpp) -ament_target_dependencies(smooth_control_law ${dependencies}) +target_include_directories(smooth_control_law + PUBLIC + "$" + "$" +) +target_link_libraries(smooth_control_law PUBLIC + angles::angles + ${geometry_msgs_TARGETS} + nav2_util::nav2_util_core + tf2::tf2 +) # Add Graceful Controller set(library_name nav2_graceful_controller) @@ -50,18 +44,40 @@ add_library(${library_name} SHARED src/path_handler.cpp src/utils.cpp ) - -target_link_libraries(${library_name} smooth_control_law) -ament_target_dependencies(${library_name} ${dependencies}) +target_include_directories(${library_name} + PUBLIC + "$" + "$" +) +target_link_libraries(${library_name} PUBLIC + ${geometry_msgs_TARGETS} + nav2_core::nav2_core + nav2_util::nav2_util_core + nav2_costmap_2d::nav2_costmap_2d_core + nav_2d_utils::tf_help + ${nav_msgs_TARGETS} + pluginlib::pluginlib + rclcpp::rclcpp + rclcpp_lifecycle::rclcpp_lifecycle + ${rcl_interfaces_TARGETS} + smooth_control_law + tf2::tf2 + tf2_ros::tf2_ros + ${visualization_msgs_TARGETS} +) +target_link_libraries(${library_name} PRIVATE + tf2_geometry_msgs::tf2_geometry_msgs +) install(TARGETS smooth_control_law ${library_name} + EXPORT nav2_graceful_controller ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin ) install(DIRECTORY include/ - DESTINATION include/ + DESTINATION include/${PROJECT_NAME} ) if(BUILD_TESTING) @@ -70,12 +86,31 @@ if(BUILD_TESTING) # the following line skips the linter which checks for copyrights set(ament_cmake_copyright_FOUND TRUE) ament_lint_auto_find_test_dependencies() + + find_package(ament_cmake_gtest REQUIRED) + ament_find_gtest() + add_subdirectory(test) endif() -ament_export_include_directories(include) +ament_export_include_directories(include/${PROJECT_NAME}) ament_export_libraries(smooth_control_law ${library_name}) -ament_export_dependencies(${dependencies}) +ament_export_dependencies( + geometry_msgs + nav2_core + nav2_util + nav2_costmap_2d + nav_2d_utils + nav_msgs + pluginlib + rclcpp + rclcpp_lifecycle + rcl_interfaces + tf2 + tf2_ros + visualization_msgs +) +ament_export_targets(nav2_graceful_controller) pluginlib_export_plugin_description_file(nav2_core graceful_controller_plugin.xml) diff --git a/nav2_graceful_controller/include/nav2_graceful_controller/ego_polar_coords.hpp b/nav2_graceful_controller/include/nav2_graceful_controller/ego_polar_coords.hpp index eadf608844..f0f1229a10 100644 --- a/nav2_graceful_controller/include/nav2_graceful_controller/ego_polar_coords.hpp +++ b/nav2_graceful_controller/include/nav2_graceful_controller/ego_polar_coords.hpp @@ -15,13 +15,11 @@ #ifndef NAV2_GRACEFUL_CONTROLLER__EGO_POLAR_COORDS_HPP_ #define NAV2_GRACEFUL_CONTROLLER__EGO_POLAR_COORDS_HPP_ -#include +#include #include "angles/angles.h" #include "geometry_msgs/msg/pose.hpp" #include "tf2/utils.h" -#include "tf2/transform_datatypes.h" -#include "tf2_geometry_msgs/tf2_geometry_msgs.hpp" namespace nav2_graceful_controller { diff --git a/nav2_graceful_controller/package.xml b/nav2_graceful_controller/package.xml index b6deb17b72..b45196dcf5 100644 --- a/nav2_graceful_controller/package.xml +++ b/nav2_graceful_controller/package.xml @@ -8,24 +8,27 @@ Apache-2.0 ament_cmake + nav2_common - nav2_common + angles + geometry_msgs nav2_core - nav2_util nav2_costmap_2d - rclcpp - geometry_msgs - nav2_msgs + nav2_util + nav_2d_utils + nav_msgs pluginlib + rclcpp + rclcpp_lifecycle + rcl_interfaces tf2 tf2_geometry_msgs - nav_2d_utils - angles + tf2_ros visualization_msgs + ament_cmake_gtest ament_lint_auto ament_lint_common - ament_cmake_gtest nav2_controller diff --git a/nav2_graceful_controller/src/graceful_controller.cpp b/nav2_graceful_controller/src/graceful_controller.cpp index f8610a55c9..b442ede1fe 100644 --- a/nav2_graceful_controller/src/graceful_controller.cpp +++ b/nav2_graceful_controller/src/graceful_controller.cpp @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include +#include + #include "nav2_core/controller_exceptions.hpp" #include "nav2_util/geometry_utils.hpp" #include "nav2_graceful_controller/graceful_controller.hpp" diff --git a/nav2_graceful_controller/test/CMakeLists.txt b/nav2_graceful_controller/test/CMakeLists.txt index 1becbba0b1..d78b32e594 100644 --- a/nav2_graceful_controller/test/CMakeLists.txt +++ b/nav2_graceful_controller/test/CMakeLists.txt @@ -4,18 +4,26 @@ find_package(nav2_controller REQUIRED) ament_add_gtest(test_graceful_controller test_graceful_controller.cpp ) -ament_target_dependencies(test_graceful_controller - ${dependencies} - nav2_controller -) target_link_libraries(test_graceful_controller ${library_name} + ${geometry_msgs_TARGETS} + nav2_controller::simple_goal_checker + nav2_core::nav2_core + nav2_costmap_2d::nav2_costmap_2d_core + nav2_util::nav2_util_core + ${nav_msgs_TARGETS} + rclcpp::rclcpp + tf2_ros::tf2_ros + ${visualization_msgs_TARGETS} ) # Egopolar test ament_add_gtest(test_egopolar test_egopolar.cpp ) -ament_target_dependencies(test_egopolar - geometry_msgs tf2_geometry_msgs angles +target_link_libraries(test_egopolar + ${library_name} + ${geometry_msgs_TARGETS} + rclcpp::rclcpp + tf2_geometry_msgs::tf2_geometry_msgs )