Sunday, 11 December 2011

HELLO ROS

ROOKIE'S GUIDE TO MAKING ROS PACKAGES

This article is a tutorial for accomodating a basic C++ 'Hello World' programme (helloROS.cpp) into ROS nodes.
 
Fig.1. helloROS.cpp program code

#.1 - Make the ros package, it should be in the ros path;

roscreate-pkg hello roscpp

That will create a 'hello' file with the following contents;

Fig.2. Files created by roscreate-pkg hello roscpp
#.2 - Make sure that it is in the ros path;  

rospack find hello 

If rospack can find the path to 'hello', then the package is 'visible' to ROS.

#.3 - Edit the CMakeLists.txt

At the end of the CMakeLists.txt file add; 

rosbuild_add_executable(hello path/to/helloROS.cpp)

Where hello is the name of the executable to be made from the helloROS.cpp code. Usually it is a convention to keep helloROS.cpp etc files in the same folder- so the path/to/ is often not needed.

#.4 - Build the package 

rosmake hello 

#.5 - Run the code and confirm that it works ! 

rosrun hello hello 

If that works then it should print Hello ROS and the C++ executable can be found in the bin folder, which is generated by the rosmake command. It is worth noting that since this is a very simple example, rosrun hello hello will work even without the master (roscore). 

0 comments: