Skip to content

Commit c1baa5d

Browse files
committed
Update python publisher and subscriber tutorial with links to relevant documentation
1 parent 5bb9d82 commit c1baa5d

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

source/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Py-Publisher-And-Subscriber.rst

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ Open the file using your preferred text editor.
135135
2.1 Examine the code
136136
~~~~~~~~~~~~~~~~~~~~
137137

138-
The first lines of code after the comments import ``rclpy`` so its ``Node`` class can be used.
138+
The first lines of code after the comments import {package(rclpy)} so its `Node <{package_link(rclpy)}api/node.html>`__ class can be used.
139139

140140
.. code-block:: python
141141
142142
import rclpy
143143
from rclpy.executors import ExternalShutdownException
144144
from rclpy.node import Node
145145
146-
The next statement imports the built-in string message type that the node uses to structure the data that it passes on the topic.
146+
The next statement imports the built-in {interface(std_msgs/msg/String)} message type that the node uses to structure the data that it passes on the topic.
147147

148148
.. code-block:: python
149149
@@ -152,19 +152,19 @@ The next statement imports the built-in string message type that the node uses t
152152
These lines represent the node's dependencies.
153153
Recall that dependencies have to be added to ``package.xml``, which you'll do in the next section.
154154

155-
Next, the ``MinimalPublisher`` class is created, which inherits from (or is a subclass of) ``Node``.
155+
Next, the ``MinimalPublisher`` class is created, which inherits from (or is a subclass of) `Node <{package_link(rclpy)}api/node.html>`__.
156156

157157
.. code-block:: python
158158
159159
class MinimalPublisher(Node):
160160
161161
Following is the definition of the class's constructor.
162-
``super().__init__`` calls the ``Node`` class's constructor and gives it your node name, in this case ``minimal_publisher``.
162+
``super().__init__`` calls the `Node <{package_link(rclpy)}api/node.html>`__ class's constructor and gives it your node name, in this case ``minimal_publisher``.
163163

164-
``create_publisher`` declares that the node publishes messages of type ``String`` (imported from the ``std_msgs.msg`` module), over a topic named ``topic``, and that the "queue size" is 10.
165-
Queue size is a required QoS (quality of service) setting that limits the amount of queued messages if a subscriber is not receiving them fast enough.
164+
`create_publisher <{package_link(rclpy)}api/node.html#rclpy.node.Node.create_publisher>`__ declares that the node publishes messages of type {interface(std_msgs/msg/String)} (imported from the ``std_msgs.msg`` module), over a topic named ``topic``, and that the "queue size" is 10.
165+
Queue size is a required :doc:`Quality of Service </Concepts/Intermediate/About-Quality-of-Service-Settings>` (QoS) setting that limits the amount of queued messages if a subscriber is not receiving them fast enough.
166166

167-
Next, a timer is created with a callback to execute every 0.5 seconds.
167+
Next, `create_timer <{package_link(rclpy)}api/node.html#rclpy.node.Node.create_timer>`__ is used to create a callback that executes every 0.5 seconds.
168168
``self.i`` is a counter used in the callback.
169169

170170
.. code-block:: python
@@ -176,7 +176,7 @@ Next, a timer is created with a callback to execute every 0.5 seconds.
176176
self.timer = self.create_timer(timer_period, self.timer_callback)
177177
self.i = 0
178178
179-
``timer_callback`` creates a message with the counter value appended, and publishes it to the console with ``get_logger().info``.
179+
``timer_callback`` creates a message with the counter value appended, publishes it, and prints it to the console with `get_logger() <{package_link(rclpy)}api/node.html#rclpy.node.Node.get_logger>`__'s `info() <{package_link(rclpy)}rclpy.impl.rcutils_logger.html#rclpy.impl.rcutils_logger.RcutilsLogger.info>`__ function.
180180

