Giter VIP home page Giter VIP logo

behavior-tree's Introduction

A lightweight behavior tree library in C++.

NEWS!

💥 Thanks to Davide Faconti there is now a more sophisticated version of the library. The new version of this library is available here. There is also GUI available here.

Our book Behavior Trees in Robotics and AI, published by CRC Press Taylor & Francis, is available for purchase (ebook and hardcover) on the CRC Press Store or Amazon. The Preprint version (free) is available here: https://arxiv.org/abs/1709.00084

Tutorials available at https://btirai.github.io/












portfolio_view BT++

License MIT Version

REFERENCE

Please refer to the following paper when using the library:

How Behavior Trees Modularize Hybrid Control Systems and Generalize Sequential Behavior Compositions, the Subsumption Architecture, and Decision Trees. Michele Colledanchise and Petter Ogren. IEEE Transaction on Robotics 2017.

bibtex entry:

@ARTICLE{TRO17Colledanchise,
author={M. Colledanchise and P. Ögren},
journal={IEEE Transactions on Robotics},
title={{How Behavior Trees Modularize Hybrid Control Systems and Generalize Sequential Behavior Compositions, the Subsumption Architecture, and Decision Trees}},
year={2017},
volume={33},
number={2},
pages={372-389},
keywords={Computer architecture;Decision trees;High definition video;Robot control;Switches;Behavior trees (BTs);decision trees;finite state machines (FSMs);hybrid dynamical systems (HDSs);modularity;sequential behavior compositions;subsumption architecture},
doi={10.1109/TRO.2016.2633567},
ISSN={1552-3098},
month={April},}

DEPENDENCIES

Regarding visualization purposes:

Regarding tests:

BT NODES SUPPORT

Fallback: Fallback nodes are used to find and execute the first child that does not fail. A Selector node will return immediately with a status code of success or running when one of its children returns success or running. The children are ticked in order of importance, from left to right.

Sequence: Sequence nodes are used to find and execute the first child that has not yet succeeded. A sequence node will return immediately with a status code of failure or running when one of its children returns failure or running. The children are ticked in order, from left to right.

Parallel: The parallel node ticks its children in parallel and returns success if M ≤ N children return success, it returns failure if N − M + 1 children return failure, and it returns running otherwise.

Decorator: The decorator node manipulates the return status of its child according to the policy defined by the user (e.g. it inverts the success/failure status of the child). In this library the decorators implemented are the two common ones: Decorator Retry which retries the execution of a node if this fails; and Decorator Negation That inverts the Success/Failure outcome.

Action: An Action node performs an action, and returns Success if the action is completed, Failure if it can not be completed and Running if completion is under way.

Condition: A Condition node determines if a desired condition c has been met. Conditions are technically a subset of the Actions, but are given a separate category and graphical symbol to improve readability of the BT and emphasize the fact that they never return running and do not change any internal states/variables of the BT.

A user manual is available in the project folder (BTppUserManual.pdf).

SETUP

