Skip to content

Commit

Permalink
Revamp nav2_behavior_tree CMakeLists.txt to use modern idioms.
Browse files Browse the repository at this point in the history
This commit does a number of things:

1.  Switches to using target_link_libraries everywhere.
This gives us finer-grained control over what dependencies
are exported to downstream as public, or private.  In the
particular case of nav2_behavior_tree, this actually doesn't matter
*too* much, but it will help for other packages.
2.  Moves the include directory down one level to
include/${PROJECT_NAME}, which is best practice in ROS 2
since Humble.
3.  Makes sure to export nav2_behavior_tree as a CMake target, so
downstream users of it can use that target.
4.  Removes the use of boost.  To do this, we had to introduce
our own version of the "split_string" method.
5.  Moves the test_action_server.hpp file into the main include
directory.  This is slightly odd, but because downstream packages
(opennav_docking_bt) depend on this header file to compile
their own tests, it is technically part of the public interface.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette committed Jun 25, 2024
1 parent 715df8f commit c285b10
Show file tree
Hide file tree
Showing 38 changed files with 226 additions and 283 deletions.
124 changes: 75 additions & 49 deletions nav2_behavior_tree/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,48 @@ cmake_minimum_required(VERSION 3.5)
project(nav2_behavior_tree CXX)

