diff --git a/.clang-format b/.clang-format index d912fdc66..80f4f718b 100644 --- a/.clang-format +++ b/.clang-format @@ -1,5 +1,5 @@ --- -BasedOnStyle: Google +BasedOnStyle: Google AccessModifierOffset: -2 ConstructorInitializerIndentWidth: 2 AlignEscapedNewlinesLeft: false @@ -8,15 +8,13 @@ AllowAllParametersOfDeclarationOnNextLine: false AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false AllowShortFunctionsOnASingleLine: None -AllowShortLoopsOnASingleLine: false AlwaysBreakTemplateDeclarations: true AlwaysBreakBeforeMultilineStrings: false BreakBeforeBinaryOperators: false BreakBeforeTernaryOperators: false -BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: AfterColon +BreakConstructorInitializers: BeforeComma BinPackParameters: true -ColumnLimit: 90 +ColumnLimit: 90 ConstructorInitializerAllOnOneLineOrOnePerLine: true DerivePointerBinding: false PointerBindsToType: true @@ -31,19 +29,20 @@ PenaltyBreakString: 1 PenaltyBreakFirstLessLess: 1000 PenaltyExcessCharacter: 1000 PenaltyReturnTypeOnItsOwnLine: 90 -SpacesBeforeTrailingComments: 3 -Cpp11BracedListStyle: true -Standard: Auto -IndentWidth: 2 -TabWidth: 2 -UseTab: Never +SpacesBeforeTrailingComments: 2 +Cpp11BracedListStyle: false +Standard: Auto +IndentWidth: 2 +TabWidth: 2 +UseTab: Never IndentFunctionDeclarationAfterType: false SpacesInParentheses: false -SpacesInAngles: false +SpacesInAngles: false SpaceInEmptyParentheses: false SpacesInCStyleCastParentheses: false SpaceAfterControlStatementKeyword: true SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: Never ContinuationIndentWidth: 4 SortIncludes: false SpaceAfterCStyleCast: false @@ -54,17 +53,16 @@ BreakBeforeBraces: Custom # Control of individual brace wrapping cases BraceWrapping: { - AfterClass: 'true' - AfterControlStatement: 'true' - AfterEnum : 'true' - AfterFunction : 'true' - AfterNamespace : 'true' - AfterStruct : 'true' - AfterUnion : 'true' - BeforeCatch : 'true' - BeforeElse : 'true' - IndentBraces : 'false' + AfterClass: 'true', + AfterControlStatement: 'true', + AfterEnum : 'true', + AfterFunction : 'true', + AfterNamespace : 'true', + AfterStruct : 'true', + AfterUnion : 'true', + BeforeCatch : 'true', + BeforeElse : 'true', + IndentBraces : 'false', SplitEmptyFunction: 'false' } ... - diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 000000000..9eb010608 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,19 @@ +--- +name: Bug report +about: Help me help you... +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +If you are experiencing a crash, provide a backtrace (GDB or similar). + +*How to Reproduce** + +Please provide a specific description of how to reproduce the issue or source code that can be compiled and executed. Please attach a file/project that is easy to compile, don't copy and paste code snippets! + +Even better, create a Pull Request with a failing unit test. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 000000000..021458556 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 000000000..27c6ae66a --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,11 @@ + diff --git a/.github/workflows/cmake_ubuntu.yml b/.github/workflows/cmake_ubuntu.yml index 3c0889ba7..aaf5f628d 100644 --- a/.github/workflows/cmake_ubuntu.yml +++ b/.github/workflows/cmake_ubuntu.yml @@ -19,13 +19,13 @@ jobs: steps: - uses: actions/checkout@v2 - + - name: Install Conan id: conan uses: turtlebrowser/get-conan@main with: version: 1.59.0 - + - name: Create default profile run: conan profile new default --detect @@ -50,11 +50,10 @@ jobs: shell: bash working-directory: ${{github.workspace}}/build run: cmake --build . --config ${{env.BUILD_TYPE}} - + - name: run test (Linux) working-directory: ${{github.workspace}}/build run: ./tests/behaviortree_cpp_test - + - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 - diff --git a/.github/workflows/cmake_windows.yml b/.github/workflows/cmake_windows.yml index aed23392f..192fdcac6 100644 --- a/.github/workflows/cmake_windows.yml +++ b/.github/workflows/cmake_windows.yml @@ -18,16 +18,14 @@ jobs: os: [windows-latest] steps: - - uses: actions/checkout@v2 - + - uses: actions/checkout@v4 + - name: Install Conan id: conan uses: turtlebrowser/get-conan@main - with: - version: 1.59.0 - + - name: Create default profile - run: conan profile new default --detect + run: conan profile detect - name: Create Build Environment # Some projects don't allow in-source building, so create a separate build directory @@ -47,8 +45,7 @@ jobs: working-directory: ${{github.workspace}}/build shell: bash run: cmake --build . --config ${{env.BUILD_TYPE}} - + - name: run test (Windows) working-directory: ${{github.workspace}}/build run: $env:PATH+=";${{env.BUILD_TYPE}}"; tests/${{env.BUILD_TYPE}}/behaviortree_cpp_test.exe - diff --git a/.github/workflows/pixi.yaml b/.github/workflows/pixi.yaml index f6269ee7b..bf156ec1d 100644 --- a/.github/workflows/pixi.yaml +++ b/.github/workflows/pixi.yaml @@ -2,57 +2,21 @@ name: Pixi (conda) on: [push, pull_request] -env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) - # Note if this value is changed, has to be manually updated in the `windows-latest` tests_command - BUILD_TYPE: Release - jobs: pixi_conda_build: strategy: matrix: - include: - - os: windows-latest - build_depend: vs2022_win-64=19.* - tests_command: "'PATH=\\\"$PATH;build/Release\\\" build/tests/Release/behaviortree_cpp_test.exe'" - - os: ubuntu-latest - build_depend: "gxx=12.2.*" - tests_command: "./build/tests/behaviortree_cpp_test" + os: + - windows-latest + - ubuntu-latest runs-on: ${{ matrix.os }} steps: # Pixi is the tool used to create/manage conda environment - - uses: prefix-dev/setup-pixi@v0.4.1 - with: - pixi-version: v0.7.0 - locked: false - frozen: false - run-install: false - manifest-path: build-env/pixi.yaml - - name: Make pixi workspace - run: | - pixi init build-env - - name: Install dependencies - working-directory: ${{github.workspace}}/build-env - run: | - pixi add cmake zeromq=4.3.4 gtest=1.12.* gmock=1.12.* sqlite=3.40.* ${{ matrix.build-depend }} - pixi install - - name: Create Build Directory - working-directory: ${{github.workspace}}/build-env - run: mkdir build - uses: actions/checkout@v3 + - uses: prefix-dev/setup-pixi@v0.4.1 with: - path: build-env/BehaviorTree.CPP + pixi-version: v0.16.1 - name: Build - working-directory: ${{github.workspace}}/build-env - run: | - pixi task add build "cd build; cmake ../BehaviorTree.CPP -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}; cmake --build . --parallel --config ${{env.BUILD_TYPE}}" - pixi run build + run: pixi run build - name: Run tests - working-directory: ${{github.workspace}}/build-env - run: | - pixi task add tests ${{ matrix.tests_command }} - pixi run tests - - - - \ No newline at end of file + run: pixi run test diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 000000000..6095e0861 --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,14 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [master] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.1 diff --git a/.github/workflows/ros2-rolling.yaml b/.github/workflows/ros2-rolling.yaml new file mode 100644 index 000000000..cb5004506 --- /dev/null +++ b/.github/workflows/ros2-rolling.yaml @@ -0,0 +1,17 @@ +name: ros2-rolling + +on: [push, pull_request] + +jobs: + industrial_ci: + strategy: + matrix: + env: + - {ROS_DISTRO: rolling, ROS_REPO: main} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: 'ros-industrial/industrial_ci@master' + env: ${{matrix.env}} + with: + package-name: plotjuggler diff --git a/.github/workflows/ros2.yaml b/.github/workflows/ros2.yaml index 23422b835..afdccc466 100644 --- a/.github/workflows/ros2.yaml +++ b/.github/workflows/ros2.yaml @@ -8,11 +8,11 @@ jobs: matrix: env: - {ROS_DISTRO: humble, ROS_REPO: main} - - {ROS_DISTRO: rolling, ROS_REPO: main} + - {ROS_DISTRO: iron, ROS_REPO: main} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 - uses: 'ros-industrial/industrial_ci@master' env: ${{matrix.env}} with: - package-name: behaviortree_cpp + package-name: plotjuggler diff --git a/.gitignore b/.gitignore index 79bec0c7a..cba22ead7 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,8 @@ CMakeSettings.json # OSX junk .DS_Store + +# pixi environments +.pixi + +CMakeUserPresets.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..e6ace8262 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,44 @@ + +# To use: +# +# pre-commit run -a +# +# Or: +# +# pre-commit install # (runs every time you commit in git) +# +# To update this file: +# +# pre-commit autoupdate +# +# See https://github.com/pre-commit/pre-commit + +exclude: ^3rdparty/|3rdparty|^include/behaviortree_cpp/contrib/ +repos: + + # Standard hooks + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-added-large-files + - id: check-ast + - id: check-case-conflict + - id: check-docstring-first + - id: check-merge-conflict + - id: check-symlinks + - id: check-xml + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + exclude_types: [svg] + - id: mixed-line-ending + - id: trailing-whitespace + exclude_types: [svg] + - id: fix-byte-order-marker + + # CPP hooks + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v17.0.6 + hooks: + - id: clang-format + args: ['-fallback-style=none', '-i'] diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a9cb4cb0d..3abc9b986 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,52 @@ Changelog for package behaviortree_cpp ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +4.6.0 (2024-04-28) +------------------ +* add tutorial 19 about the global blackboard +* renamed examples to match website +* Update TestNode and the corresponding tutorial +* bug fixes related to sequence_id and unit tests added +* Add string concatenation operator to scripting (`#802 `_) +* Add library alias for BT::behaviortree_cpp (`#808 `_) +* add Time Stamped blackboard (`#805 `_) +* add additional information and functionality to SQLiteLogger +* add syntax for entries in the root blackboard ("@" prefix) +* Fix/pixi build (`#791 `_) +* fix unit tests in Windows +* fix windows compilation +* Update cmake_windows.yml +* Deprecate Balckboard::clear(). Issue `#794 `_ +* Support string vector conversion for ports (`#790 `_) +* add more convertToString for integers +* warn about overwritten enums +* fix ambiguous to_json +* Extend unit test for blackboard backup to run the second tree (`#789 `_) +* json convertion changed and +* issue `#755 `_ : add backchaining test and change reactive nodes checks (`#770 `_) +* Update switch_node.h +* test moved and port remapping fixed +* Create pull_request_template.md + +* adding pre-commit +* handle enums conversions is assignment +* Contributors: Davide Faconti, Sean Geles, Sebastian Castro, Victor Massagué Respall, avikus-seonghyeon.kwon, tony-p + +4.5.2 (2024-03-07) +------------------ +* bugfix: string to enum/integer/boolean in scripts +* bug fix in scripting comparison +* added more pretty-prints to demangler +* fixes and checks in default values, based on PR `#773 `_ +* Initialize std::atomic_bool (`#772 `_) +* Fix issue `#767 `_ and `#768 `_ +* updated default port syntax: "{=}" +* new default port capability: blackbard entries +* fix issue `#757 `_ : skipped nodes should not call post-condition ALWAYS +* Merge pull request `#756 `_ from imere/imere-patch-1 +* fix(test): Typo in gtest_blackboard.cpp +* Contributors: Davide Faconti, Lu Z, Marq Rasmussen + 4.5.1 (2024-01-23) ------------------ * Support enums and real numbers in Node Switch diff --git a/CMakeLists.txt b/CMakeLists.txt index 1863b80de..d0ca68dd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.16.3) # version on Ubuntu Focal -project(behaviortree_cpp VERSION 4.5.1 LANGUAGES C CXX) +project(behaviortree_cpp VERSION 4.6.0 LANGUAGES C CXX) set(CMAKE_CONFIG_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CONFIG_PATH}") @@ -19,9 +19,10 @@ endif() if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS -DWIN32_LEAN_AND_MEAN) else() - add_definitions(-Wpedantic) + add_definitions(-Wpedantic -fno-omit-frame-pointer) endif() + #---- project configuration ---- option(BTCPP_SHARED_LIBS "Build shared libraries" ON) option(BTCPP_BUILD_TOOLS "Build commandline tools" ON) @@ -96,13 +97,15 @@ list(APPEND BT_SOURCE src/actions/test_node.cpp src/actions/sleep_node.cpp + src/actions/updated_action.cpp src/decorators/delay_node.cpp src/decorators/inverter_node.cpp src/decorators/repeat_node.cpp src/decorators/retry_node.cpp - src/decorators/timeout_node.cpp src/decorators/subtree_node.cpp + src/decorators/timeout_node.cpp + src/decorators/updated_decorator.cpp src/controls/if_then_else_node.cpp src/controls/fallback_node.cpp @@ -160,6 +163,7 @@ target_link_libraries(${BTCPP_LIBRARY} Threads::Threads ${CMAKE_DL_LIBS} $ + PUBLIC ${BTCPP_EXTRA_LIBRARIES} ) @@ -183,6 +187,8 @@ else() target_compile_options(${BTCPP_LIBRARY} PRIVATE -Wall -Wextra) endif() +add_library(BT::${BTCPP_LIBRARY} ALIAS ${BTCPP_LIBRARY}) + ############################################################# message( STATUS "BTCPP_LIB_DESTINATION: ${BTCPP_LIB_DESTINATION} " ) message( STATUS "BTCPP_INCLUDE_DESTINATION: ${BTCPP_INCLUDE_DESTINATION} " ) @@ -220,4 +226,3 @@ INSTALL( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ FILES_MATCHING PATTERN "*.h*") export_btcpp_package() - diff --git a/LICENSE b/LICENSE index f60806f21..e55a7557f 100644 --- a/LICENSE +++ b/LICENSE @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/README.md b/README.md index d10662562..34ea88641 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![LGTM Grade](https://img.shields.io/lgtm/grade/cpp/github/BehaviorTree/BehaviorTree.CPP)](https://lgtm.com/projects/g/BehaviorTree/BehaviorTree.CPP/context:cpp) ![Discourse topics](https://img.shields.io/discourse/topics?server=https%3A%2F%2Fdiscourse.behaviortree.dev) -# BehaviorTree.CPP 4.5 +# BehaviorTree.CPP 4.6

