forked from BehaviorTree/BehaviorTree.CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove legacy ament functions * Add ament_export_targets * Match namespace for conan and ROS * Depends on ament/ament_cmake#498 merging and backport to humble * Add CI for export tests and colcon building Signed-off-by: Ryan Friedman <[email protected]>
- Loading branch information
Showing
10 changed files
with
272 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: colcon ament Ubuntu | ||
|
||
on: [push, pull_request] | ||
|
||
env: | ||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) | ||
BUILD_TYPE: Release | ||
|
||
jobs: | ||
build: | ||
# The CMake configure and build commands are platform agnostic and should work equally | ||
# well on Windows or Mac. You can convert this to a matrix build if you need | ||
# cross-platform coverage. | ||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
container: ['osrf/ros:humble-desktop', 'osrf/ros:rolling-desktop'] | ||
os: [ubuntu-22.04] | ||
ros_distro: [humble, rolling] | ||
include: | ||
- container: osrf/ros:humble-desktop | ||
ros_distro: humble | ||
- container: osrf/ros:rolling-desktop | ||
ros_distro: rolling | ||
|
||
container: ${{ matrix.container }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Install binary dependencies with rosdep | ||
id: rosdep | ||
run: | | ||
apt update | ||
rosdep update | ||
source /opt/ros/${{matrix.config.rosdistro}}/setup.bash | ||
rosdep install --from-paths src --ignore-src -y --rosdistro ${{matrix.config.rosdistro}} | ||
shell: bash | ||
|
||
- name: Build with colcon | ||
id: colcon-build | ||
run: | | ||
source /opt/ros/${{matrix.config.rosdistro}}/setup.bash | ||
colcon build | ||
shell: bash | ||
|
||
- name: Test with colcon | ||
id: colcon-test | ||
run: | | ||
source /opt/ros/${{matrix.config.rosdistro}}/setup.bash | ||
colcon test | ||
colcon test-result --all --verbose | ||
shell: bash | ||
|
||
- name: Test consuming with ament_target_dependencies | ||
run: | | ||
source /opt/ros/${{matrix.config.rosdistro}}/setup.bash | ||
# This sets the variable AMENT_PREFIX_PATH | ||
source install/setup.bash | ||
cd tests/export/ament_target_deps | ||
colcon build | ||
- name: Test consuming with target_link_libraries | ||
run: | | ||
source /opt/ros/${{matrix.config.rosdistro}}/setup.bash | ||
# This sets the variable AMENT_PREFIX_PATH | ||
source install/setup.bash | ||
cd tests/export/target_link_libs | ||
colcon build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Export tests | ||
|
||
The purpose of the tests below is to ensure that BTCPP exports itself correctly for use with find_package. | ||
|
||
Without testing this, it is easy to accidentally break consumer applications when working on CMake installation code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cmake_minimum_required(VERSION 3.22.1) # version on Ubuntu Jammy | ||
project(btcpp_ament_tgt_dep LANGUAGES CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
find_package(ament_cmake 1 CONFIG REQUIRED) | ||
find_package(behaviortree_cpp 4 REQUIRED) | ||
|
||
add_executable(btcpp_sample main.cpp) | ||
|
||
# This function doesn't yet support PRIVATE as an argument. | ||
# See https://github.com/ament/ament_cmake/issues/158#issuecomment-475384147 | ||
# Instead, test preserving legacy usage with no linkage specifier. | ||
ament_target_dependencies(btcpp_sample behaviortree_cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copy of https://github.com/BehaviorTree/btcpp_sample/blob/main/main.cpp | ||
|
||
#include "behaviortree_cpp/bt_factory.h" | ||
|
||
using namespace BT; | ||
|
||
// clang-format off | ||
static const char* xml_text = R"( | ||
<root BTCPP_format="4" > | ||
<BehaviorTree ID="MainTree"> | ||
<Sequence name="root"> | ||
<AlwaysSuccess/> | ||
<SaySomething message="this works too" /> | ||
<ThinkWhatToSay text="{the_answer}"/> | ||
<SaySomething message="{the_answer}" /> | ||
</Sequence> | ||
</BehaviorTree> | ||
</root> | ||
)"; | ||
// clang-format on | ||
|
||
class SaySomething : public BT::SyncActionNode | ||
{ | ||
public: | ||
SaySomething(const std::string& name, const BT::NodeConfig& config) : | ||
BT::SyncActionNode(name, config) | ||
{} | ||
|
||
BT::NodeStatus tick() override | ||
{ | ||
std::string msg; | ||
getInput("message", msg); | ||
std::cout << msg << std::endl; | ||
return BT::NodeStatus::SUCCESS; | ||
} | ||
|
||
static BT::PortsList providedPorts() | ||
{ | ||
return {BT::InputPort<std::string>("message")}; | ||
} | ||
}; | ||
|
||
class ThinkWhatToSay : public BT::SyncActionNode | ||
{ | ||
public: | ||
ThinkWhatToSay(const std::string& name, const BT::NodeConfig& config) : | ||
BT::SyncActionNode(name, config) | ||
{} | ||
|
||
BT::NodeStatus tick() override | ||
{ | ||
setOutput("text", "The answer is 42"); | ||
return BT::NodeStatus::SUCCESS; | ||
} | ||
|
||
static BT::PortsList providedPorts() | ||
{ | ||
return {BT::OutputPort<std::string>("text")}; | ||
} | ||
}; | ||
|
||
int main() | ||
{ | ||
|
||
BehaviorTreeFactory factory; | ||
|
||
factory.registerNodeType<SaySomething>("SaySomething"); | ||
factory.registerNodeType<ThinkWhatToSay>("ThinkWhatToSay"); | ||
|
||
auto tree = factory.createTreeFromText(xml_text); | ||
|
||
tree.tickWhileRunning(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
cmake_minimum_required(VERSION 3.22.1) # version on Ubuntu Jammy | ||
project(btcpp_tgt_link_libs LANGUAGES CXX) | ||
|
||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
find_package(ament_cmake 1 CONFIG REQUIRED) | ||
set(CMAKE_FIND_DEBUG_MODE TRUE) | ||
find_package(behaviortree_cpp 4 CONFIG REQUIRED) | ||
set(CMAKE_FIND_DEBUG_MODE FALSE) | ||
|
||
add_executable(btcpp_sample main.cpp) | ||
|
||
# Check it works with the same target that conan users use | ||
target_link_libraries(btcpp_sample PRIVATE BT::behaviortree_cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copy of https://github.com/BehaviorTree/btcpp_sample/blob/main/main.cpp | ||
|
||
#include "behaviortree_cpp/bt_factory.h" | ||
|
||
using namespace BT; | ||
|
||
// clang-format off | ||
static const char* xml_text = R"( | ||
<root BTCPP_format="4" > | ||
<BehaviorTree ID="MainTree"> | ||
<Sequence name="root"> | ||
<AlwaysSuccess/> | ||
<SaySomething message="this works too" /> | ||
<ThinkWhatToSay text="{the_answer}"/> | ||
<SaySomething message="{the_answer}" /> | ||
</Sequence> | ||
</BehaviorTree> | ||
</root> | ||
)"; | ||
// clang-format on | ||
|
||
class SaySomething : public BT::SyncActionNode | ||
{ | ||
public: | ||
SaySomething(const std::string& name, const BT::NodeConfig& config) : | ||
BT::SyncActionNode(name, config) | ||
{} | ||
|
||
BT::NodeStatus tick() override | ||
{ | ||
std::string msg; | ||
getInput("message", msg); | ||
std::cout << msg << std::endl; | ||
return BT::NodeStatus::SUCCESS; | ||
} | ||
|
||
static BT::PortsList providedPorts() | ||
{ | ||
return {BT::InputPort<std::string>("message")}; | ||
} | ||
}; | ||
|
||
class ThinkWhatToSay : public BT::SyncActionNode | ||
{ | ||
public: | ||
ThinkWhatToSay(const std::string& name, const BT::NodeConfig& config) : | ||
BT::SyncActionNode(name, config) | ||
{} | ||
|
||
BT::NodeStatus tick() override | ||
{ | ||
setOutput("text", "The answer is 42"); | ||
return BT::NodeStatus::SUCCESS; | ||
} | ||
|
||
static BT::PortsList providedPorts() | ||
{ | ||
return {BT::OutputPort<std::string>("text")}; | ||
} | ||
}; | ||
|
||
int main() | ||
{ | ||
|
||
BehaviorTreeFactory factory; | ||
|
||
factory.registerNodeType<SaySomething>("SaySomething"); | ||
factory.registerNodeType<ThinkWhatToSay>("ThinkWhatToSay"); | ||
|
||
auto tree = factory.createTreeFromText(xml_text); | ||
|
||
tree.tickWhileRunning(); | ||
|
||
return 0; | ||
} |