From Introduction to Robotics (CS460)
Jump to: navigation, search

How to Configure Eclipse to Program with ROS

This page shows how to integrate Eclipse IDE in ROS Catkin Workspace. The ROS IDEs page present details for integrating other IDEs. This page provides the simplified steps to configure Eclipse to work with Catkin.
The content of this page is taken and updated based on this Reference slides

Step 1. Install and Configure Eclipse

First, you need to install Eclipse. Before installation, make sure to install Java Virtual Machine (JVM) because eclipse is programmed with Java. Run the following command:

sudo apt-get install default-jre

Then, download Eclipse IDE for C/C++. Since/if you use Ubuntu OS, download Linux-32 bits or Linux-64 depending on your operating system.
Extract the downloaded package and move it into /opt directory with the command

sudo mv eclipse /opt

As /opt might need some admin privileges, it might be useful to change previdelged of the eclipse folder to be accessible by any user by doing the following

cd /opt
sudo chmod -R 777 eclipse

You can create a link to be used by all users

sudo ln -s /opt/eclipse/eclipse /usr/bin/eclipse

Then, for easier access, you can add the following text into a unit dash entry:

sudo gedit /usr/share/applications/eclipse.desktop

and add the following text

[Desktop Entry]
Exec=bash -i -c "/opt/eclipse/eclipse"
Comment=Integrated Development Environment

The final step is to compile the project workspace and auto generate eclipse project files:

$cd ~/catkin_ws
$catkin_make --force-cmake -G"Eclipse CDT4 - Unix Makefiles"

The project files will be generated in the build/ folder (~/catkin_ws/build/.project and ~/catkin_ws/build/.cproject)

Step 2. Import the project into Eclipse

Now, start Eclipse. Choose your catkin_ws as the workspace folder.

Then, choose

File --> Import --> General --> Existing Projects into Workspace


Now import the project from the ~/catkin_ws/build folder.

Fix Preprocessor Include Paths

By default, the intellisense in Eclipse won’t recognize the system header files (like <string>). To fix that: Go to

Project Properties --> C/C++ General --> Preprocessor Include Paths, Macros, etc. --> Providers tab


CDT GCC Built-in Compiler Settings


After that rebuild the C/C++ index by Right click on

project -> Index -> Rebuild


Step 3. Create a ROS Project

Eclipse provides a link Source directory within the project so that you can edit the source code.

Right click on src and select New –> Source File, and create a file named talker.cpp


Use Eclipse standard shortcuts to get code completion (i.e., Ctrl+Space)


Step 4. Write your first code

The following code provide simple publisher node that periodically publish a hello message of type std_msgs/String

#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>

int main(int argc, char **argv)
   ros::init(argc, argv, "talker"); // Initiate new ROS node named "talker"

   ros::NodeHandle n;
   ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
   ros::Rate loop_rate(10);

   int count = 0;
   while (ros::ok()) // Keep spinning loop until user presses Ctrl+C
       std_msgs::String msg;

       std::stringstream ss;
       ss << "hello world " << count; = ss.str(); 


       ros::spinOnce(); // Need to call this function often to allow ROS to process incoming messages

      loop_rate.sleep(); // Sleep for the rest of the cycle, to enforce the loop rate
   return 0;

Step 5. Building your node

First, you need to modify the CMakeLists.txt of your package. The changes you need to make are hilighted in red colour.


Sometimes, when your node depends on other executable targets, you need to add the appropriate dependencies. For example:

add_dependencies(talker beginner_tutorials_generate_message_cpp)

This makes sure message headers are generated before being used.
After changing the CMakeLists file call catkin_make

Step 5. Running the Code Inside Eclipse

  • 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 (use the Browse… button)
  • Make sure roscore is running in a terminal
  • Click Run


Then, you will see the following output


Step 5. Running the Node From a Terminal

First, make sure you have sourced your workspace

cd ~/catkin_ws
source devel/setup.bash

Then, run the node as follows

rosrun beginner_tutorials talker

You will see the following output