当前位置:网站首页>[ROS] (06) ROS Communication - Topic Communication
[ROS] (06) ROS Communication - Topic Communication
2022-08-02 14:18:00 【CynalFly】
文章只是个人学习过程中学习笔记,主要参考ROS教程1.
目录
1、概念
话题(Topics):节点可以将消息发布到话题,Or receive messages by subscribing to a topic.A topic is a name used to identify the content of a message.Nodes interested in some kind of data will subscribe to the corresponding topic.A single topic may have multiple concurrent publishers(publishers)和订阅者(subscribers),And a single node can publish and subscribe to multiple topics at the same time,Individual nodes can also publish or subscribe(监听)multiple topics.通常,发布者和订阅者不知道彼此的存在.There is a decoupling relationship between them.从逻辑上讲,A topic can be thought of as a strongly typed message bus.Each bus has a name,只要类型正确,Anyone can connect to the bus to send or receive messages.
消息(Messages):订阅或发布话题时所使用的ROS数据类型.Messages are made up of typed fields.Standard primitive types are supported(整数、浮点、布尔值等),and arrays of primitive types.Messages can include arbitrarily nested structures and arrays(很像C结构).
为了让事情更清楚,我将使用 FMA radio system as an analogy:广播电台(
node)的发射器(publisher)will be at some fixed frequency(topic)Stream your favorite channels(message).Suppose you are in a car,Want to listen to your favorite channel(message).You will have a radio receiver(subscriber)Tune to this frequency(topic).You neither know the exact location of the radio station,Radio stations also don't want to know where you are.But you can still enjoy music on your favorite channels.
2、话题通信机制
话题通信是ROSOne of the most commonly used in communication is based on发布和订阅How the model communicates.for real-time、周期性、少逻辑处理的数据传输场景.
ROS Node想要通过topicway to deliver messages,首先 publisher 节点和 Subscriber Nodes are comingROS Master(节点管理器)Register the node name in 、话题名称、消息类型、URI地址和端口,然后ROS Master向 Subcriber 节点发送 publisher 节点信息, Subscriber Node according to the received publisher 节点信息,向 publisher The node requests a direct connection,after they are connected, publisher 节点向 Subscriber 节点发送消息.Communication between nodes uses a basedTCP/IP的消息传输,称为TCPROS.

3、话题命令rostopic
rostopic命令工具能让你获取ROS话题的信息.
| 命令 | 功能 |
|---|---|
rostopic bw | 列出消息发布带宽 |
rostopic delay | display delay of topic from timestamp in header |
rostopic echo | 显示某个话题上发布的数据 |
rostopic find | 根据消息类型查找话题 |
rostopic hz | Reports the rate at which data is published |
rostopic info | 获取指定Topic Current published news |
rostopic list | 列出当前所有的Topic |
rostopic pub | 把数据发布到当前某个正在广播的话题上 |
rostopic type | View message types for all posted threads |
Tips:使用
rostopic <command> -hHelp option for more detailed usage.
4、 Topic communication practice – The keyboard controls the turtle(turtlesim)运动
通过ROS内置的turtlesimTo carry out the practice of topic communication,There are two nodes involved in this practice,One is the keyboard node that controls the movement of the turtleturtle_teleop_key,The other is a display node that shows the turtle's movementturtlesim_node,They communicate with each other through topics,turtle_teleop_key(publisher)在话题上发布键盘按下的消息,turtlesim_node(subscriber)则订阅该话题以接收消息,Implement turtle motion.我们可以使用rqt_graph GUI来Displays currently running nodes and topics.
实现的步骤如下:
步骤1:在新终端中启动roscore
roscore
步骤2:在新终端中启动turtlesim_node
rosrun turtlesim turtlesim_node
步骤3:Start the keyboard in a new terminalturtle_teleop_key
rosrun turtlesim turtle_teleop_key
步骤4:在turtle_teleop_key终端中(Be sure to select the terminal window,Make sure keystrokes are captured),Press the arrow keys on the keyboard to control the turtle movement.
5、Topic command practice
使用控制乌龟(turtlesim)运动Cases to practice topic commands.
5.1 rostopic list
rostopic list Ability to list all topics that are currently subscribed and published.
# (1) Lists all topics that are currently subscribed and published.
rostopic list
# (2) Lists all published and subscribed topics and their type details.
rostopic list -v

5.2 rostopic type
rostopic type [topic] The command is used to view the message type of the posted topic.
# (1) View posted topics[/turtle1/cmd_vel]的消息类型.
rostopic type /turtle1/cmd_vel
# (2) 使用rosmsgView the details of the message
rosmsg show geometry_msgs/Twist

