Robot Operating System Cookbook
上QQ阅读APP看书,第一时间看更新

Building the ROS node

As we are working with the chapter2_tutorials package, we will edit the CMakeLists.txt file here and prepare and configure the packages for the build:

$ rosed chapter2_tutorials CMakeLists.txt 

At the end of this file, we will have to add the following lines (https://github.com/kbipin/Robot-Operating-System-Cookbook/blob/master/chapter2_tutorials/CMakeLists.txt):

include_directories( 
include 
  ${catkin_INCLUDE_DIRS} 
) 
 
add_executable(example1a src/example_1a.cpp) 
add_executable(example1b src/example_1b.cpp) 
 
add_dependencies(example1a chapter2_tutorials_generate_messages_cpp) 
add_dependencies(example1b chapter2_tutorials_generate_messages_cpp) 
 
target_link_libraries(example1a ${catkin_LIBRARIES}) 
target_link_libraries(example1b ${catkin_LIBRARIES}) 

The catkin_make tool is used to build the package that will compile all the nodes:

$ cd ~/catkin_ws/
$ catkin_make --pkg chapter2_tutorials

To work with the nodes created previously, we have to first start roscore:

$ roscore

Next, we can check whether ROS is running using the rosnode list command in another terminal, as follows:

$ rosnode list

Now, we run both nodes in different shells:

$ rosrun chapter2_tutorials example1a
$ rosrun chapter2_tutorials example1b

We will see something similar to the following screenshot in the shell where the example1b node is running:

Subscriber node output

We can use the rosnode and rostopic commands to debug and get the information about the running node:

$ rosnode list
$ rosnode info /example1_a
$ rosnode info /example1_b
$ rostopic list
$ rostopic info /message
$ rostopic type /message
$ rostopic bw /message