ROS: How to develop catkin packages from an IDE

Robot Operative System (ROS) is the de-facto standard system for running, publishing and sharing software modules for mobile robots. Binary distributions come with tons of precompiled packages but at some point it is unavoidable to compile one or more ROS packages from sources, one obvious such situation being the development of new packages. Current ROS versions support the Ubuntu GNU/Linux distribution and employ the catkin build system, in turn heavily based on the great CMake.

I am a big supporter of working by typing commands on a terminal instead of the usually far less efficient move-mouse-and-click alternatives… with one exception: coding. Yes: IMHO, having a great IDE that helps you browse thru symbol and datatype declarations and provides powerful code autocompletion is mandatory for efficient coding.

Next I provide a short tutorial for setting-up a catkin development environment with my favorite GNU/Linux IDEs: CodeBlocks and QtCreator.

Option 1: CodeBlocks

ROS_IDE_Codeblocks_exampleThis is the easiest way to use an IDE in ROS development.

1) Make sure to have CodeBlocks installed in the system!

sudo apt-get install codeblocks

2) Prepare your catkin workspace as usual. Read, for example, this tutorial. Let’s assume your catkin WS is placed in $HOME/catkin_ws

3) Invoke catkin_make with this extra argument to force the generation of CodeBlocks project files:

cd ~/catkin_ws
catkin_make --force-cmake -G"CodeBlocks - Unix Makefiles"

4) Open the IDE project file(s) that will be created into ~/catkin-ws/build/ . To open the entire catkin workspace:

codeblocks ~/catkin_ws/Project.cbp

**IMPORTANT**: Always open the IDE from a terminal in which you first called ROS setup.bash (normally done in .bashrc), so it inherits all the environment variables. An alternative is to modify launchers (Desktop “icons”) to launch bash -i -c "codeblocks" instead  of simply codeblocks .

Note that the CodeBlocks IDE freezes sometimes while opening files with a large tree of #include dependencies (unavoidable in any complex ROS package), hence I recommend QtCreator instead. It is a bit more complex to set up, but worth it. Read below.

 

Option 2: QtCreator

1) Make sure to have QtCreator installed in the system!

sudo apt-get install qtcreator

2) Prepare your catkin workspace as usual. Read, for example, this tutorial. Let’s assume your catkin WS is placed in $HOME/catkin_ws

3) In order to avoid driving QtCreator mad, we must replace the symlink’ed CMakeLists.txt in catkin_ws/src with a physical copy of the actual stuff:

cd ~/catkin_ws/src
ls -l  # Take note of the actual symlink target
sed -i '' CMakeLists.txt
ls -l # The symlink should have gone away

 

4) Invoke qtcreator from a terminal in which you have already setup the ROS environment (normally via .bashrc):

qtcreator
5) Select the menu  File -> “Open File or project…“, then pick  ~/catkin_ws/src/CMakeLists.txt and set the build dir to ~/catkin_ws/build/ (where ~ stands for your home directory). Press Configure.

6) Select the tab Projects -> Build Settings and add these CMake arguments:

-DCMAKE_INSTALL_PREFIX=../install -DCATKIN_DEVEL_PREFIX=../devel

ROS_IDE_QtCreator1

7) Save all and close QtCreator.

8) Right now we have some duplicated directories so it’s recommended to delete them to avoid errors:

rm -fr ~/catkin_ws/build/devel

9) Invoke qtcreator from a terminal and you’re ready to go!

qtcreator

ROS_IDE_QtCreator2

 

Happy coding.

Publicado en Programación, Robótica Etiquetado con: , , , , ,
  • Pingback: QtCreator y otros IDEs en ROS indigo | Página personal de Manuel Fdez. Carmona()

  • Dimenterious Fox

    Thank you.
    But how to add packages to this project?

    • jlblanco

      Just clone the packages into [catkin_ws]/src/ as usual, then re-open the QtCreator project to force invoking cmake again.

  • Tobias Hunger

    About Qt Creator setup:

    Step 3 is not necessary for me (using Qt Creator 3.6-rc1).

    I did configure configure the default build path to “../build” in Tools>Options>Build & Run, before opening the project. So I was able to just enter the cmake variables from Step 6 when opening the project and do not have to close creator nor delete any directories (Steps 6 to 9).