Tutorials

Transform a behavior tree into a finite state machine

This tutorial will teach you how to use the algorithm in this package to transform a behavior tree into a functionally equivalent finite state machine.

Background

This implements the algorithm described in *Behavior Trees in Robotics and AI: An Introduction* by Michele Colledanchise, Petter Ögren. Of particular interest is the section 2.2.2 Creating a FSM that works like a BTs (page 29).

For our implementation, please refer to the Bt2FSM class.

Prerequisites

You need to have this package installed in your workspace. If you don’t have it, build it:

mkdir -p ~/colcon_ws/src
cd ~/colcon_ws/src
git clone https://github.com/boschresearch/bt_tools.git
cd ~/colcon_ws
colcon build --symlink-install --packages-select btlib
source ~/colcon_ws/devel/setup.bash

Input file

You can pass any behavior tree in the behaviortree.cpp format to the algorithm. For example simple_bt.xml:

<root BTCPP_format="4">
    <BehaviorTree>
        <Sequence>
            <ServiceBtCondition name="TEST_CONDITION" />
            <Fallback>
                <ActionBtAction name="TEST_ACTION_A" />
                <ActionBtAction name="TEST_ACTION_B" />
            </Fallback>
        </Sequence>
    </BehaviorTree>
</root>

Call the algorithm

Then pass it to the script:

bt_to_fsm.py ~/colcon_ws/src/bt_tools/btlib/test/_test_data/bt2fsm/simple_bt.xml

Output

This will generate a file called fsm.png in your current directory. It will look something like this:

FSM