Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tips about service client and rate (backport #4132) #4841

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,8 @@ In ROS 2:
node.get_logger().info('service not available, waiting again...')
resp = add_two_ints.call_async(req)
rclpy.spin_until_future_complete(node, resp)

.. warning::

Do not use ``rclpy.spin_until_future_complete`` in a ROS 2 callback.
For more details see the :doc:`sync deadlock article <../Sync-Vs-Async>`.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Finally it creates a new ``AddTwoInts`` request object.
self.get_logger().info('service not available, waiting again...')
self.req = AddTwoInts.Request()

Below the constructor is the ``send_request`` method, which will send the request and return a future that can be passed to ``spin_until_future_complete``:
Below the constructor is the ``send_request`` method, which will send the request and spin until it receives the response or fails.

.. code-block:: python

Expand All @@ -255,7 +255,7 @@ Below the constructor is the ``send_request`` method, which will send the reques
self.req.b = b
return self.cli.call_async(self.req)

Finally we have the ``main`` method, which constructs a ``MinimalClientAsync`` object, sends the request using the passed-in command-line arguments, calls ``spin_until_future_complete``, and logs the results:
Finally we have the ``main`` method, which constructs a ``MinimalClientAsync`` object, sends the request using the passed-in command-line arguments, calls ``rclpy.spin_until_future_complete`` to wait for the result, and logs the results.

.. code-block:: python

Expand All @@ -273,6 +273,10 @@ Finally we have the ``main`` method, which constructs a ``MinimalClientAsync`` o
minimal_client.destroy_node()
rclpy.shutdown()

.. warning::

Do not use ``rclpy.spin_until_future_complete`` in a ROS 2 callback.
For more details see the :doc:`sync deadlock article <../../../How-To-Guides/Sync-Vs-Async>`.

3.2 Add an entry point
~~~~~~~~~~~~~~~~~~~~~~
Expand Down