Sarafun Behavior Trees package
1
Behavior trees for the SARAFun project
|
This repository contains code that showcases a potential application of behavior trees. It provides:
sarafun_tree
ROS package. It provides the required utilities for running a behavior tree in the context of the SARAFun EU project.sarafun_manipulation
, sarafun_generic_al_server
and sarafun_assembly
, that implement actionlib servers for interacting with the behavior tree.It depends on a modified version of the ROS-Behavior-Tree package by Michele Colledanchise. The main changes are
ActionTemplate
and ConditionTemplate
, and their exposure as libraries.The modified package is found here.
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.
The provided packages depend on yaml-cpp.
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 the
ROS-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 ```
These packages depend on yaml-cpp, version 0.5.3, which can be obtained here
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:
/sarafun/start_tree
/sarafun/stop_tree
/sarafun/restart_tree
The start service requires a file path to be given. This will be used by the json parser to load the appropriate tree.
This package provides two demos:
sarafun_tree/data/example_demo1.json
, and each action will prompt the user to enter the key "p" for preempting the action, "a" to abort it and anything else to succeed. Preempting or aborting an action results in a FAILURE
state in the behavior tree. Edit the sarafun_tree/data/example_demo1.json
file in order to test different tree configurations! To run this demo, type ``` $ roslaunch sarafun_tree run_sarafun_bt_demo.launch demo1:=true ```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.
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 id
s 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" } } } ```
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:
FAILURE
as soon as one of its children returns FAILURE
, or SUCCESS
in case all of its children are successfulSUCCESS
as soon as one of its children returns SUCCESS
, or FAILURE
in case all of its children are successfulSUCCESS
FAILURE
SUCCESS
or FAILURE
at the end of its execution, according to the implementation. While executing, it will return RUNNING
SUCCESS
or FAILURE
as soon as it tick'ed, and should be used to help the behavior tree logic by verifying some condition.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: