Topics

Topics are buses used by nodes to transmit data. Topics can be transmitted without a direct connection between nodes, meaning the production and consumption of data are decoupled. A topic can have various subscribers. Each topic is strongly typed by the ROS message type used to publish it, and nodes can only receive messages from a matching type. A node can subscribe to a topic only if it has the same message type.

The topics in ROS can be transmitted using TCP/IP and UDP. The TCP/IP-based transport is known as TCPROS and uses the persistent TCP/IP connection. This is the default transport used in ROS.

The UDP-based transport is known as UDPROS and is a low-latency, lossy transport. So, it is best suited for tasks such as teleoperation.

ROS has a tool to work with topics called rostopic. It is a command-line tool that gives us information about the topic or publishes data directly on the network.

  • rostopic bw /topic: This displays the bandwidth used by the topic.
  • rostopic echo /topic: This prints messages to the screen.
  • rostopic find message_type: This finds topics by their type.
  • rostopic hz /topic: This displays the publishing rate of the topic.
  • rostopic info /topic: This prints information about the active topic, the topics published, the ones it is subscribed to, and services.
  • rostopic list: This prints information about active topics.
  • rostopic pub /topic type args: This publishes data to the topic. It allows us to create and publish data in whatever topic we want, directly from the command line.
  • rostopic type /topic: This prints the topic type, that is, the type of message it publishes.