The first step to use BT++ is to retrieve its source code. You can either download it here (https://github.com/miccol/Behavior-Tree) or clone the repository:

$ cd /path/to/folder
$ git clone https://github.com/miccol/Behavior−Tree.git

Once you have the repository, compile the library:

$ cd /path/to/folder/
$ mkdir ./build
$ cd build
$ cmake ..
$ make

NOTE In case you get the following error:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: GLUT_Xmu_LIBRARY (ADVANCED)

please see solution here. Thanks miquelramirez for this.

Check the installation by running a sample example.

$ cd /path/to/folder/
$ cd build/sample
$ ./btpp_example

INSTALL THE LIBRARY SYSTEM-WIDE (tested on Ubuntu 14.04 and 16.04)

If you would like to install the library system-wide, then run:

$ cd /path/to/folder/
$ cd build
$ sudo make install

On Ubuntu, this will install the library (libbtpp.so) in /usr/local/lib.
In an external project, just call in your CMakeLists 'find_package(BTpp)' to find the library.
The include directory is defined as BTpp_INCLUDE_DIRS and the libraries to link as BTpp_LIBRARIES.
The repository my-behavior-tree-project shows an example on how to use the library once system-wide installed.

CREATE YOUR OWN ACTION NODE

  1. Implement your action node class extending the abstract class BT::ActionNode.
  2. Implement the method BT::ReturnStatus Tick() with the code you want to execute while the action is running. Use the method is_halted() to check if the action has been prempted. When the execution of your action finished, return BT::SUCCESS or BT::FAILURE accordingly.
  3. Implement the method void Halt() with the code you want to execute when the action gets preempted (halted). See the file src/example.cpp for an example.

CREATE YOUR OWN CONDITION NODE

  1. Implement your condition node class extending the abstract class BT::ConditionNode.
  2. Implement the method BT::ReturnStatus Tick() with the code you want to execute to check the condition. Return BT::SUCCESS or BT::FAILURE accordingly.
    See the file src/example.cpp for an example.

NOTES

In case you are puzzled about why a sequence (or fallback) node with 2 or more actions as children never get past the first action, see this discussion.

LICENSE

The MIT License (MIT)

Copyright (c) 2014-2018 Michele Colledanchise

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 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.

behavior-tree's People

Contributors

cmcghan avatar ewerlopes avatar miccol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

behavior-tree's Issues

Dependencies?

Hi;

I have been taking a look in this project code these days... The organization of the code is great, by the way. However, I realized there are some header files missing. For instance, there is no "Action/ActionNodeTemplate.h". So, I would like to know if there is any plan of yours for continuing improving the project any time soon.

Regards.

I can't use xilb.

your source code is dependent on xlib. But in windows OS that is not supported. Can you fix it?

coding style

Hi,

first of all, thanks for making this code available.
If I can make a suggestions, there are few coding styles that can help improving the maintenability and readability of the code.

  1. Don't expose constants such has the node name and type as public member.
    You don't want the user to be able to change them. Make the private and provide public getters.

  2. use naming conventions instead of CamelCase everywhere. I would recommend https://google.github.io/styleguide/cppguide.html

  3. Remove the member NodeType Type. You are just duplicating the information with no real benefit for maintainers and users.

I am working on these improvements here: https://github.com/facontidavide/Behavior-Tree

Regards

Davide

Improving Reactivity using Implicit Sequences is unclear

Hi Michele,
I am new to BTs and AI in general so let me say your book as been extremely helpful. I am trying to understand the design principle "Improving Reactivity using Implicit Sequences". Figure 3.3:
capture
This is Figure 3.2 rearranged so that if the agent has already passed through the door, it doesn't try to open or unlock the door. What I don't understand in Figure 3.3 is that if the Open Door action returns success then the whole fallback node would return success and the agent never passes through the door. Same with unlocking the door--the unlock action (if performed) would return success when complete causing the fallback node to return success even though the agent never opened the door or went though it. It almost seems like it should be like this:
reactivebt
which follows the PPA methodology nicely. Am I missing something? Thanks again--this is awesome!

Jason

```make install``` rule fails

After completing the build, the command

sudo make install

fails with the following output

Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/BTpp/libBTpp.a
-- Installing: /usr/local/lib/BTpp/btpp-targets.cmake
-- Installing: /usr/local/lib/BTpp/btpp-targets-release.cmake
CMake Error at cmake_install.cmake:59 (file):
  file INSTALL cannot find
  "/home/bowman/Sandboxes/libbtpp/btpp-config.cmake".


Makefile:61: recipe for target 'install' failed

Looks like the support for pkg-config is not complete in the master branch?

PS: Also, the installation rules for headers seem to be broken/incomplete on master.

Question: is a thread per node really necessary?

Hi,

I noticed that a single thread is created for each node. This seems like a waste of resources in large systems with potentially dozens of nodes.

I guess that either a custom (simple) scheduler or a coroutine library might be able to do the job.
Considering the overhead of the context switching, I have the feeling that even traversing the entire tree might be faster.

Is there any reason I am not aware of to use a separate thread per node?

Cheers

Davide

Hiccup building the library on Ubuntu 16.04

Hello there,

the build instructions given on Readme.md fail on Unbuntu 16.04 after installing the listed dependencies (GL, GLUT and googletest). CMake aborts with the following output:

-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found X11: /usr/lib/x86_64-linux-gnu/libX11.so
-- Found GTest: /usr/local/lib/libgtest.a  
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found GLUT: /usr/lib/x86_64-linux-gnu/libglut.so  
-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libGL.so  
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
GLUT_Xmu_LIBRARY (ADVANCED)
    linked by target "btpp_gtest" in directory /home/bowman/Sandboxes/libbtpp
    linked by target "btpp_example" in directory /home/bowman/Sandboxes/libbtpp
    linked by target "BTpp" in directory /home/bowman/Sandboxes/libbtpp

The error is obscure, but fortunately well documented. Following the advice given in the link, namely to install the packages libxmu-dev and libxi-dev allows CMake to succeed.

I'd advise to add a note on this to the README.md file, for future reference.

Thanks a lot for making the library available @miccol!

ControlNodes and BT::RUNNING

This is a heads up about something that I want to discuss in more detail in a future PR.

I am looking at the code of the main ControlNodes and I am trying to understand what happens when a child returns RUNNING.

Apparently, when a child returns RUNNING, these Nodes halt the following children.

On the other hand, FallbackNodeWithMemory and SequenceNodeWithMemory never invoke haltChildren, in any case.

Is that intentional?

In my opinion:

  • Fallback with or without memory should call haltChildren(i+1) only when child return SUCCESS.
  • Sequence with or without memory should call haltChildren(i+1) only when child return FAILURE.

JSON <-> BT++ convertion

Hi Michele,

I noticed you mentioned :

"I am in contact with the developer of Behavior3.com I also had in mind of doing a parsing from JSON files"

I am thinking to do the same, and I would like (if you want) to collaborate this time and avoid replicated work.
Few preliminary thoughts:

  1. To generate a JSON from a BT++ is pretty easy.
  2. To generate a BT++ from a JSON file is, on the other hand, slightly more complicated, because it requires a proper factory and any user defined action / condition will need to register an allocating method to this factory.

I have a design in mind, but I wonder if you already have some idea or not about it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.