Skip to content

Commit

Permalink
Add tips about service client and rate (#4132) (#4841)
Browse files Browse the repository at this point in the history
* add tips about service client and rate

Signed-off-by: Matthew Foran <[email protected]>
Co-authored-by: Tomoya Fujita <[email protected]>
Co-authored-by: Chris Lalancette <[email protected]>
(cherry picked from commit 9f4d273)

Co-authored-by: Matthew Foran <[email protected]>
  • Loading branch information
mergify[bot] and mjforan authored Oct 30, 2024
1 parent ec3c9c4 commit 608d46f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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

0 comments on commit 608d46f

Please sign in to comment.