Building the node

As we are using the chapter2_tutorials package, we are going to edit the CMakeLists.txt file. You can use your favorite editor or the rosed tool. This will open the file with the Vim editor:

    $ rosed chapter2_tutorials CMakeLists.txt  

At the end of the file, we will copy the following lines:

include_directories( 
include 
  ${catkin_INCLUDE_DIRS} 
) 
 
add_executable(example1_a src/example1_a.cpp) 
add_executable(example1_b src/example1_b.cpp) 
 
add_dependencies(example1_a 
chapter2_tutorials_generate_messages_cpp)add_dependencies(example1_b
chapter2_tutorials_generate_messages_cpp) target_link_libraries(example1_a ${catkin_LIBRARIES}) target_link_libraries(example1_b ${catkin_LIBRARIES})

Now, to build the package and compile all the nodes, use the catkin_make tool as follows:

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

If ROS is not running on your computer, you will have to use the following command:

    $ roscore  

You can check whether ROS is running using the rosnode list command as follows:

    $ rosnode list  

Now run both nodes in different shells:

    $ rosrun chapter2_tutorials example1_a
    
    $ rosrun chapter2_tutorials example1_b  

If you check the shell where the example1_b node is running, you will see something similar to the following screenshot:

Everything that is happening can be viewed in the following diagram. You can see that the example1_a node is publishing the message topic, and the example2_b node is subscribing to the topic:

You can use rosnode and rostopic to debug and see what the nodes are doing. Try the following commands:

    $ rosnode list
    $ rosnode info /example1_a
    $ rosnode info /example1_b
    $ rostopic list
    $ rostopic info /message
    $ rostopic type /message
    $ rostopic bw /message  
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.158.151