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
This 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
6) Select the tab Projects -> Build Settings and add these CMake arguments:
-DCMAKE_INSTALL_PREFIX=../install -DCATKIN_DEVEL_PREFIX=../devel
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
Happy coding.