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

Switch nav2_collision_monitor to modern CMake idioms. #4582

Merged
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
141 changes: 81 additions & 60 deletions nav2_collision_monitor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,23 @@
cmake_minimum_required(VERSION 3.5)
project(nav2_collision_monitor)

### Dependencies ###

find_package(ament_cmake REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav2_common REQUIRED)
find_package(nav2_costmap_2d REQUIRED)
find_package(nav2_msgs REQUIRED)
find_package(nav2_util REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)
find_package(nav2_common REQUIRED)
find_package(nav2_util REQUIRED)
find_package(nav2_costmap_2d REQUIRED)
find_package(nav2_msgs REQUIRED)
find_package(visualization_msgs REQUIRED)

### Header ###

nav2_package()

### Libraries and executables ###

include_directories(
include
)

set(dependencies
rclcpp
rclcpp_components
sensor_msgs
geometry_msgs
std_msgs
tf2
tf2_ros
tf2_geometry_msgs
nav2_util
nav2_costmap_2d
nav2_msgs
visualization_msgs
)

set(monitor_executable_name collision_monitor)
set(detector_executable_name collision_detector)
set(monitor_library_name ${monitor_executable_name}_core)
Expand All @@ -60,6 +35,27 @@ add_library(${monitor_library_name} SHARED
src/range.cpp
src/kinematics.cpp
)
target_include_directories(${monitor_library_name}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(${monitor_library_name} PUBLIC
${geometry_msgs_TARGETS}
nav2_costmap_2d::nav2_costmap_2d_client
nav2_costmap_2d::nav2_costmap_2d_core
${nav2_msgs_TARGETS}
nav2_util::nav2_util_core
rclcpp::rclcpp
rclcpp_lifecycle::rclcpp_lifecycle
${sensor_msgs_TARGETS}
tf2::tf2
tf2_ros::tf2_ros
${visualization_msgs_TARGETS}
)
target_link_libraries(${monitor_library_name} PRIVATE
rclcpp_components::component
)

add_library(${detector_library_name} SHARED
src/collision_detector_node.cpp
src/polygon.cpp
Expand All @@ -72,43 +68,57 @@ add_library(${detector_library_name} SHARED
src/range.cpp
src/kinematics.cpp
)

add_executable(${monitor_executable_name}
src/collision_monitor_main.cpp
target_include_directories(${detector_library_name}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(${detector_library_name} PUBLIC
${geometry_msgs_TARGETS}
nav2_costmap_2d::nav2_costmap_2d_client
nav2_costmap_2d::nav2_costmap_2d_core
${nav2_msgs_TARGETS}
nav2_util::nav2_util_core
rclcpp::rclcpp
rclcpp_lifecycle::rclcpp_lifecycle
${sensor_msgs_TARGETS}
tf2_ros::tf2_ros
tf2::tf2
${visualization_msgs_TARGETS}
)
add_executable(${detector_executable_name}
src/collision_detector_main.cpp
target_link_libraries(${detector_library_name} PRIVATE
rclcpp_components::component
)

ament_target_dependencies(${monitor_library_name}
${dependencies}
)
ament_target_dependencies(${detector_library_name}
${dependencies}
add_executable(${monitor_executable_name}
src/collision_monitor_main.cpp
)

target_link_libraries(${monitor_executable_name}
target_include_directories(${monitor_executable_name}
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(${monitor_executable_name} PRIVATE
rclcpp::rclcpp
${monitor_library_name}
)
target_link_libraries(${detector_executable_name}
${detector_library_name}
)

ament_target_dependencies(${monitor_executable_name}
${dependencies}
add_executable(${detector_executable_name}
src/collision_detector_main.cpp
)

ament_target_dependencies(${detector_executable_name}
${dependencies}
target_include_directories(${detector_executable_name}
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(${detector_executable_name} PRIVATE
rclcpp::rclcpp
${detector_library_name}
)

rclcpp_components_register_nodes(${monitor_library_name} "nav2_collision_monitor::CollisionMonitor")

rclcpp_components_register_nodes(${detector_library_name} "nav2_collision_monitor::CollisionDetector")

### Install ###

install(TARGETS ${monitor_library_name} ${detector_library_name}
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
Expand All @@ -119,14 +129,12 @@ install(TARGETS ${monitor_executable_name} ${detector_executable_name}
)

install(DIRECTORY include/
DESTINATION include/
DESTINATION include/${PROJECT_NAME}
)

install(DIRECTORY launch DESTINATION share/${PROJECT_NAME})
install(DIRECTORY params DESTINATION share/${PROJECT_NAME})

### Testing ###

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
Expand All @@ -135,13 +143,26 @@ if(BUILD_TESTING)
ament_lint_auto_find_test_dependencies()

find_package(ament_cmake_gtest REQUIRED)

ament_find_gtest()

add_subdirectory(test)
endif()

### Ament stuff ###

ament_export_include_directories(include)
ament_export_include_directories(include/${PROJECT_NAME})
ament_export_libraries(${monitor_library_name} ${detector_library_name})
ament_export_dependencies(${dependencies})
ament_export_dependencies(
geometry_msgs
nav2_costmap_2d
nav2_msgs
nav2_util
rclcpp
rclcpp_lifecycle
sensor_msgs
tf2
tf2_ros
visualization_msgs
)
ament_export_targets(export_${PROJECT_NAME})

ament_package()
16 changes: 8 additions & 8 deletions nav2_collision_monitor/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
<license>Apache-2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>
<build_depend>nav2_common</build_depend>

<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>tf2</depend>
<depend>tf2_ros</depend>
<depend>tf2_geometry_msgs</depend>
<depend>sensor_msgs</depend>
<depend>geometry_msgs</depend>
<depend>std_msgs</depend>
<depend>nav2_common</depend>
<depend>nav2_util</depend>
<depend>nav2_costmap_2d</depend>
<depend>nav2_msgs</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>rclcpp_lifecycle</depend>
<depend>sensor_msgs</depend>
<depend>std_msgs</depend>
<depend>tf2</depend>
<depend>tf2_ros</depend>
<depend>visualization_msgs</depend>

<test_depend>ament_cmake_gtest</test_depend>
Expand Down
46 changes: 27 additions & 19 deletions nav2_collision_monitor/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
# Kinematics test
ament_add_gtest(kinematics_test kinematics_test.cpp)
ament_target_dependencies(kinematics_test
${dependencies}
)
target_link_libraries(kinematics_test
${monitor_library_name}
rclcpp::rclcpp
)

# Data sources test
ament_add_gtest(sources_test sources_test.cpp)
ament_target_dependencies(sources_test
${dependencies}
)
target_link_libraries(sources_test
${monitor_library_name}
rclcpp::rclcpp
nav2_util::nav2_util_core
${sensor_msgs_TARGETS}
tf2_ros::tf2_ros
)

# Polygon shapes test
ament_add_gtest(polygons_test polygons_test.cpp)
ament_target_dependencies(polygons_test
${dependencies}
)
target_link_libraries(polygons_test
${monitor_library_name}
${geometry_msgs_TARGETS}
nav2_util::nav2_util_core
rclcpp::rclcpp
tf2_ros::tf2_ros
)

# Velocity Polygon test
ament_add_gtest(velocity_polygons_test velocity_polygons_test.cpp)
ament_target_dependencies(velocity_polygons_test
${dependencies}
)
target_link_libraries(velocity_polygons_test
${monitor_library_name}
${geometry_msgs_TARGETS}
nav2_util::nav2_util_core
rclcpp::rclcpp
tf2_ros::tf2_ros
)

# Collision Monitor node test
ament_add_gtest(collision_monitor_node_test collision_monitor_node_test.cpp)
ament_target_dependencies(collision_monitor_node_test
${dependencies}
)
target_link_libraries(collision_monitor_node_test
${monitor_library_name}
${geometry_msgs_TARGETS}
${nav2_msgs_TARGETS}
nav2_util::nav2_util_core
rclcpp::rclcpp
${sensor_msgs_TARGETS}
tf2_ros::tf2_ros
${visualization_msgs_TARGETS}
)
# Collision Detector node test
ament_add_gtest(collision_detector_node_test collision_detector_node_test.cpp)
ament_target_dependencies(collision_detector_node_test
${dependencies}
)
target_link_libraries(collision_detector_node_test
${detector_library_name}
)
${geometry_msgs_TARGETS}
nav2_util::nav2_util_core
rclcpp::rclcpp
${sensor_msgs_TARGETS}
tf2_ros::tf2_ros
${visualization_msgs_TARGETS}
)
6 changes: 3 additions & 3 deletions nav2_collision_monitor/test/velocity_polygons_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

#include <gtest/gtest.h>

#include <math.h>
#include <chrono>
#include <cmath>
#include <limits>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <string>
#include <limits>

#include "rclcpp/rclcpp.hpp"
#include "nav2_util/lifecycle_node.hpp"
Expand Down
Loading