Groot with ROS

Vihan Melaka
Arimac
Published in
4 min readJan 10, 2021

Behavior trees

A Behavior Tree (BT) is a way to structure the switching between different tasks in an autonomous agent, such as a robot or a virtual entity in a computer game.

BTs are a very efficient way of creating complex systems that are both modular and reactive. These properties are crucial in many applications, which has led to the spread of BT from computer game programming to many branches of AI and Robotics.

BehaviorTree.CPP project has an implementation of behavior trees that can be used alongside with ROS. All the node which are required to build a basic behavior tree is implemented in this project. You can get a good knowledge about behavior trees by reading the documentation in the BehaviorTree.CPP, specially you should get a good understanding about the different type of nodes used in behavior trees before starting to build them. Following link will take you to the BehaviorTree.CPP project.

To use this concept with ROS you have to install the behaviortree cpp package using following command,

sudo apt-get install ros-$ROS_DISTRO-behaviortree-cpp-v3

(In $ROS_DISTRO enter the ros version you are using eg : kinetic, Indigo etc.)

If you want to compile it with catkin, you must include this package to your catkin workspace.

After building behavior trees using the above implementation you can use an application called “Groot” to visualize the behavior tree you have constructed. One of the main users of Groot application is that we can monitor our behavior tree in the runtime of its execution. But there is no proper documentation on how to use Groot application with ROS to monitor behaviors of robots that build using ROS. In this article we will show how to connect runtime ros behavior tree with Groot.

ZeroMQ

As you already know Groot and ROS are two separate applications, in order for them to communicate there must be some intermediate program to connect this to applications. To do this task we use a plugin called “ZeroMQ”.

ZeroMQ (also known as ØMQ, 0MQ, or zmq) looks like an embedded networking library but acts like a concurrency framework. It gives you sockets that carry atomic messages across various transports like in-process, inter-process, TCP, and multicast. You can connect sockets N-to-N with patterns like fan-out, pub-sub, task distribution, and request-reply. It’s fast enough to be the fabric for clustered products. Its asynchronous I/O model gives you scalable multi-core applications, built as asynchronous message-processing tasks. It has a score of language APIs and runs on most operating systems.

Installing ZeroMQ on ubuntu

  • Before installing, make sure you have installed all the needed packages
sudo apt-get install libtool pkg-config build-essential autoconf automakesudo apt-get install libzmq-dev
  • Install libsodium
git clone git://github.com/jedisct1/libsodium.git
cd libsodium
./autogen.sh
./configure && make check
sudo make install
sudo ldconfig
  • Install zeromq
wget http://download.zeromq.org/zeromq-4.1.2.tar.gz
tar -xvf zeromq-4.1.2.tar.gz
cd zeromq-4.1.2
./autogen.sh
./configure && make check
sudo make install
sudo ldconfig

How to install Groot ?

After successfully installing ZeroMQ as mentioned in the above section you can install Groot by following the steps below.

You need CMake 3.2 and Qt 5 to compile Groot.

  • At first you have to install dependencies.
sudo apt install qtbase5-dev libqt5svg5-dev libzmq3-dev libdw-dev
  • Then clone GitHub Groot repository.
git clone https://github.com/BehaviorTree/Groot.git
  • Then run the following command one by one on the terminal.
cd Groot
git submodule update --init --recursive
mkdir build
cd build
cmake ..
make

After successfully making the project navigate to Groot -> build folder and run groot executable file. You can download Groot in this github repository.

Connecting Groot with ROS

Groot uses ZeroMQ plugin to connect with other applications. It has a ZeroMQ client already existing inside it so what we have to do is to create a ZeroMQ publisher inside our ROS package to publish information about the behavior tree at runtime. The package “Behavior tree cpp” has already implemented a class to publish data using ZeroMQ as well.

To publish our behavior tree using the class that is already implemented in the behavior tree package we have to create an instance of the ZeroMQ publisher in the class where we initiate our behavior tree ( usually main class) and pass our behavior tree to that class as an argument. Following code shows how it can be done,

Results

After connecting Groot with ROS using Zmq plugin we were able to monitor a behavior tree of a robot at runtime. To test this we created a behavior tree for a robot to carry out the following task,

  1. Robot stays in a IDLE state until its sonar sensor gets blocked.
  2. When its sonar gets blocked it starts to patrolling to predefined destination.
  3. After completing patrolling task it will come back to its initial position.

Following GIF and image will show how we were able to monitor behavior tree explained above at runtime of the robot.

Visualizing a behavior tree of a robot at runtime using Groot
Visualization of behavior tree using Groot at runtime

As you can see nodes that were failed during the execution are indicated in red color and the nodes which were successful are indicated in green color. Nodes that are in the running status are indicated by the orange color.

--

--