├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── main.cpp └── package.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(btcpp_sample LANGUAGES CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 17) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | add_executable(btcpp_sample main.cpp) 9 | 10 | find_package(ament_cmake QUIET) 11 | 12 | if(ament_cmake_FOUND) 13 | 14 | find_package(behaviortree_cpp REQUIRED) 15 | ament_target_dependencies(btcpp_sample behaviortree_cpp) 16 | 17 | elseif( CATKIN_DEVEL_PREFIX OR CATKIN_BUILD_BINARY_PACKAGE) 18 | 19 | find_package(catkin REQUIRED COMPONENTS behaviortree_cpp) 20 | catkin_package(CATKIN_DEPENDS behaviortree_cpp) 21 | target_include_directories(btcpp_sample PRIVATE ${catkin_INCLUDE_DIRS}) 22 | target_link_libraries(btcpp_sample ${catkin_LIBRARIES}) 23 | 24 | else() 25 | 26 | find_package(behaviortree_cpp REQUIRED) 27 | target_link_libraries(btcpp_sample BT::behaviortree_cpp) 28 | 29 | endif() 30 | 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 BehaviorTree 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sample BehaviorTree.CPP project 2 | 3 | This project is compatible with version 4.X of [BehaviorTree.CPP](https://github.com/BehaviorTree/BehaviorTree.CPP). 4 | 5 | The **CMakeLists.txt** and **package.xml** files are compatible with both ROS and ROS2. 6 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "behaviortree_cpp/bt_factory.h" 2 | 3 | using namespace BT; 4 | 5 | // clang-format off 6 | static const char* xml_text = R"( 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | )"; 21 | // clang-format on 22 | 23 | class SaySomething : public BT::SyncActionNode 24 | { 25 | public: 26 | SaySomething(const std::string& name, const BT::NodeConfig& config) : 27 | BT::SyncActionNode(name, config) 28 | {} 29 | 30 | BT::NodeStatus tick() override 31 | { 32 | std::string msg; 33 | getInput("message", msg); 34 | std::cout << msg << std::endl; 35 | return BT::NodeStatus::SUCCESS; 36 | } 37 | 38 | static BT::PortsList providedPorts() 39 | { 40 | return {BT::InputPort("message")}; 41 | } 42 | }; 43 | 44 | class ThinkWhatToSay : public BT::SyncActionNode 45 | { 46 | public: 47 | ThinkWhatToSay(const std::string& name, const BT::NodeConfig& config) : 48 | BT::SyncActionNode(name, config) 49 | {} 50 | 51 | BT::NodeStatus tick() override 52 | { 53 | setOutput("text", "The answer is 42"); 54 | return BT::NodeStatus::SUCCESS; 55 | } 56 | 57 | static BT::PortsList providedPorts() 58 | { 59 | return {BT::OutputPort("text")}; 60 | } 61 | }; 62 | 63 | int main() 64 | { 65 | 66 | BehaviorTreeFactory factory; 67 | 68 | factory.registerNodeType("SaySomething"); 69 | factory.registerNodeType("ThinkWhatToSay"); 70 | 71 | auto tree = factory.createTreeFromText(xml_text); 72 | 73 | tree.tickWhileRunning(); 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | btcpp_sample 3 | 0.1.0 4 | Dummy project to check compiling 5 | 6 | Davide Faconti 7 | MIT 8 | Davide Faconti 9 | 10 | catkin 11 | ament_cmake 12 | 13 | rclcpp 14 | behaviortree_cpp 15 | 16 | 17 | catkin 18 | ament_cmake 19 | 20 | 21 | 22 | --------------------------------------------------------------------------------