-
Notifications
You must be signed in to change notification settings - Fork 7
Behavior Tree Tutorial 1.3 Create a Package for your Behaviors
You have created a behavior Tree with the pre-defined nodes that are shipped with the BT library. While these are quite Powerful already you will need to write your own behaviors. The first step to do this is to set up a behavior package and load it in the editor.
Node modules have to be made available to the workspace as python modules. A node module is a .py file that can contain multiple nodes, which will all be added to the behavior tree environment together, if the module is added. These modules should be contained in a catkin package.
Start by creating a catkin package just as you would regularly: catkin_create_pkg tutorial_behaviors rospy roslint ros_bt_py_msgs ros_bt_py
roslint is not strictly required. The ros_bt_py contains the relevant classes of the node, the configurations and and the messages package their corresponding message type.
To ensure your catkin package declares modules and scripts check your CMakeLists.txt and make sure catkin_python_setup()
is not commented out.
If you want the linter checking also add this, for example in the testing section:
#############
## Testing ##
#############
roslint_python()
Next you need to create a setup.py file in the top directory of your repository. This is standard ROS packaging behavior For this repository it is:
#!/usr/bin/env python
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
setup_args = generate_distutils_setup(
version='0.0.0',
scripts=[],
packages=['tutorial_behaviors',
'tutorial_behaviors.nodes'],
package_dir={'': 'src'}
)
setup(**setup_args)
Make sure that package_dir
references the directory containing all your modules and list all directories inside that directory in the packages
list, even if they are not containing modules directly, but their subdirectories do.
When you create the package, these folders are not present so create them:
$ roscd tutorial_behaviors
$ mkdir -p src/tutorial_behaviors/nodes
Of course you can also name or organize your folder differently, this is just the default.
Also make sure every (sub-)directory (even empty ones!) contains a __init__.py by calling
$ touch src/tutorial_behaviors/__init__.py
$ touch src/tutorial_behaviors/nodes/__init__.py
for good measure you should now compile the workspace and run linter checks to see if you have any critical errors before you begin writing your own nodes.
Next you need to write your nodes.