Add and run code for ROS-packages
In the “Project Explorer” tab expand the content of an imported project, select the “src” folder, click the right mouse button to show the context menu, select an item “New”, then an item “Source File”.
Type in the field “Source file” the name of the file (e.g “talker.cpp” taken from the tutorial) and click the button “Finish”.
Open the created file and copy/paste in it source code from the section “1.1.1 The Code” of the tutorial (or from GitHub). Errors may be indicating that dependency from ROS-packages are not resolved – it will be resolved in a while.
Open the file “CMakeList.txt” and add the following line at the end (similar to existing commented lines) – this line specifies “make” to build an executable with name “talker” from the file “talker.cpp” located in the directory “src”.
For each file added to the directory “src” it is needed to add such line in the file CMakeList.txt
Build the project (as described earlier in this instruction) – a new directory “Binaries” will be created in the project hierarchy. This directory contains files with extension “.out” and an executable file “talker”.
Add a new run-configuration
- Click on the arrow-down on the right of a button “Run” to display a menu.
- Select an item “Run Configurations…”.
- In the dialog “Run Configurations” select one of existing configurations under the “C/C++ Application” item.
- Click on the button “Search Project”.
- In the dialog “Program Selection” select the file “talker” and click the button “Ok”.
- Click on the button “Apply” in the dialog “Run Configurations…” and close the dialog.
Run another copy of the Terminal (hit Ctrl+Alt+T) and run the following command starting ROS-core which allows services communicating – without this started “talker” will be terminated with an error “Failed to contact master”.
Switch to Eclipse, select the project in the “Project Explorer” tab and click on the button “Run” – “talker” package will start sending data shown in the “Console” tab. Click on the button “Terminate” to stop the application.