This page collects experience and advice on using integrated development environments (IDEs) with ROS. Please contribute.
On ROS Answers there is a thread about Which IDE(s) do ROS developers use? that might have further hints not yet entered here.
Reusing your shell's environment
For building and running ROS programs from inside IDEs, the ROS enviroment has to be set up. All IDEs might have a config for that, but running your IDE from your ROS-sourced shell should be the easiest way, avoiding inconsistency.
Likewise, you can enhance your IDE's launcher icon to load your shells environment. E.g., replace its command eclipse with bash -i -c "eclipse". This will make bash source ~/.bashrc, in which ROS has to be sourced and parameterized, and start that IDE.
Eclipse's built in C++ indexing capabilities have gotten quite good in recent versions.
To use this tutorial, users should not "sudo apt-get install eclipse". Instead:
- Go to www.eclipse.org
- Click on "download now" from the top-right corner
- Download eclipse for C/C++ developers
- Extract eclipse into a folder of your choice
Creating the Eclipse project files
CMake can produce Eclipse project files automatically. These project files then set up all include paths correctly, so that auto completion and code browsing will work out of the box.
However, currently, a small hack is required for generating these project files in the right folder. The problem is that ROS creates the Makefiles and all other build artifacts in the build/ folder, but Eclipse expects the source files to be located within (or below) the folder where its project files are stored.
Fortunately, there is now a make target using a small script that circumvents this problem, by forcing CMake to create the project files in the directory of your package (and not the build/ folder). Proceed as follows:
Open a terminal, roscd into the folder of your package, and execute:
You will now find two Eclipse files in your package. It is not recommended to add them to the repository, as they contain absolute links and will be different for different users checking out your software.
Note that if you change anything to your manifest.xml, you will have to run this script again, which will overwrite your Eclipse project file and thereby reverting all manual changes to the project settings.
Note: Simply running the cmake Eclipse generator like
c m a k e -G"Eclipse CDT4 - Unix Makefiles"
will overwrite the Makefile. This can also happen if make eclipse-project does not complete successfully. If you already did this, you will want to restore the original Makefile, which should contain the following line:
include $(shell rospack find mk)/cmake.mk
Creating eclipse files for multiple packages/stacks
Go to the directory where your packages reside (which may be a stack-folder or just a simple folder) and run:
rosmake --target=eclipse-project --specified-only *
If you need to convert deeper nested packages or multiple stacks at once be encouraged to use this eclipse projects bash script for subdirectories.
For information on the proper approach using catkin, start here
Importing the project into Eclipse
Now start Eclipse, select File --> Import --> Existing projects into workspace, hit next, then browse for your package's directory (select root directory). Do NOT select Copy projects into workspace. Then finish.
You should now be able to browse through the code (hold down CTRL while clicking on a function/class name), get auto completion (automatically appears, or press CTRL-SPACE) et cetera.
Building the project inside Eclipse
The eclipse-project make target automatically tries to set the environment variables correctly such that building within Eclipse should work out-of-the-box.
If not, this is where you need to start looking: Right click on the project, select Properties --> C/C++ Make Project --> Environment, and check whether the following environment variables are assigned to the correct values:
The easiest way to obtain the correct values for your installation is to open a terminal, and run
echo $ROS_ROOT echo $ROS_PACKAGE_PATH echo $PYTHONPATH echo $PATH
You should now be able to compile your package properly, for example by hitting CTRL-B (or selecting Project --> Build project in the menu).
Note: When working with multiple projects, Eclipse won't be able to determine the correct build order or when dependent projects have to be rebuilt. You have to set the project interdependencies manually for each project in your workspace (see http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.cdt.doc.user/reference/cdt_u_prop_general_pns_ref.htm).
Running and debugging your executables within Eclipse
As for building within Eclipse, the crucial step here is to set the required environment variables correctly in the launch configuration.
Create a new launch configuration, by clicking on Run --> Run configurations... --> C/C++ Application (double click or click on New). Select the correct binary on the main tab (Search project should work when your binary was already built). Then in the environment tab, add (at least)
again with the values of your installation. If you are unsure about them, open a terminal and run
echo $ROS_ROOT echo $ROS_MASTER_URI
Finally, if you cannot save the configuration, remove the @ character in the name of the new run configuration.
This should now allow you to run and debug your programs within Eclipse. The output directly goes into the Console of Eclipse. Note that the ROS_INFO macros use ANSI escape sequences, which are not parsed by Eclipse; therefore, the output might look similar to this one (from Writing a Publisher/Subscriber (C++)):
[0m[ INFO] [1276011369.925053237]: I published [Hello there! This is message ][0m [0m[ INFO] [1276011370.125082573]: I published [Hello there! This is message ][0m [0m[ INFO] [1276011370.325025148]: I published [Hello there! This is message ][0m [0m[ INFO] [1276011370.525034947]: I published [Hello there! This is message ][0m
You could use an ANSI console plugin (e.g. http://www.mihai-nita.net/eclipse/) to get rid of the "[0m" characters in the output.
More eclipse goodies
Setup a file template that pre-formats whenever a new source or header file is created. The template could for example contain the license header, author name, and include guards (in case of a header file). To setup the templates, choose in the Preferences C/C++->Code Style->Code Templates. For example, to add the license header choose Files->C++ Source File->Default C++ source template and click on Edit.... Paste the license header and click OK. From now on, all source files while automatically contain the license header.
Enable Doxygen with the project properties clicking on C/C++ General, enabling project specific settings and selecting Doxygen as Documentation tool. This option automatically completes Doxygen style comments highlights them.
People that are used to the emacs key bindings can select emacs-style bindings in Windows->Preferences General->Keys and selecting the emacs Scheme. Also, other useful key bindings (e.g. make project) can easily be added.
To also index files that live outside the ROS tree (e.g. the boost include files) you can add them in project properties C/C++ General->Paths and Symbols.
The generated eclipse project also works great for Python code. Just install the PyDev plugin for syntax highlighting and code completion.
Eclipse also has extensive formatting configuration capabilities. To add the ROS formatting profile to Eclipse, perform the following steps:
Download ROS_format.xml to some location
- Start Eclipse
Select Window->Preferences->C/C++->Code Style
Select ROS_format.xml from the location used in step 1
As you edit a file, Eclipse should use this new profile to format your code following the ROS conventions. To reformat an entire file, select Edit->Format.
Here's how to create a ROS package using CodeBlocks:
Create a new project as you normally do in CodeBlocks, either as a console project or as a wxWidgets project. Write a manifest.xml file that specifies the ROS dependencies, as you normally do for a ROS package. To get the compiler and the linker flags, use these commands from a terminal window:
rospack export --lang=cpp --attrib=cflags PackageName rospack export --lang=cpp --attrib=lflags PackageNameYou can just copy and paste the results into the Build Options of your project, specifically:
In CodeBlocks, right click on the project name, select Build Options, select the project (rather than the Debug or Release versions that are selected by default in the popup window), select the tabs for Compiler Settings, Other Options, and paste the cflags you got from above. Then select the linker settings tab, and in Other Linker Options, paste the linker flags you got from above. You can also do this with a bash script: copy the flags into bash scripts, make them executable, and put the scripts in place of the long lists of flags. You can use environment varialbles in the script. Note that CodeBlocks allows a "local" definition of environment variables as well.
`rospack find roscpp`/scripts/genmsg_cpp msg/MessageName.msg
I posted in the Attachments an example of code that works in a CodeBlocks wxWidgets GUI project and runs a ROS node that subscribes, advertises, services, and publishes data across various busses. The files are nodeTemplate.cpp and nodeTemplate.h
Here's how to use the sample code: . Create a package called wxWidgetsNodeTemplate, using the attached manifest.xml file. Also create a msg directory and a srv directory.
Use the attached RosNodeTemplate.msg file and auto-generate the header for it with
`rospack find roscpp`/scripts/genmsg_cpp msg/RosNodeTemplate.msg
Similarly use the attached NodeTemplateServer,srv file and auto-generate the header for it with
`rospack find roscpp`/scripts/gensrv_cpp srv/NodeTemplateServer.srv
Now create a CodeBlocks project as detailed above. Add the attached files, nodeTempalte.h and nodeTemplate.cpp to the project.
- Now make an instance of nodeTemplate, passing it a pointer to a wxTextCtrl:
- m_pNodeTemplate = new nodeTemplate(txtGeneral);
- It will listen to monitor_node_bus and write to the textbox when it sees activity on that bus.
- It will service calls to node_service_bus and write to the textbox when the service is called.
- You can publish on node_bus_out with
Support through the rosemacs package. Navigate and tab complete the ros package file system, live tracking and tab completion of topics, tracking and notifications when nodes startup/die, etc.
Experimental support through the rosvim plugin, from Michael Styer. Drop the file in ~/.vim/plugin.
Extended version of rosvim.vim is here (sorted and implemented <Tab> completion feature), and ctrlp.vim interface of ros.vim is here. You can install these plugins easily by using vimscript installation plugins such as https://github.com/gmarik/vundle and https://github.com/Shougo/neobundle.vim.
The NetBeans IDE is written in Java and supports development in Java and many other programming languages. Here, C/C++ development support will be of interest.
Go to http://www.netbeans.org/
Click on "Download FREE (NetBeans 6.9.1)" in the middle of the page
- Download the C/C++ bundle
If http://www.netbeans.org/ is experiencing problems, try e.g. http://dlc.sun.com.edgesuite.net/netbeans/6.9.1/final/bundles/netbeans-6.9.1-ml-cpp-linux.sh (MD5 sum from http://www.netbeans.org/ is 26f585185b95682cb07d3e5218760702)
- Run (as root) the downloaded file (install script and embedded archive)
$ sudo sh netbeans-6.9.1-ml-cpp-linux.sh
Getting ROS environment variables in NetBeans
NetBeans can "import" project from existing sources. It can use Makefiles, and even run configure script or CMake to generate one. But, that kind of automatic project configuration and build would overwrite stub makefile that every ROS package has. That makefile in essence runs ROS build system for a package, and that is what we want NetBeans to do.
In recent ROS (where rosinstall generates setup files for multiple types of shell)
Since from recent versions rosinstall generates setup.sh, setup.bash and setup.zsh (as oposed to just setup.sh which was actually a bash script), there is no need for all the steps that are described in the next section.
The following will suffice to get ROS environment variables to NetBeans:
$ roscd $ cd .. $ echo ". $(pwd)/setup.sh" > ~/.netbeans/6.9/etc/netbeans.conf
We don't actually need perks specific to bash.
In previous ROS
If rosinstall doesn't generate setup files for multiple types of shell, you need to do the following. Since ROS shell tools are for bash, we'll convert NetBeans startup script from sh to bash. Simply edit the first line of NetBeans startup script (located at /usr/bin/netbeans if you installed from the Ubuntu package, or possibly /usr/local/netbeans-6.9.1/bin/netbeans if you installed manually) from
Further down the startup script it can be seen that the file ~/.netbeans/6.9/etc/netbeans.conf is included if it exists. We'll create that file like this
$ roscd $ cd .. $ echo "source $(pwd)/setup.sh" > ~/.netbeans/6.9/etc/netbeans.conf
Now, it just takes to modify NetBeans .desktop launcher (/usr/share/applications/netbeans-6.9.1.desktop). Change the line
Making NetBeans project
We'll try to setup project for Microstrain 3DM-GX2 IMU driver package, so note it's path:
$ roscd microstrain_3dmgx2_imu $ pwd
- Start "C/C++ Project with Existing Sources" wizard
- Use the above path to "Specify the folder that contains existing sources"
- Select "Custom" Configuration Mode (note that Automatic Mode recognizes cmake)
- Proceed with the wizard accepting defaults
You should get a NetBeans project for microstrain_3dmgx2_imu package with automatically configured Code Assistance (and almost working for all dependencies). E.g. you can see that the bullet library headers weren't parsed.
We will configure Code Assistance manually. That means entering paths to all header files the package uses and all preprocessor definitions.
$ rospack cflags-only-I microstrain_3dmgx2_imu | sed 's/ /:/g' -
Open the project properties. Go to Code Assistance -> C++ Compiler and paste the output of the above command to Include Directories field.
Use rospack to find the preprocessor definitions and enter them manually.
$ rospack cflags-only-other microstrain_3dmgx2_imu
Code auto formatting in NetBeans
Following file netbeans-ros-code_style.zip is prepared to enable auto formatting of C++ code in NetBeans as defined in CppStyleGuide. In order to use it, you should import it to Netbeans (Tools -> Options -> Import).
With this, example given in CppStyleGuide#Formatting will be identically formated, except of extra blank lines before function or class definitions. For a discussion see Google C++ style guide Vertical Whitespace.
As QtCreator supports opening CMake projects out of the box ,it does not require a setup procedure if started from a terminal. Note that this is absolutely crucial, because otherwise the environment will not be set correctly and functionality related to rosbuild will fail when running cmake.
To open a ROS package code as a project, use "Open File or Project" and select the CMakeLists.txt of your ROS package. Take care to select the "[package_name]/build" directory as the build directory, which is the ROS default.