Writing a topic publisher
In this section, you’ll write your first ROS 2 publisher. To work on the core concepts, we will create a new ROS 2 application and build upon it in the following chapters. This application will be super minimalistic so that we can focus on the concept we want to learn, nothing else.
What we want to do for now is publish a number on a topic. This topic is new and we will create it. You don’t really create a topic—you create a publisher or a subscriber to that topic. This will automatically create the topic name, which will be registered on the graph.
To write a publisher, we need a node. We could use the first node we created in the previous chapter, but the purpose of the node is not the same. Hence, we will create a new node named number_publisher
. In this node, we will create a publisher. As to the topic we want to publish to, we will have to choose a name and an interface.
Now, let’s get started with Python.