find_package(ament_cmake REQUIRED)
find_package(action_msgs REQUIRED)
find_package(behaviortree_cpp REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav2_common REQUIRED)
find_package(nav2_msgs REQUIRED)
find_package(nav2_util REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(nav2_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(behaviortree_cpp REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(nav2_util REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)

nav2_package()

add_compile_options(-Wno-shadow) # Delete after https://github.com/BehaviorTree/BehaviorTree.CPP/issues/811 is released

include_directories(
include
)

set(library_name ${PROJECT_NAME})

set(dependencies
rclcpp
rclcpp_action
rclcpp_lifecycle
geometry_msgs
sensor_msgs
nav2_msgs
nav_msgs
behaviortree_cpp
tf2
tf2_ros
tf2_geometry_msgs
std_msgs
std_srvs
nav2_util
)

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

ament_target_dependencies(${library_name}
${dependencies}
target_include_directories(${library_name}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(${library_name} PUBLIC
${action_msgs_TARGETS}
behaviortree_cpp::behaviortree_cpp
${geometry_msgs_TARGETS}
${nav_msgs_TARGETS}
${nav2_msgs_TARGETS}
nav2_util::nav2_util_core
rclcpp::rclcpp
rclcpp_action::rclcpp_action
rclcpp_lifecycle::rclcpp_lifecycle
${sensor_msgs_TARGETS}
tf2::tf2
tf2_ros::tf2_ros
)

add_library(nav2_compute_path_to_pose_action_bt_node SHARED plugins/action/compute_path_to_pose_action.cpp)
Expand Down Expand Up @@ -213,12 +206,30 @@ add_library(nav2_goal_updated_controller_bt_node SHARED plugins/decorator/goal_u
list(APPEND plugin_libs nav2_goal_updated_controller_bt_node)

foreach(bt_plugin ${plugin_libs})
ament_target_dependencies(${bt_plugin} ${dependencies})
target_include_directories(${bt_plugin}
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(${bt_plugin} PUBLIC
behaviortree_cpp::behaviortree_cpp
${geometry_msgs_TARGETS}
${nav_msgs_TARGETS}
${nav2_msgs_TARGETS}
nav2_util::nav2_util_core
rclcpp::rclcpp
rclcpp_action::rclcpp_action
rclcpp_lifecycle::rclcpp_lifecycle
${sensor_msgs_TARGETS}
tf2::tf2
tf2_ros::tf2_ros
${std_msgs_TARGETS}
${std_srvs_TARGETS}
)
target_compile_definitions(${bt_plugin} PRIVATE BT_PLUGIN_EXPORT)
endforeach()

install(TARGETS ${library_name}
${plugin_libs}
install(TARGETS ${library_name} ${plugin_libs}
EXPORT ${library_name}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
Expand All @@ -229,39 +240,54 @@ set(GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen)
configure_file(plugins_list.hpp.in ${GENERATED_DIR}/plugins_list.hpp)

add_executable(generate_nav2_tree_nodes_xml src/generate_nav2_tree_nodes_xml.cpp)
ament_target_dependencies(generate_nav2_tree_nodes_xml ${dependencies})
target_link_libraries(generate_nav2_tree_nodes_xml PRIVATE
behaviortree_cpp::behaviortree_cpp
nav2_util::nav2_util_core
)
# allow generate_nav2_tree_nodes_xml to find plugins_list.hpp
target_include_directories(generate_nav2_tree_nodes_xml PRIVATE ${GENERATED_DIR})
install(TARGETS generate_nav2_tree_nodes_xml DESTINATION lib/${PROJECT_NAME})


install(DIRECTORY include/
DESTINATION include/
)

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

install(FILES nav2_tree_nodes.xml DESTINATION share/${PROJECT_NAME})
install(FILES ${GENERATED_DIR}/plugins_list.hpp DESTINATION include/${PROJECT_NAME})
install(FILES ${GENERATED_DIR}/plugins_list.hpp DESTINATION include/${PROJECT_NAME}/${PROJECT_NAME})

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
find_package(ament_cmake_gtest REQUIRED)

ament_find_gtest()

add_subdirectory(test)
endif()

ament_export_include_directories(
include
include/${PROJECT_NAME}
)

ament_export_libraries(
${library_name}
${plugin_libs}
)
ament_export_libraries(${library_name})

ament_export_dependencies(${dependencies})
ament_export_dependencies(
action_msgs
behaviortree_cpp
geometry_msgs
nav2_common
nav2_msgs
nav2_util
nav_msgs
rclcpp
rclcpp_action
rclcpp_lifecycle
sensor_msgs
std_msgs
std_srvs
tf2
tf2_ros
)
ament_export_targets(${library_name})

ament_package()
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#ifndef NAV2_BEHAVIOR_TREE__BT_ACTION_SERVER_HPP_
#define NAV2_BEHAVIOR_TREE__BT_ACTION_SERVER_HPP_

#include <chrono>
#include <functional>
#include <memory>
#include <string>
#include <vector>
Expand All @@ -24,6 +26,8 @@
#include "nav2_behavior_tree/ros_topic_logger.hpp"
#include "nav2_util/lifecycle_node.hpp"
#include "nav2_util/simple_action_server.hpp"
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"

namespace nav2_behavior_tree
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@
#ifndef NAV2_BEHAVIOR_TREE__BT_ACTION_SERVER_IMPL_HPP_
#define NAV2_BEHAVIOR_TREE__BT_ACTION_SERVER_IMPL_HPP_

#include <memory>
#include <string>
#include <chrono>
#include <exception>
#include <fstream>
#include <limits>
#include <memory>
#include <set>
#include <exception>
#include <string>
#include <vector>
#include <limits>

#include "nav2_msgs/action/navigate_to_pose.hpp"
#include "nav2_behavior_tree/bt_action_server.hpp"
#include "ament_index_cpp/get_package_share_directory.hpp"
#include "nav2_util/node_utils.hpp"
#include "rcl_action/action_server.h"
#include "rclcpp_lifecycle/lifecycle_node.hpp"

namespace nav2_behavior_tree
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "rclcpp/rclcpp.hpp"
#include "nav2_msgs/msg/behavior_tree_log.hpp"
#include "nav2_msgs/msg/behavior_tree_status_change.h"
#include "tf2/time.h"
#include "tf2_ros/buffer_interface.h"

namespace nav2_behavior_tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef UTILS__TEST_ACTION_SERVER_HPP_
#define UTILS__TEST_ACTION_SERVER_HPP_
#ifndef NAV2_BEHAVIOR_TREE__UTILS__TEST_ACTION_SERVER_HPP_
#define NAV2_BEHAVIOR_TREE__UTILS__TEST_ACTION_SERVER_HPP_

#include <string>
#include <memory>
Expand Down Expand Up @@ -97,4 +97,4 @@ class TestActionServer : public rclcpp::Node
bool goal_cancelled_ = false;
};

#endif // UTILS__TEST_ACTION_SERVER_HPP_
#endif // NAV2_BEHAVIOR_TREE__UTILS__TEST_ACTION_SERVER_HPP_
52 changes: 16 additions & 36 deletions nav2_behavior_tree/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,26 @@

<buildtool_depend>ament_cmake</buildtool_depend>

<build_export_depend>tf2_geometry_msgs</build_export_depend>
<build_export_depend>std_srvs</build_export_depend>

<build_depend>rclcpp</build_depend>
<build_depend>rclcpp_action</build_depend>
<build_depend>rclcpp_lifecycle</build_depend>
<build_depend>behaviortree_cpp</build_depend>
<build_depend>builtin_interfaces</build_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>nav2_msgs</build_depend>
<build_depend>nav_msgs</build_depend>
<build_depend>tf2</build_depend>
<build_depend>tf2_ros</build_depend>
<build_depend>tf2_geometry_msgs</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>std_srvs</build_depend>
<build_depend>nav2_util</build_depend>
<build_depend>lifecycle_msgs</build_depend>
<build_depend>nav2_common</build_depend>

<exec_depend>rclcpp</exec_depend>
<exec_depend>rclcpp_action</exec_depend>
<exec_depend>rclcpp_lifecycle</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>behaviortree_cpp</exec_depend>
<exec_depend>builtin_interfaces</exec_depend>
<exec_depend>geometry_msgs</exec_depend>
<exec_depend>sensor_msgs</exec_depend>
<exec_depend>nav2_msgs</exec_depend>
<exec_depend>nav_msgs</exec_depend>
<exec_depend>tf2</exec_depend>
<exec_depend>tf2_ros</exec_depend>
<exec_depend>tf2_geometry_msgs</exec_depend>
<exec_depend>nav2_util</exec_depend>
<exec_depend>lifecycle_msgs</exec_depend>
<depend>action_msgs</depend>
<depend>behaviortree_cpp</depend>
<depend>geometry_msgs</depend>
<depend>nav2_common</depend>
<depend>nav2_msgs</depend>
<depend>nav2_util</depend>
<depend>nav_msgs</depend>
<depend>rclcpp</depend>
<depend>rclcpp_action</depend>
<depend>rclcpp_lifecycle</depend>
<depend>sensor_msgs</depend>
<depend>std_msgs</depend>
<depend>std_srvs</depend>
<depend>tf2</depend>
<depend>tf2_ros</depend>

<test_depend>ament_lint_common</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_cmake_gtest</test_depend>
<test_depend>lifecycle_msgs</test_depend>
<test_depend>test_msgs</test_depend>

<export>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <cmath>
#include <limits>
#include <memory>
#include <string>
Expand All @@ -22,6 +23,9 @@
#include "nav2_util/geometry_utils.hpp"
#include "nav2_util/robot_utils.hpp"
#include "nav_msgs/msg/path.hpp"
#include "rclcpp/rclcpp.hpp"
#include "tf2/LinearMath/Quaternion.h"
#include "tf2_ros/buffer.h"
#include "tf2_ros/create_timer_ros.h"

#include "nav2_behavior_tree/plugins/action/truncate_path_local_action.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <string>
#include <chrono>
#include <memory>
#include <string>

#include "rclcpp/rclcpp.hpp"
#include "tf2/time.h"
#include "tf2_ros/buffer.h"

#include "nav2_behavior_tree/plugins/condition/transform_available_condition.hpp"

Expand Down
19 changes: 17 additions & 2 deletions nav2_behavior_tree/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
ament_add_gtest(test_bt_utils test_bt_utils.cpp)
ament_target_dependencies(test_bt_utils ${dependencies})
target_link_libraries(test_bt_utils
${library_name}
${geometry_msgs_TARGETS}
)

include_directories(.)
function(plugin_add_test target filename plugin)
ament_add_gtest(${target} ${filename})
target_link_libraries(${target}
${geometry_msgs_TARGETS}
nav2_util::nav2_util_core
behaviortree_cpp::behaviortree_cpp
${library_name}
${plugin}
)
target_include_directories(${target}
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/test>")
endfunction()

add_subdirectory(plugins/condition)
add_subdirectory(plugins/decorator)
Expand Down
Loading

0 comments on commit c285b10

Please sign in to comment.