Create your own RoboKudo package

RoboKudo offers methods to separate your own perception routines, analysis engines and much more into separate ROS packages. Let us start by creating a package called rk_tutorial. On ROS 2, activate the virtualenv used for RoboKudo, source your ROS workspace, and change into its source directory (for example, cd ~/ros2_ws/src). On ROS 1, use the source directory of your catkin workspace instead.

The ROS 2 commands below use ~/ros2_ws; replace it with your workspace path if you used a different location. The ROS 1 tabs are legacy instructions for a ROS 1 checkout.

ros2 run robokudo_ros rk_create_package rk_tutorial 

# Use the same Python environment as RoboKudo.
python -m pip install -e ./rk_tutorial
rosrun robokudo rk_create_package rk_tutorial

The script will create a new ROS package that has the structure needed for RoboKudo:

'rk_tutorial'
|-rk_tutorial                   -> code and configuration base
  |-annotators
  |-descriptors
     |-analysis_engines -> Pipeline/Analysis Engine definitions (Behaviour Trees)
|-package.xml                   -> package metadata
|-setup.py                      -> python install information
|-setup.cfg                     -> python executable information for ros2 run
'rk_tutorial'
|-src                       -> code and configuration base
   |-rk_tutorial            -> name of your package
      |-annotators
      |-descriptors
         |-analysis_engines -> Pipeline/Analysis Engine definitions (Behaviour Trees)
|-package.xml               -> catkin package xml
|-setup.py                  -> python install information
|-CMakeLists.txt            -> CMake file

You can now add your own annotators and analysis engines (also called pipelines) that use components from the RoboKudo core package. Declare ROS dependencies in package.xml (and CMakeLists.txt on ROS 1). Declare Python dependencies in your package’s Python packaging metadata and install them into the same virtualenv as RoboKudo.

To verify your new package, let us create your very first own analysis engine. Copy over the demo analysis engine from the RoboKudo core package (note the renaming of the file):

cd ~/ros2_ws/src/
# Locate the installed Python package, independently of where CRAM was cloned.
ROBOKUDO_PYTHON_DIR=$(python -c 'from pathlib import Path; import robokudo; print(Path(robokudo.__file__).parent)')
cp "$ROBOKUDO_PYTHON_DIR/descriptors/analysis_engines/demo.py" \
    ./rk_tutorial/rk_tutorial/descriptors/analysis_engines/my_demo.py
cd ~/robokudo_ws/src/
cp ./robokudo/robokudo/src/robokudo/descriptors/analysis_engines/demo.py \
    ./rk_tutorial/src/rk_tutorial/descriptors/analysis_engines/my_demo.py

Open my_demo.py and adapt in the name method the return value to 'my_demo' instead of 'demo'.

Please make sure to rebuild and source your workspace as described below:

cd ~/ros2_ws
python -m colcon build --merge-install
source ~/ros2_ws/install/setup.bash
cd ~/robokudo_ws
catkin build
source ~/robokudo_ws/devel/setup.bash

After that, you can start your own analysis engine by executing:

ros2 run robokudo_ros main _ae=my_demo _ros_pkg=rk_tutorial
rosrun robokudo main.py _ae=my_demo _ros_pkg=rk_tutorial

It should show the same result as in the previous tutorial.

For ROS 2, the current module loader imports rk_tutorial.descriptors.analysis_engines.my_demo as a Python module. Keep the editable install in the same virtualenv used to start RoboKudo. After adding or changing files, rebuild the workspace if you are using a regular colcon install rather than a symlink install, then source it again.