This article is a tutorial for accomodating a basic C++ 'Hello World' programme (helloROS.cpp) into ROS nodes.
![]() |
| Fig.1. helloROS.cpp program code |
roscreate-pkg hello roscpp
That will create a 'hello' file with the following contents;
![]() |
| Fig.2. Files created by roscreate-pkg hello roscpp |
#.3 - 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.
#.4 - Edit the CMakeLists.txt
At the end of the CMakeLists.txt file add;
rosbuild_add_executable(hello path/to/helloROS.cpp)
#.5 - Build the package
rospack find hello
If rospack can find the path to 'hello', then the package is 'visible' to ROS.
#.4 - 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.
#.5 - Build the package
rosmake hello
#.6 - 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).
Tested on ROS Electric, should work on nearly all ROS distributions.
Later, a Hello program for Python was also added to the package.
Tested on ROS Electric, should work on nearly all ROS distributions.
Later, a Hello program for Python was also added to the package.



0 comments:
Post a Comment