5.3 rostopic echo
rostopic echo [topic] 可以显示在某个话题上发布的数据.
rostopic echo /turtle1/cmd_vel
当输入命令后,You may see that nothing happens,Because no data has been posted to this topic yet.This can be done by pressing the arrow keys on the keyboardturtle_teleop_key节点发布数据.Remember if you can't control the turtle,请选中turtle_teleop_keyterminal window to ensure that keystrokes are captured.When the right and up keys are pressed,应该看到以下内容:
现在让我们再看一下rqt_graph.First press the refresh button in the upper left corner to display the new node.正如你所看到的,rostopic echo(Shown here in red)Also subscribed nowturtle1/cmd_vel话题.
5.4 rostopic pub
rostopic pub [topic] [msg_type] [args] Commands can publish data to a topic that is currently being broadcast.
# The command will send a message to turtlesim,告诉它以2.0大小的线速度和1.8大小的角速度移动.
rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'
-1:这一选项会让rostopic只发布一条消息,然后退出./turtle1/cmd_vel:这是要发布到的话题的名称geometry_msgs/Twist:这是发布到话题时要使用的消息的类型.--:这一选项(两个破折号)用来告诉选项解析器,表明之后的参数都不是选项.如果参数前有破折号(-)比如负数,那么这是必需的.
There is also a quick way to type:先输入以下命令,然后双击Tab键,最后使用<-和->键修改
linear和angular.rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist

下面我们用 rostopic pub -r command to issue a steady stream of commands:
# 命令以1Hzfrequency to send messages toturtlesim,Make sure that the turtle continues to do a circular motion
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'

5.5 rostopic hz
rostopic hz [topic] The command is used to report the rate at which data is published.
rostopic hz /turtle1/cmd_vel

5.6 rostopic bw
rostopic bw [topic] 显示指定话题的消息数据带宽(bandwidth).
rostopic bw /turtle1/cmd_vel

5.7 rostopic info
rostopic info [topic] 获取指定Topic Current published news .
5.8 rostopic find
rostopic find [msg_type] 根据消息类型查找话题.
rostopic find geometry_msgs/Twist

ROS.otg. ROS教程[EB/OL]. 2020-12-22[2022-7-5].
http://wiki.ros.org/cn/ROS/Tutorials. ︎
边栏推荐
- The future of financial services will never stop, and the bull market will continue 2021-05-28
- Linux:CentOS 7 安装MySQL5.7
- [ROS](03)CMakeLists.txt详解
- 【ROS】工控机的软件包不编译
- 泡利不相容原理适用的空间范围(系统)是多大?
- Minio文件上传
- Raft对比ZAB协议
- Data Organization---Chapter 6 Diagram---Graph Traversal---Multiple Choice Questions
- 第十四单元 视图集及路由
- Flask-RESTful请求响应与SQLAlchemy基础
猜你喜欢

uview 2.x版本 tabbar在uniapp小程序里头点击两次才能选中图标

The most complete ever!A collection of 47 common terms of "digital transformation", read it in seconds~

Chapter6 visualization (don't want to see the version)

目标检测场景SSD-Mobilenetv1-FPN

你接受不了60%的暴跌,就没有资格获得6000%的涨幅 2021-05-27

RHCE第一天作业

第十一单元 序列化器

不精确微分/不完全微分(Inexact differential/Imperfect differential)

Mysql's case the when you how to use

yolov5,yolov4,yolov3乱七八糟的
随机推荐
浅浅写一下PPOCRLabel的使用及体验
MySQL数据库语法格式
【ROS】工控机的软件包不编译
Swagger 的使用
Mysql's case the when you how to use
MobileNet ShuffleNet & yolov5 replace backbone
Flask请求应用上下文源码分析
标量替换、栈上分配、同步消除
logback源码阅读(一)获取ILoggerFactory、Logger
瑞吉外卖笔记——第08讲读写分离
Audio processing: floating point data stream to PCM file
网络安全第二次作业
The future of financial services will never stop, and the bull market will continue 2021-05-28
【Tensorflow】AttributeError: module ‘keras.backend‘ has no attribute ‘tf‘
rpm包的卸载与安装[通俗易懂]
Flask-RESTful请求响应与SQLAlchemy基础
定了!就在7月30日!
FFmpeg AVPacket详解
未来的金融服务永远不会停歇,牛市仍将继续 2021-05-28
EasyExcel 的使用