ROS study notes (two): message communication

Insert picture description hereInsert picture description here

topic

The topic is a one-way asynchronous communication mechanism. A single publisher can communicate with multiple subscribers, and a single subscriber can also communicate with multiple publishers on a topic, that is, as long as it is a publisher and subscriber node based on the same topic, they can all be For communication, it can realize 1:1, 1:N, N:1 and N:N communication.

topic1
topic2
topic1
topic2
pub1
sub/pub
sub1
pub2
sub2

The msg file is a message file used for topics, and the extension is *.msg.

//custommsg.msg
数据类型 message

service

The service is a two-way synchronous communication mechanism. The service is a one-time message communication. When the service request and response are completed, the two connected nodes will be disconnected. In other words, when the client initiates a data request, the client node establishes a connection with the server node, and the client After receiving the data response, the end disconnects the connection with the server node.

响应
请求
server
client

The srv file is a message file used by the service, with the extension *.srv. The main difference with the msg file is: use three hyphens (-) as the separator, where the upper part of the separator is the request data, and the lower part is the response data.

//customsrv.srv
数据类型 request
---
数据类型 response

action

The action is a two-way asynchronous communication mechanism. Unlike the service server, the action server takes a long time to respond to the result after receiving the target request, and there will be feedback data sent to the action client in the middle, and it can also send a command to cancel the target at any time.

结果
反馈
目标
server
client

The action file is the message file used in the action, and the extension is *.action. The main difference with msg and srv files is: three hyphens (—) are used as separators in two places, the upper part is the target data, the middle part is the result data, and the last is the feedback data.

//customaction.action
数据类型 goal
---
数据类型 result
---
数据类型 feedback

type of data

name ROS C++ python
Boolean bool uint8_t bool
Short integer int16 int16_t int
Integer int32 int32_t int
Long integer int64 int64_t long
Single precision floating point float32 float float
Double-precision floating-point number float64 double float
String string std::string str
Timestamp time ros :: Time rospy.Time
Array uint8 [] std::vector bytes

Guess you like

Origin blog.csdn.net/qq_42386127/article/details/98600731