181181
.. code-block:: python
182182
@@ -201,7 +201,7 @@ Lastly, the main function is defined.
201201
pass
202202
203203
204-
First the ``rclpy`` library is initialized, then the node is created, and then it "spins" the node so its callbacks are called.
204+
First the {package(rclpy)} library is initialized, then the node is created, and then it "spins" the node (using `spin() <{package_link(rclpy)}api/init_shutdown.html#rclpy.spin>`__) so its callbacks are called.
205205

206206
2.2 Add dependencies
207207
~~~~~~~~~~~~~~~~~~~~
@@ -225,7 +225,7 @@ After the lines above, add the following dependencies corresponding to your node
225225
<exec_depend>rclpy</exec_depend>
226226
<exec_depend>std_msgs</exec_depend>
227227
228-
This declares the package needs ``rclpy`` and ``std_msgs`` when its code is executed.
228+
This declares the package needs {package(rclpy)} and {package(std_msgs)} when its code is executed.
229229

230230
Make sure to save the file.
231231

@@ -242,7 +242,7 @@ Again, match the ``maintainer``, ``maintainer_email``, ``description`` and ``lic
242242
description='Examples of minimal publisher/subscriber using rclpy',
243243
license='Apache-2.0',
244244
245-
Add the following line within the ``console_scripts`` brackets of the ``entry_points`` field:
245+
Add the following line within the ``console_scripts`` brackets of the `entry_points <https://setuptools.pypa.io/en/latest/userguide/entry_point.html>`__ field:
246246

247247
.. code-block:: python
248248
@@ -266,7 +266,7 @@ The contents of the ``setup.cfg`` file should be correctly populated automatical
266266
[install]
267267
install_scripts=$base/lib/py_pubsub
268268
269-
This is simply telling setuptools to put your executables in ``lib``, because ``ros2 run`` will look for them there.
269+
This is simply telling `setuptools <https://setuptools.pypa.io/en/latest/userguide>`__ to put your executables in ``lib``, because ``ros2 run`` will look for them there.
270270

271271
You could build your package now, source the local setup files, and run it, but let's create the subscriber node first so you can see the full system at work.
272272

@@ -353,7 +353,7 @@ Open the ``subscriber_member_function.py`` with your text editor.
353353
main()
354354
355355
The subscriber node's code is nearly identical to the publisher's.
356-
The constructor creates a subscriber with the same arguments as the publisher.
356+
The constructor creates a subscriber with the same arguments as the publisher using `create_subscription <{package_link(rclpy)}api/node.html#rclpy.node.Node.create_subscription>`__.
357357
Recall from the :doc:`topics tutorial <../Beginner-CLI-Tools/Understanding-ROS2-Topics/Understanding-ROS2-Topics>` that the topic name and message type used by the publisher and subscriber must match to allow them to communicate.
358358

359359
.. code-block:: python
@@ -391,7 +391,7 @@ The ``setup.cfg`` file can also remain untouched.
391391
~~~~~~~~~~~~~~~~~~~~~~
392392

393393
Reopen ``setup.py`` and add the entry point for the subscriber node below the publisher's entry point.
394-
The ``entry_points`` field should now look like this:
394+
The `entry_points <https://setuptools.pypa.io/en/latest/userguide/entry_point.html>`__ field should now look like this:
395395

396396
.. code-block:: python
397397
@@ -406,8 +406,8 @@ Make sure to save the file, and then your pub/sub system should be ready.
406406

407407
4 Build and run
408408
^^^^^^^^^^^^^^^
409-
You likely already have the ``rclpy`` and ``std_msgs`` packages installed as part of your ROS 2 system.
410-
It's good practice to run ``rosdep`` in the root of your workspace (``ros2_ws``) to check for missing dependencies before building:
409+
You likely already have the {package(rclpy)} and {package(std_msgs)} packages installed as part of your ROS 2 system.
410+
It's good practice to run `rosdep <https://docs.ros.org/en/independent/api/rosdep/html/>`__ (check the :doc:`rosdep tutorial </Tutorials/Intermediate/Rosdep>`) in the root of your workspace (``ros2_ws``) to check for missing dependencies before building:
411411

412412
.. tabs::
413413

0 commit comments

Comments
 (0)