@@ -41,14 +41,6 @@ You can learn about the main concepts, the API and the tutorials here: https://w If the documentation doesn't answer your questions and/or you want to connect with the other **BT.CPP** users, visit [our forum](https://github.com/BehaviorTree/BehaviorTree.CPP/discussions) -## Previous version - -Version 3.8 of the software can be found in the branch -[v3.8](https://github.com/BehaviorTree/BehaviorTree.CPP/tree/v3.8). - -That branch might receive bug fixes, but the new features will be implemented -only in the master branch. - # GUI Editor Editing a BehaviorTree is as simple as editing an XML file in your favorite text editor. @@ -89,6 +81,11 @@ cmake ../BehaviorTree.CPP cmake --build . --parallel ``` +If you want to build in a [pixi](https://pixi.sh/) project (conda virtual environment). +``` +pixi run build +``` + If you want to use BT.CPP in your application, please refer to the example here: https://github.com/BehaviorTree/btcpp_sample . @@ -101,6 +98,13 @@ You can contact the primary author, **dfaconti@aurynrobotics.com**, to discuss y [![Star History Chart](https://api.star-history.com/svg?repos=BehaviorTree/BehaviorTree.CPP&type=Date)](https://star-history.com/#BehaviorTree/BehaviorTree.CPP&Date) +## Previous version + +Version 3.8 of the software can be found in the branch +[v3.8](https://github.com/BehaviorTree/BehaviorTree.CPP/tree/v3.8). + +That branch might receive bug fixes, but the new features will be implemented +only in the master branch. # License diff --git a/cmake/conan.cmake b/cmake/conan.cmake index 33512fcee..3fa9a26ba 100644 --- a/cmake/conan.cmake +++ b/cmake/conan.cmake @@ -146,7 +146,7 @@ macro(_conan_detect_compiler) set(COMPILER_VERSION ${MAJOR}) else() set(COMPILER_VERSION ${MAJOR}.${MINOR}) - endif() + endif() elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL QCC) set(_CONAN_SETTING_COMPILER qcc) set(COMPILER_VERSION ${MAJOR}.${MINOR}) @@ -180,7 +180,7 @@ macro(_conan_detect_compiler) set(COMPILER_VERSION ${MAJOR}) else() set(COMPILER_VERSION ${MAJOR}.${MINOR}) - endif() + endif() set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION}) @@ -190,7 +190,7 @@ macro(_conan_detect_compiler) set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) endif () elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang - AND NOT "${CMAKE_${LANGUAGE}_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC" + AND NOT "${CMAKE_${LANGUAGE}_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC" AND NOT "${CMAKE_${LANGUAGE}_SIMULATE_ID}" STREQUAL "MSVC") string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) @@ -203,7 +203,7 @@ macro(_conan_detect_compiler) set(COMPILER_VERSION ${MAJOR}) else() set(COMPILER_VERSION ${MAJOR}.${MINOR}) - endif() + endif() set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION}) @@ -219,8 +219,8 @@ macro(_conan_detect_compiler) set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) endif () elseif(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL MSVC - OR (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang - AND "${CMAKE_${LANGUAGE}_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC" + OR (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang + AND "${CMAKE_${LANGUAGE}_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC" AND "${CMAKE_${LANGUAGE}_SIMULATE_ID}" STREQUAL "MSVC")) set(_VISUAL "Visual Studio") @@ -475,7 +475,7 @@ function(conan_cmake_autodetect detected_settings) endfunction() macro(conan_parse_arguments) - set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS NO_LOAD NO_OUTPUT_DIRS + set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS NO_LOAD NO_OUTPUT_DIRS OUTPUT_QUIET NO_IMPORTS SKIP_STD) set(oneValueArgs CONANFILE ARCH BUILD_TYPE INSTALL_FOLDER OUTPUT_FOLDER CONAN_COMMAND) set(multiValueArgs DEBUG_PROFILE RELEASE_PROFILE RELWITHDEBINFO_PROFILE MINSIZEREL_PROFILE @@ -656,11 +656,11 @@ function(conan_cmake_install) if(DEFINED NO_IMPORTS) set(NO_IMPORTS --no-imports) endif() - set(install_args install ${PATH_OR_REFERENCE} ${REFERENCE} ${UPDATE} ${NO_IMPORTS} ${REMOTE} - ${LOCKFILE} ${LOCKFILE_OUT} ${LOCKFILE_NODE_ID} ${INSTALL_FOLDER} - ${OUTPUT_FOLDER} ${GENERATOR} ${BUILD} ${ENV} ${ENV_HOST} ${ENV_BUILD} - ${OPTIONS} ${OPTIONS_HOST} ${OPTIONS_BUILD} ${PROFILE} ${PROFILE_HOST} - ${PROFILE_BUILD} ${SETTINGS} ${SETTINGS_HOST} ${SETTINGS_BUILD} + set(install_args install ${PATH_OR_REFERENCE} ${REFERENCE} ${UPDATE} ${NO_IMPORTS} ${REMOTE} + ${LOCKFILE} ${LOCKFILE_OUT} ${LOCKFILE_NODE_ID} ${INSTALL_FOLDER} + ${OUTPUT_FOLDER} ${GENERATOR} ${BUILD} ${ENV} ${ENV_HOST} ${ENV_BUILD} + ${OPTIONS} ${OPTIONS_HOST} ${OPTIONS_BUILD} ${PROFILE} ${PROFILE_HOST} + ${PROFILE_BUILD} ${SETTINGS} ${SETTINGS_HOST} ${SETTINGS_BUILD} ${CONF} ${CONF_HOST} ${CONF_BUILD}) string(REPLACE ";" " " _install_args "${install_args}") @@ -764,12 +764,12 @@ function(conan_cmake_lock_create) set(BASE --base) endif() set(lock_create_Args lock create ${PATH} ${REFERENCE} ${UPDATE} ${BASE} ${REMOTE} ${LOCKFILE} ${LOCKFILE_OUT} ${LOCKFILE_NODE_ID} ${INSTALL_FOLDER} - ${GENERATOR} ${BUILD} ${ENV} ${ENV_HOST} ${ENV_BUILD} ${OPTIONS} ${OPTIONS_HOST} ${OPTIONS_BUILD} + ${GENERATOR} ${BUILD} ${ENV} ${ENV_HOST} ${ENV_BUILD} ${OPTIONS} ${OPTIONS_HOST} ${OPTIONS_BUILD} ${PROFILE} ${PROFILE_HOST} ${PROFILE_BUILD} ${SETTINGS} ${SETTINGS_HOST} ${SETTINGS_BUILD}) string(REPLACE ";" " " _lock_create_Args "${lock_create_Args}") message(STATUS "Conan executing: ${CONAN_CMD} ${_lock_create_Args}") - + if(ARGS_OUTPUT_QUIET) set(OUTPUT_OPT OUTPUT_QUIET) endif() @@ -1083,7 +1083,7 @@ function(conan_cmake_profile) set(profileMultiValueArgs SETTINGS OPTIONS CONF ENV BUILDENV RUNENV TOOL_REQUIRES) cmake_parse_arguments(ARGS "" "${profileOneValueArgs}" "${profileMultiValueArgs}" ${ARGN}) - if(DEFINED ARGS_FILEPATH) + if(DEFINED ARGS_FILEPATH) set(_FN "${ARGS_FILEPATH}") else() set(_FN "${CMAKE_CURRENT_BINARY_DIR}/profile") diff --git a/conanfile.txt b/conanfile.txt index 56dd97006..7b81d1d6d 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,5 +1,5 @@ [requires] -gtest/1.12.1 +gtest/1.14.0 zeromq/4.3.4 sqlite3/3.40.1 diff --git a/contributors.txt b/contributors.txt index 578b30da4..83ef7a03d 100644 --- a/contributors.txt +++ b/contributors.txt @@ -1,4 +1,3 @@ Davide Faconti Michele Colledanchise Rocco Santomo - diff --git a/convert_v3_to_v4.py b/convert_v3_to_v4.py index 027eebbca..0866ffcde 100755 --- a/convert_v3_to_v4.py +++ b/convert_v3_to_v4.py @@ -170,4 +170,4 @@ class ArgsType(typing.NamedTuple): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/docs/substitution_sample.json b/docs/substitution_sample.json index b9d58de03..fd908e727 100644 --- a/docs/substitution_sample.json +++ b/docs/substitution_sample.json @@ -1,15 +1,15 @@ { - "TestNodeConfigs": { - "MyTest": { - "async_delay": 2000, - "return_status": "SUCCESS", - "post_script": "msg ='message SUBSTITUED'" - } - }, - - "SubstitutionRules": { - "mysub/action_*": "TestAction", - "talk": "TestSaySomething", - "last_action": "MyTest" + "TestNodeConfigs": { + "MyTest": { + "async_delay": 2000, + "return_status": "SUCCESS", + "post_script": "msg ='message SUBSTITUED'" } -} \ No newline at end of file + }, + + "SubstitutionRules": { + "mysub/action_*": "TestAction", + "talk": "TestSaySomething", + "last_action": "MyTest" + } +} diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 62f4b0fdb..08e68cf3e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -54,27 +54,37 @@ CompileExample("t07_load_multiple_xml") CompileExample("t08_additional_node_args") CompileExample("t09_scripting") CompileExample("t10_observer") -CompileExample("t11_replace_rules") -if(BTCPP_GROOT_INTERFACE AND BTCPP_SQLITE_LOGGING) -CompileExample("t12_groot_howto") -CompileExample("generate_log") +if(BTCPP_GROOT_INTERFACE) + CompileExample("t11_groot_howto") endif() +CompileExample("t12_default_ports") +CompileExample("t13_access_by_ref") +CompileExample("t14_subtree_model") +CompileExample("t15_nodes_mocking") +CompileExample("t16_global_blackboard") +CompileExample("t17_blackboard_backup") +CompileExample("t18_waypoints") + CompileExample("ex01_wrap_legacy") CompileExample("ex02_runtime_ports") -CompileExample("ex04_waypoints") -CompileExample("ex05_subtree_model") -CompileExample("ex06_access_by_ptr") -CompileExample("t13_plugin_executor") +if(BTCPP_SQLITE_LOGGING) + CompileExample("ex03_sqlite_log") +endif() + + +############ Create plugin and executor in folder plugin_example ########## -############ Create plugin for tutorial 13 ########## # library must be SHARED -add_library(t13_plugin_action SHARED t13_plugin_action.cpp ) +add_library(test_plugin_action SHARED plugin_example/plugin_action.cpp ) # you must set the definition BT_PLUGIN_EXPORT -target_compile_definitions(t13_plugin_action PRIVATE BT_PLUGIN_EXPORT ) -# remove the "lib" prefix. Name of the file will be t13_plugin_action.so -set_target_properties(t13_plugin_action PROPERTIES PREFIX "") +target_compile_definitions(test_plugin_action PRIVATE BT_PLUGIN_EXPORT ) +# remove the "lib" prefix. Name of the file will be test_plugin_action.so +set_target_properties(test_plugin_action PROPERTIES PREFIX "") # link dependencies as usual -target_link_libraries(t13_plugin_action ${BTCPP_LIBRARY} ) +target_link_libraries(test_plugin_action ${BTCPP_LIBRARY} ) + +add_executable(test_plugin_executor plugin_example/plugin_executor.cpp ) +target_link_libraries(test_plugin_executor ${BTCPP_LIBRARY}) diff --git a/examples/broken_sequence.cpp b/examples/broken_sequence.cpp deleted file mode 100644 index 032d242f9..000000000 --- a/examples/broken_sequence.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "Blackboard/blackboard_local.h" -#include "behaviortree_cpp/behavior_tree.h" -#include "behaviortree_cpp/bt_factory.h" - -using namespace BT; - -NodeStatus SayHello() -{ - printf("hello\n"); - return NodeStatus::SUCCESS; -} - -class ActionTestNode : public ActionNode -{ -public: - ActionTestNode(const std::string& name) : ActionNode(name) - {} - - NodeStatus tick() override - { - time_ = 5; - stop_loop_ = false; - int i = 0; - while (!stop_loop_ && i++ < time_) - { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - return NodeStatus::SUCCESS; - } - - virtual void halt() override - { - stop_loop_ = true; - } - -private: - int time_; - std::atomic_bool stop_loop_; -}; - -int main() -{ - BT::SequenceNode root("root"); - BT::SimpleActionNode action1("say_hello", std::bind(SayHello)); - ActionTestNode action2("async_action"); - - root.addChild(&action1); - root.addChild(&action2); - - int count = 0; - - NodeStatus status = NodeStatus::RUNNING; - - while (status == NodeStatus::RUNNING) - { - status = root.executeTick(); - - std::cout << count++ << " : " << root.status() << " / " << action1.status() << " / " - << action2.status() << std::endl; - - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - - return 0; -} -// Output -/* - -hello -0 : RUNNING / SUCCESS / RUNNING -hello -1 : RUNNING / SUCCESS / RUNNING -hello -2 : RUNNING / SUCCESS / RUNNING -hello -3 : RUNNING / SUCCESS / RUNNING -hello -4 : RUNNING / SUCCESS / RUNNING -hello -5 : SUCCESS / IDLE / IDLE - -*/ diff --git a/examples/ex01_wrap_legacy.cpp b/examples/ex01_wrap_legacy.cpp index 80abf64f7..b6fb195da 100644 --- a/examples/ex01_wrap_legacy.cpp +++ b/examples/ex01_wrap_legacy.cpp @@ -20,7 +20,7 @@ class MyLegacyMoveTo bool go(Point3D goal) { printf("Going to: %f %f %f\n", goal.x, goal.y, goal.z); - return true; // true means success in my legacy code + return true; // true means success in my legacy code } }; @@ -33,7 +33,7 @@ Point3D convertFromString(StringView key) { // three real numbers separated by semicolons auto parts = BT::splitString(key, ';'); - if (parts.size() != 3) + if(parts.size() != 3) { throw RuntimeError("invalid input)"); } @@ -46,7 +46,7 @@ Point3D convertFromString(StringView key) return output; } } -} // namespace BT +} // namespace BT // clang-format off static const char* xml_text = R"( @@ -81,7 +81,7 @@ int main() // Register the lambda with BehaviorTreeFactory::registerSimpleAction - PortsList ports = {BT::InputPort("goal")}; + PortsList ports = { BT::InputPort("goal") }; factory.registerSimpleAction("MoveTo", MoveToWrapperWithLambda, ports); auto tree = factory.createTreeFromText(xml_text); diff --git a/examples/ex02_runtime_ports.cpp b/examples/ex02_runtime_ports.cpp index d6e645dc2..25a13beeb 100644 --- a/examples/ex02_runtime_ports.cpp +++ b/examples/ex02_runtime_ports.cpp @@ -17,8 +17,8 @@ static const char* xml_text = R"( class ThinkRuntimePort : public BT::SyncActionNode { public: - ThinkRuntimePort(const std::string& name, const BT::NodeConfig& config) : - BT::SyncActionNode(name, config) + ThinkRuntimePort(const std::string& name, const BT::NodeConfig& config) + : BT::SyncActionNode(name, config) {} BT::NodeStatus tick() override @@ -31,15 +31,15 @@ class ThinkRuntimePort : public BT::SyncActionNode class SayRuntimePort : public BT::SyncActionNode { public: - SayRuntimePort(const std::string& name, const BT::NodeConfig& config) : - BT::SyncActionNode(name, config) + SayRuntimePort(const std::string& name, const BT::NodeConfig& config) + : BT::SyncActionNode(name, config) {} // You must override the virtual function tick() BT::NodeStatus tick() override { auto msg = getInput("message"); - if (!msg) + if(!msg) { throw BT::RuntimeError("missing required input [message]: ", msg.error()); } @@ -54,12 +54,12 @@ int main() //-------- register ports that might be defined at runtime -------- // more verbose way - PortsList think_ports = {BT::OutputPort("text")}; + PortsList think_ports = { BT::OutputPort("text") }; factory.registerBuilder( CreateManifest("ThinkRuntimePort", think_ports), CreateBuilder()); // less verbose way - PortsList say_ports = {BT::InputPort("message")}; + PortsList say_ports = { BT::InputPort("message") }; factory.registerNodeType("SayRuntimePort", say_ports); factory.registerBehaviorTreeFromText(xml_text); diff --git a/examples/ex03_sqlite_log.cpp b/examples/ex03_sqlite_log.cpp new file mode 100644 index 000000000..9ea8c028b --- /dev/null +++ b/examples/ex03_sqlite_log.cpp @@ -0,0 +1,149 @@ +#include "dummy_nodes.h" +#include "behaviortree_cpp/bt_factory.h" +#include "behaviortree_cpp/loggers/bt_sqlite_logger.h" +#include "behaviortree_cpp/xml_parsing.h" + +struct TaskA +{ + int type; + std::string name; +}; + +struct TaskB +{ + double value; + std::string name; +}; + +using Command = std::variant; + +// Simple Action that updates an instance of Position2D in the blackboard +class SetTask : public BT::SyncActionNode +{ +public: + SetTask(const std::string& name, const BT::NodeConfig& config) + : BT::SyncActionNode(name, config) + {} + + BT::NodeStatus tick() override + { + auto type = getInput("type").value(); + if(type == "A") + { + setOutput("task", TaskA{ 43, type }); + } + else if(type == "B") + { + setOutput("task", TaskB{ 3.14, type }); + } + return BT::NodeStatus::SUCCESS; + } + + static BT::PortsList providedPorts() + { + return { BT::InputPort("type"), BT::OutputPort("task") }; + } + +private: +}; + +// clang-format off + +static const char* xml_text = R"( + + + + + +