Sarafun Behavior Trees package  1
Behavior trees for the SARAFun project
 All Data Structures Namespaces Functions Variables Enumerations Enumerator
Sarafun Behavior Trees package Documentation

This repository contains code that showcases a potential application of behavior trees. It provides:

It depends on a modified version of the ROS-Behavior-Tree package by Michele Colledanchise. The main changes are

The modified package is found here.

Instalation

Compiler

There is an issue with gcc 4.8 that prevents compiling the json parser used in this project. So first, make sure you have a more recent version of gcc. In ubuntu this can be achieved by doing ``` $ sudo add-apt-repository ppa:ubuntu-toolchain-r/test $ sudo apt-get update $ sudo apt-get install gcc-4.9 g++-4.9 ``` and your system should now be correctly configured.

Dependencies

The provided packages depend on yaml-cpp.

ROS packages

If you do not have a created catkin workspace, create one by doing ``` $ mkdir ~/catkin_ws $ mkdir ~/catkin_ws/src $ cd ~/catkin_ws $ catkin_make ``` Otherwise skip this step. Go to the src folder of your catkin workspace and introduce the following commands ``` $ wstool init $ wstool merge https://raw.githubusercontent.com/diogoalmeida/sarafun_bt/master/.rosinstall $ wstool update This will download theROS-Behavior-Treepackage, as well as the SARAFun packages required for running the demo. Compile the packages by doing$ catkin_make -DCMAKE_CXX_COMPILER=/usr/bin/g++-4.9 installat the root of your workspace. After compiling, do not forget to source the workspace: $ source devel/setup.bash ```

YAML parser

These packages depend on yaml-cpp, version 0.5.3, which can be obtained here

Services

The tree client provides services to start, stop and restart a tree. When starting, the tree client will parse the input file and generate a tree based on it. Restarting a tree stops the currently running tree, parses the input file and generates a new one based on it. The provided services are:

The start service requires a file path to be given. This will be used by the json parser to load the appropriate tree.

Running the demo

This package provides two demos:

To start execution, call the /sarafun/start_tree service.

NOTE: The online motion generator requires the abb_irb14000_support package, which is not freely available. You can find the robot description in this repository.

This will run a simple tree with 5 actions. Each action will command the robot to move to a different position. The two main subtrees execution depends on the output of the simple condition in the first one. This will be true for the first x ticks on the tree (defined in the launch file under /IsSimple/count_limit. When the condition becomes false, the running action will be preempted, and the second subtree is executed, where the first action under the selector asks the robot to achieve an unreachable goal, and is thus preempted after the timeout period has expired.

Creating a different tree

The behavior tree package takes a json file as input in order to generate the tree. The file is located in sarafun_tree/data and its name is given by the ROS parameter /sarafun/bt/file. If the parameter is not set, it will use the default name example.json.

The file defines the tree by specifying its root and a list of nodes. A node can be a flow control node or a leaf node. It is defined by its id, type and name tags and, for the flow control nodes only, by a list of children (children) which contains the ids of the children nodes. The id tag should be unique, and it is used to refer to a particular instance of the behavior tree node. type determines the what is the node functionality (see below). Finally, the name tag is currently only used by the leaf nodes. It specifies the actionlib server name that the concrete action implementation uses and it is used by the behavior tree in order to call the server.

A simple example is as follows ```json { "root": "sequence1", "nodes": { "sequence1": { "id": "sequence1", "type": "SequenceStar", "name": "SequenceStar", "children": [ "action1", "selector1" ] }, "selector1": { "id": "selector1", "type": "Selector", "name": "Selector", "children": [ "action2", "action3" ] }, "action1": { "id": "action1", "type": "Action", "name": "action_1" }, "action2": { "id": "action2", "type": "Action", "name": "action_2" }, "action3": { "id": "action3", "type": "Action", "name": "action_3" } } } ```

Currently supported node types

There are four currently supported flow control nodes and two possible leaf node types, which are defined in the json file by the type property:

Tree visualization

The BT engine provides a basic openGL tree visualization. An arbitrary tree may not be rendered adequately, in which case the user can use the keyboard to ajust the tree: