当使用chapter2_tutorials功能包时,需要自行编辑CMakeLists.txt文件。可直接用rosed工具。
$ rosed chapter2_tutorials CMakeLists.txt
将以下命令行复制到文件的末尾处:
rosbuild_add_executable(example1_a src/example1_a.cpp)
rosbuild_add_executable(example1_b src/example1_b.cpp)
这些命令会在/bin文件夹下创建两个可执行文件。
不同编译方式有差别,可以根据其他的CMakelist.txt文件对照修改,主要修改依赖库和代码读取位置。
现在我们使用rosmake工具编译功能包就会编译全部的节点:
$ rosmake chapter2_tutorials
如果你电脑还没有启动ROS,需要首先调用:
$roscore
可通过rosnode list命令检查ROS是否运行:
$rosnode list
然后,在不同的shell窗口下分别运行以下命令:
$rosrun chapter2_tutorials example1_a
$rosrun chapter2_tutorials example1_b
如果检查以下 example1_b 正在运行的shell窗口,你会看到传送的消息
可使用rosnode和rostopic 命令来查看节点的运行状态
$ rosnode list
$ rosnode info /example1_a
$ rosnode info /example1_b
$ rostopic list
$ rostopic info /message
$ rostopic bw /message
$ rostopic type /message