Getting Started with ROS on Embedded Systems - User Guide - C++ - Topics

From RidgeRun Developer Wiki







Previous: User Guide/C++/Initialization Index Next: User Guide/C++/Messages




Introduction

This wiki is based on the following ROS page: https://docs.ros.org/en/iron/Tutorials/Beginner-CLI-Tools/Understanding-ROS2-Topics/Understanding-ROS2-Topics.html

Topics on ROS are an abstraction for a communication bus; it's where the different nodes read and write messages. The topics can be one-to-one, one-to-many, and even many-to-many.

Types

Topics have an associated message type. The subscriber nodes have to know that type. Otherwise, they will not be able to connect. That way we can be sure that a topic and its subscribers understand each other. For every different message type, there should be a different topic.

Tools

See current topics:

ros2 topic list

Check the topics and their message types:

ros2 topic list -t

Check what's being published on a certain topic:

ros2 topic echo <topic_name>

Check the connected clients and publishers:

ros2 topic info <topic_name>

Check the interface documentation associated with the message type:

ros2 interface show <msg type>

We can even send messages to the topic if the interface allows it:

ros2 topic pub <topic_name> <msg_type> '<args>'

Finally, we can check the topic's publish rate

ros2 topic hz <topic_name>
Previous: User Guide/C++/Initialization Index Next: User Guide/C++/Messages