IDE for ROS

来源:互联网 发布:可口可乐波士顿矩阵 编辑:程序博客网 时间:2024/06/01 10:30

u can see :http://wiki.ros.org/IDEs

This page collects experience and advice on using integrated development environments (IDEs) with ROS. Please contribute.

目录

  1. General
    1. Reusing your shell's environment
  2. Eclipse
    1. Installing Eclipse
    2. Creating the Eclipse project files
    3. Importing the project into Eclipse
    4. Building the project inside Eclipse
    5. Running and debugging your executables within Eclipse
    6. More eclipse goodies
    7. Auto Formatting
  3. CodeBlocks
  4. Emacs
  5. Vim
  6. NetBeans
    1. Installing NetBeans
    2. Getting ROS environment variables in NetBeans
    3. Making NetBeans project
    4. Code auto formatting in NetBeans
  7. QtCreator

General

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, butrunning 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 commandeclipse 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

Eclipse's built in C++ indexing capabilities have gotten quite good in recent versions.

Installing Eclipse

To use this tutorial, users should not "sudo apt-get install eclipse". Instead:

  • Go to eclipse web site

  • 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

For a rosbuild package

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 thebuild/ 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 thebuild/ folder). Proceed as follows:

Open a terminal, roscd into the folder of your package, and execute:

make eclipse-project

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 thiseclipse projects bash script for subdirectories.

Catkin-y approach

If you are using catkin, you do not have the possibility to usemake eclipse-project. You need to execute:

catkin_make --force-cmake -G"Eclipse CDT4 - Unix Makefiles"

After executing this command you will find the project files in thebuild/ folder. Now you can import your project as existing project into workspace.

Maybe you will need to execute the following if you would like to debug your program. To execute this command cd to thebuild/ folder. You should do so if you e.g. get an error like "No source available for main()".

cmake ../src -DCMAKE_BUILD_TYPE=Debug

For information on the proper approach using catkin, start here

Catkin and Python

For me, the above procedure didn't generate a .pydevproject file, like make eclipse-project ever did. ClickingSet as PyDev Project would create a config but without any Paths, so coding would be a hassle.

Workaround: From within the package you want to program run:

python $(rospack find mk)/make_pydev_project.py

Now copy the created file .pydevproject (which has all dependency package paths included) to<catkin_ws>/build and import your catkin-project into eclipse orSet it as PyDev Project if already imported.

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 selectCopy 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 pressCTRL-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. Especially if you followReusing your shell's environment from above.

If not, this is where you need to start looking: Right click on the project, selectProperties --> C/C++ Make Project --> Environment, and check whether the following environment variables are assigned to the correct values:

  • ROS_ROOT
  • ROS_PACKAGE_PATH
  • PYTHONPATH
  • PATH

The easiest way to obtain the correct values for your installation is to open a terminal, and run

echo $ROS_ROOTecho $ROS_PACKAGE_PATHecho $PYTHONPATHecho $PATH

You should now be able to compile your package properly, for example by hittingCTRL-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. As the same for building, this should work out-of-the-box, especially if you followReusing your shell's environment from above.

Create a new launch configuration, by clicking on Run -->Run configurations... --> C/C++ Application (double click or click onNew). Select the correct binary on the main tab (Search project should work when your binary was already built). Then in theenvironment tab, add (at least)

  • ROS_ROOT
  • ROS_MASTER_URI

again with the values of your installation. If you are unsure about them, open a terminal and run

echo $ROS_ROOTecho $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 theConsole 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 (fromWriting a Publisher/Subscriber (C++)):

[ INFO] [1276011369.925053237]: I published [Hello there! This is message [0]][ INFO] [1276011370.125082573]: I published [Hello there! This is message [1]][ INFO] [1276011370.325025148]: I published [Hello there! This is message [2]][ INFO] [1276011370.525034947]: I published [Hello there! This is message [3]]

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 chooseFiles->C++ Source File->Default C++ source template and click onEdit.... 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 asDocumentation tool. This option automatically completes Doxygen style comments highlights them.

  • People that are used to the emacs key bindings can select emacs-style bindings inWindows->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 propertiesC/C++ General->Paths and Symbols.

  • The generated eclipse project also works great for Python code. Just install thePyDev plugin for syntax highlighting and code completion.

Auto Formatting

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

  • Click Import...

  • Select ROS_format.xml from the location used in step 1

  • Click OK

As you edit a file, Eclipse should use this new profile to format your code following the ROS conventions. To reformat an entire file, selectEdit->Format.

CodeBlocks

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 PackageName
    You 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.

    If you are writing a ROS node, create the msg (and perhaps svr) directory and populate it as you normally do using.
    • `rospack find roscpp`/scripts/genmsg_cpp msg/MessageName.msg

    Then be sure to go back and add -Imgs/cpp (and perhaps -I srv/cpp) flags to the cflags in Compiler Settings, Other Options.

    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
  • m_pNodeTemplate->Publish();

  • .

Emacs

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.

Vim

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 ashttps://github.com/gmarik/vundle andhttps://github.com/Shougo/neobundle.vim.

NetBeans

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.

Installing NetBeans

Although NetBeans is included in Ubuntu repositories, everything described here was tested withNetBeans 6.9.1.

  • 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 fromhttp://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 wantNetBeans to do.

In order to use rosmake from NetBeans, we need to set ROS environment variables in NetBeans. Since NetBeans is started with a shell script on Linux, we can include the variables in the script.

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 justsetup.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 toNetBeans:

$ 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 convertNetBeans startup script fromsh 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

#!/bin/sh

to

#!/bin/bash

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

Exec=/bin/sh "/usr/local/netbeans-6.9.1/bin/netbeans"

to

Exec=/bin/bash "/usr/local/netbeans-6.9.1/bin/netbeans"

And that is it. Next time you start NetBeans it will have ROS environment variables, and you'll be able to use e.g.rosmake.

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.

To get the paths to include files for the package we will use rospack. Further, we'll use sed to format them for easier input to NetBeans.

$ 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 inNetBeans as defined inCppStyleGuide. 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 guideVertical Whitespace.

QtCreator

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.