Note: This tutorial assumes that you have completed the previous tutorials: 编写简单的发布者和订阅者(Python)(C++). |
Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags. |
检验简单的发布者和订阅者
Description: 本教程将介绍如何运行及测试发布者和订阅者。Tutorial Level: BEGINNER
Next Tutorial: 编写简单的服务和客户端 (Python) (C++)
运行发布者
确保roscore已经开启:
$ roscore
catkin specific 如果使用catkin,在运行你的程序前,请确保你在调用catkin_make后已经source过工作空间的setup.*sh文件:
# 在catkin工作空间中 $ 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
完成后,按Ctrl+C停止listener和talker。
现在已经研究了简单的发布者和订阅者,让我们再编写简单的服务和客户端(Python)(C++)。