To write code for ROS you can use a simple text editor like “gedit”, “vi” or “nano”, but when the project becomes complex you risk to lose yourself without autocompletition, indexing and project trees. On the other hand one of the must difficult thing is to debug different rosnodes using textual GDB.
Using a graphical IDE (Integrated Development Environment) like QtCreator can speed up the process of code writing and the debug phase… and its configuration is really simple since it fully support CMake!
QtCreator is a free and popular IDE. Originally designed to create Qt applications, it is also very useful to edit C++ code in general.
Eclipse is another popular IDE but QtCreator works better with ROS… and I love Qt 😉
Installing QtCreator
sudo apt-get install qtcreator
In order to be able to work with ROS code, QtCreator needs to be able to source the environment (your .bashrc). You can either launch it from a terminal, or create a custom qtcreator.desktop file:
First copy the standard qtcreator.desktop file:
cp /usr/share/applications/qtcreator.desktop ~
Then edit it and change the Exec line into:
Exec=bash -i -c qtcreator %F
Finally, remove the QtCreator icon from the launcher (if present) by right clicking it and selecting “Unlock from launcher“; drag and drop the qtcreator.desktop file you just created to the launcher.
Configuring QtCreator
QtCreator offers lots of options. The most important one is to configure the code style to indent using 2 spaces.
- Open “Tools > Options …“
- Under “C++ > Code Style“, copy the GNU style (name the copy driving for instance), and edit it
- Set the tab and indent size to 2 (spaces only)
Opening a ROS project
- Click “File > Open file or projet” and browse to the CMakeLists.txt at the root of your catkin source space (e.g. ~/catkin_ws/src/CMakeListst.txt).
- Set the build location to the build space of the catking workspace (~/catkin_ws/build).
- run cmake with no arguments
It should start parsing the packages in the project (as with catkin_make) and the list of packages should appear in the project view.
It is also possible to open a single package, just search for the relative CMakeFile.txt (e.g. ~/catkin_ws/src/Robocontroller-ROS/CMakeListst.txt) and set the right build folder (e.g. ~/catkin_ws/src/Robocontroller-ROS/build)
You are now ready to work with QtCreator and ROS. You can run your ROS nodes inside QtCreator and you can debug them.
Very important: don’t forget to add
set(ROS_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
to the CMakeLists.txt of your packages to add debug information to your executables to let QtCreator (and any other debug tool) to be able to debug your code.
Note: empty error dialog box
If you cannot debug your application and you get an empty error dialog box you must set the correct node file to QtCreator:
- click “Project” on the left
- choose “Run” tab
- add a new “Run configuration” and select the correct executable of your node that it is contained in the “lib” folder under the “build” folder (i.e.[build_path]/devel/lib/[package_name]/[node_name])
Remember that the nodes compiled with QtCreator are not available in the ROS environment, so after your debug you must go back to your workspace main directory and run the “catkin_make” command to compile the packages in your ROS workspace.
source: http://wiki.ros.org/IDEs#QtCreator
source: https://github.com/StanfordDrivingTeam/driving_public/wiki/Setting-up-QtCreator