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_amcl to use modern CMake idioms. #4564

Merged
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
171 changes: 116 additions & 55 deletions nav2_amcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,90 +2,136 @@ cmake_minimum_required(VERSION 3.5)
project(nav2_amcl)

find_package(ament_cmake REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(message_filters REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(nav2_common REQUIRED)
find_package(nav2_msgs REQUIRED)
find_package(nav2_util REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(message_filters REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2 REQUIRED)
find_package(nav2_util REQUIRED)
find_package(nav2_msgs REQUIRED)
find_package(pluginlib REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)
find_package(tf2_ros REQUIRED)

nav2_package()

include_directories(
include
)

include(CheckSymbolExists)
check_symbol_exists(drand48 stdlib.h HAVE_DRAND48)

add_subdirectory(src/pf)
add_subdirectory(src/map)
add_subdirectory(src/motion_model)
add_subdirectory(src/sensors)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-gnu-folding-constant)
endif()

set(executable_name amcl)
add_library(pf_lib SHARED
src/pf/pf.c
src/pf/pf_kdtree.c
src/pf/pf_pdf.c
src/pf/pf_vector.c
src/pf/eig3.c
src/pf/pf_draw.c
)
target_include_directories(pf_lib
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
if(HAVE_DRAND48)
target_compile_definitions(pf_lib PRIVATE "HAVE_DRAND48")
endif()

add_executable(${executable_name}
src/main.cpp
add_library(map_lib SHARED
src/map/map.c
src/map/map_range.c
src/map/map_draw.c
src/map/map_cspace.cpp
)
target_include_directories(map_lib
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")

add_library(motions_lib SHARED
src/motion_model/omni_motion_model.cpp
src/motion_model/differential_motion_model.cpp
)
target_include_directories(motions_lib
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(motions_lib PUBLIC
pf_lib
pluginlib::pluginlib
nav2_util::nav2_util_core
)

add_library(sensors_lib SHARED
src/sensors/laser/laser.cpp
src/sensors/laser/beam_model.cpp
src/sensors/laser/likelihood_field_model.cpp
src/sensors/laser/likelihood_field_model_prob.cpp
)
target_include_directories(sensors_lib
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(sensors_lib PUBLIC
pf_lib
map_lib
)

set(executable_name amcl)

set(library_name ${executable_name}_core)

add_library(${library_name} SHARED
src/amcl_node.cpp
)

target_include_directories(${library_name} PRIVATE src/include)

if(HAVE_DRAND48)
target_compile_definitions(${library_name} PRIVATE "HAVE_DRAND48")
endif()

set(dependencies
rclcpp
rclcpp_lifecycle
rclcpp_components
message_filters
tf2_geometry_msgs
geometry_msgs
nav_msgs
sensor_msgs
std_srvs
tf2_ros
tf2
nav2_util
nav2_msgs
pluginlib
target_include_directories(${library_name}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(${library_name} PUBLIC
${geometry_msgs_TARGETS}
message_filters::message_filters
nav2_util::nav2_util_core
${sensor_msgs_TARGETS}
${std_srvs_TARGETS}
pluginlib::pluginlib
sensors_lib
rclcpp::rclcpp
rclcpp_lifecycle::rclcpp_lifecycle
${nav_msgs_TARGETS}
tf2_ros::tf2_ros
tf2::tf2
${nav2_msgs_TARGETS}
)

ament_target_dependencies(${executable_name}
${dependencies}
target_link_libraries(${library_name} PRIVATE
rclcpp_components::component
tf2_geometry_msgs::tf2_geometry_msgs
)

target_link_libraries(${executable_name}
${library_name}
)

ament_target_dependencies(${library_name}
${dependencies}
add_executable(${executable_name}
src/main.cpp
)

target_link_libraries(${library_name}
map_lib pf_lib sensors_lib
target_include_directories(${executable_name}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(${executable_name} PRIVATE
${library_name}
)

rclcpp_components_register_nodes(${library_name} "nav2_amcl::AmclNode")

install(TARGETS ${library_name}
install(TARGETS ${library_name} pf_lib map_lib motions_lib sensors_lib
EXPORT ${library_name}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
Expand All @@ -96,19 +142,34 @@ install(TARGETS ${executable_name}
)

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

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
set(ament_cmake_copyright_FOUND TRUE)
set(ament_cmake_cpplint_FOUND TRUE)

ament_lint_auto_find_test_dependencies()
endif()

ament_export_include_directories(include)
ament_export_include_directories("include/${PROJECT_NAME}")
ament_export_libraries(${library_name} pf_lib sensors_lib motions_lib map_lib)
ament_export_dependencies(${dependencies})
ament_export_dependencies(
geometry_msgs
message_filters
nav_msgs
nav2_msgs
nav2_util
pluginlib
rclcpp
rclcpp_lifecycle
sensor_msgs
std_srvs
tf2
tf2_ros
)
ament_export_targets(${library_name})
pluginlib_export_plugin_description_file(nav2_amcl plugins.xml)
ament_package()
10 changes: 3 additions & 7 deletions nav2_amcl/include/nav2_amcl/amcl_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,13 @@
#include "nav2_msgs/msg/particle_cloud.hpp"
#include "nav2_msgs/srv/set_initial_pose.hpp"
#include "nav_msgs/srv/set_map.hpp"
#include "pluginlib/class_loader.hpp"
#include "rclcpp/node_options.hpp"
#include "sensor_msgs/msg/laser_scan.hpp"
#include "std_srvs/srv/empty.hpp"
#include "tf2_ros/message_filter.h"
#include "tf2_ros/transform_broadcaster.h"
#include "tf2_ros/transform_listener.h"
#include "pluginlib/class_loader.hpp"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wreorder"
#include "tf2_ros/message_filter.h"
#pragma GCC diagnostic pop

#define NEW_UNIFORM_SAMPLING 1

Expand Down
2 changes: 1 addition & 1 deletion nav2_amcl/include/nav2_amcl/angleutils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#ifndef NAV2_AMCL__ANGLEUTILS_HPP_
#define NAV2_AMCL__ANGLEUTILS_HPP_

#include <math.h>
#include <cmath>

namespace nav2_amcl
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
#ifndef NAV2_AMCL__MOTION_MODEL__DIFFERENTIAL_MOTION_MODEL_HPP_
#define NAV2_AMCL__MOTION_MODEL__DIFFERENTIAL_MOTION_MODEL_HPP_

#include <sys/types.h>
#include <math.h>
#include <algorithm>
#include "nav2_amcl/motion_model/motion_model.hpp"
#include "nav2_amcl/angleutils.hpp"
#include "nav2_amcl/pf/pf.hpp"
#include "nav2_amcl/pf/pf_vector.hpp"


namespace nav2_amcl
Expand Down
5 changes: 1 addition & 4 deletions nav2_amcl/include/nav2_amcl/motion_model/motion_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
#ifndef NAV2_AMCL__MOTION_MODEL__MOTION_MODEL_HPP_
#define NAV2_AMCL__MOTION_MODEL__MOTION_MODEL_HPP_

#include <string>
#include <memory>

#include "nav2_amcl/pf/pf.hpp"
#include "nav2_amcl/pf/pf_pdf.hpp"
#include "nav2_amcl/pf/pf_vector.hpp"

namespace nav2_amcl
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
#ifndef NAV2_AMCL__MOTION_MODEL__OMNI_MOTION_MODEL_HPP_
#define NAV2_AMCL__MOTION_MODEL__OMNI_MOTION_MODEL_HPP_

#include <sys/types.h>
#include <math.h>
#include <algorithm>
#include "nav2_amcl/motion_model/motion_model.hpp"
#include "nav2_amcl/angleutils.hpp"

#include "nav2_amcl/pf/pf.hpp"
#include "nav2_amcl/pf/pf_vector.hpp"

namespace nav2_amcl
{
Expand Down
4 changes: 2 additions & 2 deletions nav2_amcl/include/nav2_amcl/sensors/laser/laser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#ifndef NAV2_AMCL__SENSORS__LASER__LASER_HPP_
#define NAV2_AMCL__SENSORS__LASER__LASER_HPP_

#include <string>
#include "nav2_amcl/map/map.hpp"
#include "nav2_amcl/pf/pf.hpp"
#include "nav2_amcl/pf/pf_pdf.hpp"
#include "nav2_amcl/map/map.hpp"
#include "nav2_amcl/pf/pf_vector.hpp"

namespace nav2_amcl
{
Expand Down
23 changes: 13 additions & 10 deletions nav2_amcl/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,30 @@
'amcl' Player driver.
</p>
</description>
<!-- <author>Brian P. Gerkey</author>
<author>[email protected]</author> -->
<maintainer email="[email protected]">Mohammad Haghighipanah</maintainer>
<license>LGPL-2.1-or-later</license>

<author>Brian P. Gerkey</author>
<author>[email protected]</author>

<buildtool_depend>ament_cmake</buildtool_depend>
<build_depend>nav2_common</build_depend>
<depend>rclcpp</depend>
<depend>tf2_geometry_msgs</depend>

<depend>geometry_msgs</depend>
<depend>message_filters</depend>
<depend>nav_msgs</depend>
<depend>nav2_msgs</depend>
<depend>nav2_util</depend>
<depend>pluginlib</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>rclcpp_lifecycle</depend>
<depend>sensor_msgs</depend>
<depend>std_srvs</depend>
<depend>tf2_ros</depend>
<depend>tf2</depend>
<depend>nav2_util</depend>
<depend>nav2_msgs</depend>
<depend>launch_ros</depend>
<depend>launch_testing</depend>
<depend>pluginlib</depend>
<depend>tf2_geometry_msgs</depend>
<depend>tf2_ros</depend>

<test_depend>ament_lint_common</test_depend>
<test_depend>ament_lint_auto</test_depend>

Expand Down
Loading
Loading