写个学习笔记方便自己后面回查
启动发布器C++
确保roscore可用,并运行:
roscore
catkin specific 如果使用catkin,确保你在调用catkin_make后,在运行你自己的程序前,已经source了catkin工作空间下的setup.sh文件:
# In your catkin workspace
cd ~/catkin_ws
source ./devel/setup.bash
在上一个教程中我们制作了一个叫做"talker"的消息发布器,让我们运行它:
rosrun beginner_tutorials talker #(C++)
rosrun beginner_tutorials talker.py #(Python)
你将看到如下的输出信息:
[INFO] [WallTime: 1314931831.774057] hello world 1314931831.77
[INFO] [WallTime: 1314931832.775497] hello world 1314931832.77
[INFO] [WallTime: 1314931833.778937] hello world 1314931833.78
[INFO] [WallTime: 1314931834.782059] hello world 1314931834.78
[INFO] [WallTime: 1314931835.784853] hello world 1314931835.78
[INFO] [WallTime: 1314931836.788106] hello world 1314931836.79
发布器节点已经启动运行。现在需要一个订阅器节点来接受发布的消息。
启动订阅器
上一教程,我们编写了一个名为"listener"的订阅器节点。现在运行它:
rosrun beginner_tutorials listener #(C++)
rosrun beginner_tutorials listener.py #(Python)
你将会看到如下的输出信息:
[INFO] [WallTime: 1314931969.258941] /listener_17657_1314931968795I heard hello world 1314931969.26
[INFO] [WallTime: 1314931970.262246] /listener_17657_1314931968795I heard hello world 1314931970.26
[INFO] [WallTime: 1314931971.266348] /listener_17657_1314931968795I heard hello world 1314931971.26
[INFO] [WallTime: 1314931972.270429] /listener_17657_1314931968795I heard hello world 1314931972.27
[INFO] [WallTime: 1314931973.274382] /listener_17657_1314931968795I heard hello world 1314931973.27
[INFO] [WallTime: 1314931974.277694] /listener_17657_1314931968795I heard hello world 1314931974.28
[INFO] [WallTime: 1314931975.283708] /listener_17657_1314931968795I heard hello world 1314931975.28
你已经测试完了发布器和订阅器,下面我们来编写一个服务和客户端