diff --git a/nav2_map_server/CMakeLists.txt b/nav2_map_server/CMakeLists.txt index fd4208454b..3c2ce2eef8 100644 --- a/nav2_map_server/CMakeLists.txt +++ b/nav2_map_server/CMakeLists.txt @@ -4,128 +4,135 @@ project(nav2_map_server) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake_modules) find_package(ament_cmake REQUIRED) +find_package(GRAPHICSMAGICKCPP REQUIRED) +find_package(lifecycle_msgs REQUIRED) +find_package(nav_msgs REQUIRED) find_package(nav2_common REQUIRED) +find_package(nav2_msgs REQUIRED) +find_package(nav2_util REQUIRED) find_package(rclcpp REQUIRED) -find_package(rclcpp_lifecycle REQUIRED) find_package(rclcpp_components REQUIRED) -find_package(nav_msgs REQUIRED) -find_package(nav2_msgs REQUIRED) -find_package(yaml_cpp_vendor REQUIRED) +find_package(rclcpp_lifecycle REQUIRED) find_package(std_msgs REQUIRED) find_package(tf2 REQUIRED) -find_package(nav2_util REQUIRED) -find_package(GRAPHICSMAGICKCPP REQUIRED) +find_package(yaml_cpp_vendor REQUIRED) find_package(yaml-cpp REQUIRED) nav2_package() -include_directories(include) - set(map_server_executable map_server) +set(library_name ${map_server_executable}_core) + +set(map_io_library_name map_io) + set(map_saver_cli_executable map_saver_cli) set(map_saver_server_executable map_saver_server) set(costmap_filter_info_server_executable costmap_filter_info_server) -add_executable(${map_server_executable} - src/map_server/main.cpp) - -add_executable(${map_saver_cli_executable} - src/map_saver/main_cli.cpp) - -add_executable(${map_saver_server_executable} - src/map_saver/main_server.cpp) - -add_executable(${costmap_filter_info_server_executable} - src/costmap_filter_info/main.cpp) - -set(map_io_library_name map_io) - -set(library_name ${map_server_executable}_core) - add_library(${map_io_library_name} SHARED src/map_mode.cpp src/map_io.cpp) +target_include_directories(${map_io_library_name} + PUBLIC + "$" + "$") +target_include_directories(${map_io_library_name} + PRIVATE + ${GRAPHICSMAGICKCPP_INCLUDE_DIRS}) +target_link_libraries(${map_io_library_name} PUBLIC + nav2_util::nav2_util_core + ${nav_msgs_TARGETS} +) +target_link_libraries(${map_io_library_name} PRIVATE + ${GRAPHICSMAGICKCPP_LIBRARIES} + tf2::tf2 + yaml-cpp::yaml-cpp +) add_library(${library_name} SHARED src/map_server/map_server.cpp src/map_saver/map_saver.cpp src/costmap_filter_info/costmap_filter_info_server.cpp) +target_include_directories(${library_name} + PUBLIC + "$" + "$") +target_link_libraries(${library_name} PUBLIC + ${map_io_library_name} + ${nav_msgs_TARGETS} + ${nav2_msgs_TARGETS} + nav2_util::nav2_util_core + rclcpp::rclcpp + rclcpp_lifecycle::rclcpp_lifecycle +) +target_link_libraries(${library_name} PRIVATE + ${lifecycle_msgs_TARGETS} + rclcpp_components::component + yaml-cpp::yaml-cpp +) -set(map_io_dependencies - yaml_cpp_vendor - nav_msgs - nav2_util - tf2) - -set(map_server_dependencies - rclcpp - rclcpp_lifecycle - rclcpp_components - nav_msgs - nav2_msgs - yaml_cpp_vendor - std_msgs - nav2_util) - -set(map_saver_dependencies - rclcpp - rclcpp_lifecycle - nav_msgs - nav2_msgs - nav2_util) - -ament_target_dependencies(${map_server_executable} - ${map_server_dependencies}) - -ament_target_dependencies(${map_saver_cli_executable} - ${map_saver_dependencies}) - -ament_target_dependencies(${map_saver_server_executable} - ${map_saver_dependencies}) - -ament_target_dependencies(${costmap_filter_info_server_executable} - ${map_saver_dependencies}) - -ament_target_dependencies(${library_name} - ${map_server_dependencies}) - -ament_target_dependencies(${map_io_library_name} - ${map_io_dependencies}) - -target_link_libraries(${library_name} - ${map_io_library_name}) - -target_link_libraries(${map_server_executable} - ${library_name}) - -if(WIN32) - target_compile_definitions(${map_server_executable} PRIVATE - YAML_CPP_DLL) -endif() - -target_link_libraries(${map_saver_cli_executable} - ${library_name}) - -target_link_libraries(${map_saver_server_executable} - ${library_name}) - -target_link_libraries(${costmap_filter_info_server_executable} - ${library_name}) +add_executable(${map_server_executable} + src/map_server/main.cpp) +target_include_directories(${map_server_executable} + PRIVATE + "$" + "$") +target_link_libraries(${map_server_executable} PRIVATE + ${library_name} + ${map_io_library_name} + rclcpp::rclcpp +) -target_include_directories(${map_io_library_name} SYSTEM PRIVATE - ${GRAPHICSMAGICKCPP_INCLUDE_DIRS}) +add_executable(${map_saver_cli_executable} + src/map_saver/main_cli.cpp) +target_include_directories(${map_saver_cli_executable} + PRIVATE + "$" + "$") +target_link_libraries(${map_saver_cli_executable} PRIVATE + ${library_name} + ${map_io_library_name} + ${nav_msgs_TARGETS} + ${nav2_msgs_TARGETS} + nav2_util::nav2_util_core + rclcpp::rclcpp + rclcpp_lifecycle::rclcpp_lifecycle +) -target_link_libraries(${map_io_library_name} - ${GRAPHICSMAGICKCPP_LIBRARIES} - yaml-cpp::yaml-cpp) +add_executable(${map_saver_server_executable} + src/map_saver/main_server.cpp) +target_include_directories(${map_saver_server_executable} + PRIVATE + "$" + "$") +target_link_libraries(${map_saver_server_executable} PRIVATE + ${library_name} + ${map_io_library_name} + ${nav_msgs_TARGETS} + ${nav2_msgs_TARGETS} + nav2_util::nav2_util_core + rclcpp::rclcpp + rclcpp_lifecycle::rclcpp_lifecycle +) -if(WIN32) - target_compile_definitions(${map_io_library_name} PRIVATE - YAML_CPP_DLL) -endif() +add_executable(${costmap_filter_info_server_executable} + src/costmap_filter_info/main.cpp) +target_include_directories(${costmap_filter_info_server_executable} + PRIVATE + "$" + "$") +target_link_libraries(${costmap_filter_info_server_executable} PRIVATE + ${library_name} + ${map_io_library_name} + ${nav_msgs_TARGETS} + ${nav2_msgs_TARGETS} + nav2_util::nav2_util_core + rclcpp::rclcpp + rclcpp_lifecycle::rclcpp_lifecycle +) rclcpp_components_register_nodes(${library_name} "nav2_map_server::CostmapFilterInfoServer") rclcpp_components_register_nodes(${library_name} "nav2_map_server::MapSaver") @@ -133,6 +140,7 @@ rclcpp_components_register_nodes(${library_name} "nav2_map_server::MapServer") install(TARGETS ${library_name} ${map_io_library_name} + EXPORT ${library_name} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin) @@ -143,7 +151,7 @@ install(TARGETS RUNTIME DESTINATION lib/${PROJECT_NAME}) install(DIRECTORY include/ - DESTINATION include/) + DESTINATION include/${PROJECT_NAME}) install(DIRECTORY launch DESTINATION share/${PROJECT_NAME}) @@ -154,6 +162,7 @@ if(BUILD_TESTING) ament_lint_auto_find_test_dependencies() find_package(ament_cmake_gtest REQUIRED) + ament_find_gtest() add_subdirectory(test) endif() @@ -162,5 +171,7 @@ ament_export_libraries( ${library_name} ${map_io_library_name} ) -ament_export_dependencies(${map_io_dependencies} ${map_server_dependencies} yaml-cpp) +ament_export_dependencies(nav_msgs nav2_msgs nav2_util rclcpp rclcpp_lifecycle) +ament_export_targets(${library_name}) + ament_package() diff --git a/nav2_map_server/include/nav2_map_server/costmap_filter_info_server.hpp b/nav2_map_server/include/nav2_map_server/costmap_filter_info_server.hpp index 26f1153536..aa024f6dc0 100644 --- a/nav2_map_server/include/nav2_map_server/costmap_filter_info_server.hpp +++ b/nav2_map_server/include/nav2_map_server/costmap_filter_info_server.hpp @@ -18,6 +18,7 @@ #include #include "rclcpp/rclcpp.hpp" +#include "rclcpp_lifecycle/state.hpp" #include "nav2_util/lifecycle_node.hpp" #include "nav2_msgs/msg/costmap_filter_info.hpp" diff --git a/nav2_map_server/include/nav2_map_server/map_saver.hpp b/nav2_map_server/include/nav2_map_server/map_saver.hpp index bfeb986c62..18c26be3a7 100644 --- a/nav2_map_server/include/nav2_map_server/map_saver.hpp +++ b/nav2_map_server/include/nav2_map_server/map_saver.hpp @@ -16,10 +16,11 @@ #ifndef NAV2_MAP_SERVER__MAP_SAVER_HPP_ #define NAV2_MAP_SERVER__MAP_SAVER_HPP_ -#include #include +#include #include "rclcpp/rclcpp.hpp" +#include "rclcpp_lifecycle/state.hpp" #include "nav2_util/lifecycle_node.hpp" #include "nav2_msgs/srv/save_map.hpp" diff --git a/nav2_map_server/include/nav2_map_server/map_server.hpp b/nav2_map_server/include/nav2_map_server/map_server.hpp index d2a7e63f75..23c9fae9d4 100644 --- a/nav2_map_server/include/nav2_map_server/map_server.hpp +++ b/nav2_map_server/include/nav2_map_server/map_server.hpp @@ -15,15 +15,15 @@ #ifndef NAV2_MAP_SERVER__MAP_SERVER_HPP_ #define NAV2_MAP_SERVER__MAP_SERVER_HPP_ -#include #include -#include +#include -#include "rclcpp/rclcpp.hpp" #include "nav2_util/lifecycle_node.hpp" #include "nav_msgs/msg/occupancy_grid.hpp" #include "nav_msgs/srv/get_map.hpp" #include "nav2_msgs/srv/load_map.hpp" +#include "rclcpp/rclcpp.hpp" +#include "rclcpp_lifecycle/state.hpp" namespace nav2_map_server { diff --git a/nav2_map_server/package.xml b/nav2_map_server/package.xml index 2a051d4a72..1525e3f5ca 100644 --- a/nav2_map_server/package.xml +++ b/nav2_map_server/package.xml @@ -25,6 +25,7 @@ nav2_msgs nav2_util graphicsmagick + lifecycle_msgs ament_lint_common ament_lint_auto diff --git a/nav2_map_server/src/map_io.cpp b/nav2_map_server/src/map_io.cpp index 85428490ed..6fb82c1af2 100644 --- a/nav2_map_server/src/map_io.cpp +++ b/nav2_map_server/src/map_io.cpp @@ -45,6 +45,7 @@ #include "nav2_util/geometry_utils.hpp" #include "yaml-cpp/yaml.h" + #include "tf2/LinearMath/Matrix3x3.h" #include "tf2/LinearMath/Quaternion.h" #include "nav2_util/occ_grid_values.hpp" diff --git a/nav2_map_server/test/component/CMakeLists.txt b/nav2_map_server/test/component/CMakeLists.txt index 58ddbac211..58607fe5b7 100644 --- a/nav2_map_server/test/component/CMakeLists.txt +++ b/nav2_map_server/test/component/CMakeLists.txt @@ -1,12 +1,14 @@ -include_directories(${PROJECT_SOURCE_DIR}/test) - # map_server component test ament_add_gtest_executable(test_map_server_node test_map_server_node.cpp ${PROJECT_SOURCE_DIR}/test/test_constants.cpp ) -ament_target_dependencies(test_map_server_node rclcpp nav_msgs) +target_include_directories(test_map_server_node + PRIVATE + "$") target_link_libraries(test_map_server_node + rclcpp::rclcpp + ${nav_msgs_TARGETS} ${library_name} ) @@ -25,17 +27,23 @@ ament_add_gtest_executable(test_map_saver_node test_map_saver_node.cpp ${PROJECT_SOURCE_DIR}/test/test_constants.cpp ) - -ament_target_dependencies(test_map_saver_node rclcpp nav_msgs) +target_include_directories(test_map_saver_node + PRIVATE + "$") target_link_libraries(test_map_saver_node + rclcpp::rclcpp + ${nav_msgs_TARGETS} ${library_name} + ${map_io_library_name} ) add_executable(test_map_saver_publisher test_map_saver_publisher.cpp ${PROJECT_SOURCE_DIR}/test/test_constants.cpp ) - +target_include_directories(test_map_saver_publisher + PRIVATE + "$") target_link_libraries(test_map_saver_publisher ${map_io_library_name} ) diff --git a/nav2_map_server/test/map_saver_cli/CMakeLists.txt b/nav2_map_server/test/map_saver_cli/CMakeLists.txt index 01859094db..3731e541ac 100644 --- a/nav2_map_server/test/map_saver_cli/CMakeLists.txt +++ b/nav2_map_server/test/map_saver_cli/CMakeLists.txt @@ -1,12 +1,9 @@ -include_directories(${PROJECT_SOURCE_DIR}/test) - # map_saver CLI ament_add_gtest(test_map_saver_cli test_map_saver_cli.cpp ${PROJECT_SOURCE_DIR}/test/test_constants.cpp ) - -ament_target_dependencies(test_map_saver_cli rclcpp nav_msgs) target_link_libraries(test_map_saver_cli - ${dependencies} + rclcpp::rclcpp + ${nav_msgs_TARGETS} ) diff --git a/nav2_map_server/test/map_saver_cli/test_map_saver_cli.cpp b/nav2_map_server/test/map_saver_cli/test_map_saver_cli.cpp index 79cf58997f..6bce1cba28 100644 --- a/nav2_map_server/test/map_saver_cli/test_map_saver_cli.cpp +++ b/nav2_map_server/test/map_saver_cli/test_map_saver_cli.cpp @@ -92,9 +92,9 @@ TEST(MapSaverCLI, CLITest) std::string( "ros2 run nav2_map_server map_saver_cli " "-t map_failure --occ 100 --free 2 --mode trinary --fmt png -f ") + file_path + - std::string("--ros-args __node:=map_saver_test_node"); + std::string(" --ros-args --remap __node:=map_saver_test_node"); return_code = system(command.c_str()); - EXPECT_EQ(return_code, 65280); + EXPECT_EQ(return_code, 256); rclcpp::Rate(0.25).sleep(); @@ -140,7 +140,7 @@ TEST(MapSaverCLI, CLITest) command = std::string( - "ros2 run nav2_map_server map_saver_cli --ros-args -r __node:=map_saver_test_node"); + "ros2 run nav2_map_server map_saver_cli --ros-args --remap __node:=map_saver_test_node"); return_code = system(command.c_str()); EXPECT_EQ(return_code, 0); } diff --git a/nav2_map_server/test/unit/CMakeLists.txt b/nav2_map_server/test/unit/CMakeLists.txt index 936c59ed89..4140b14d6f 100644 --- a/nav2_map_server/test/unit/CMakeLists.txt +++ b/nav2_map_server/test/unit/CMakeLists.txt @@ -1,11 +1,11 @@ -include_directories(${PROJECT_SOURCE_DIR}/test) - # map_io unit test ament_add_gtest(test_map_io test_map_io.cpp ${PROJECT_SOURCE_DIR}/test/test_constants.cpp) - -ament_target_dependencies(test_map_io rclcpp nav_msgs) - +target_include_directories(test_map_io + PRIVATE + "$") target_link_libraries(test_map_io + rclcpp::rclcpp + ${nav_msgs_TARGETS} ${map_io_library_name} ) @@ -13,9 +13,8 @@ target_link_libraries(test_map_io ament_add_gtest(test_costmap_filter_info_server test_costmap_filter_info_server.cpp ) - -ament_target_dependencies(test_costmap_filter_info_server rclcpp) - target_link_libraries(test_costmap_filter_info_server + rclcpp::rclcpp ${library_name} + ${map_io_library_name} )