Skip to content

Commit cbf7ae6

Browse files
Add guidelines for realtimebox/queue (#347)
1 parent eb75804 commit cbf7ae6

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

doc/index.rst

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,49 @@
11
:github_url: https://github.com/ros-controls/realtime_tools/blob/{REPOS_FILE_BRANCH}/doc/index.rst
22

3+
##############
34
realtime_tools
4-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
##############
56

67
Contains a set of tools that can be used from a hard realtime thread, without breaking the realtime behavior.
78

9+
***************************************
10+
Exchange data between different threads
11+
***************************************
12+
This package contains different concepts for exchanging data between different threads. In the following, a guideline for the usage for ros2_controllers is given.
13+
14+
Provided concepts
15+
=================
16+
17+
RealtimeThreadSafeBox
18+
---------------------
19+
A Box that ensures thread-safe access to the boxed contents. Access is best effort. If it can not lock it will return.
20+
21+
LockFreeQueue
22+
---------------------
23+
This class provides a base implementation for lock-free queues on top of `Boost.Lockfree <https://www.boost.org/doc/libs/latest/doc/html/lockfree.html>`__ for lock-free queues with various functionalities, such as pushing, popping, and checking the state of the queue. It supports both single-producer single-consumer (SPSC) and multiple-producer multiple-consumer (MPMC) queues.
24+
25+
.. RealtimePublisher
26+
.. ---------------------
827
.. include:: ../realtime_tools/doc/realtime_publisher.rst
28+
29+
Guidelines
30+
=================
31+
There exist the following typical use-cases for ros2_controllers:
32+
33+
* Passing command messages from topic subscribers in a non-realtime thread to the realtime-thread (one-way).
34+
35+
* If you care only about the latest received message, use the ``realtime_tools::RealtimeThreadSafeBox``.
36+
* If you care about the intermediate messages, i.e., receiving more than one message before the realtime-thread can process it: Use the ``realtime_tools::LockFreeQueue`` and set a suitable queue size for your application, i.e., consider the maximum expected topic rate vs controller update rate.
37+
38+
* Send data from the realtime thread to the non-realtime thread for publishing data (one-way): Use the ``realtime_tools::RealtimePublisher``.
39+
40+
* Exchange data (two-way) between a non-realtime thread and a realtime-thread like state information, current goals etc.:
41+
42+
* For primitive types like ``bool``, you can simply use ``std::atomic<bool>``, see `cppreference <https://en.cppreference.com/w/cpp/atomic/atomic/>`__.
43+
* For all other types, when missing some data samples from RT loop is not of major importance, then use the ``realtime_tools::RealtimeThreadSafeBox`` with ``try_set`` method. In the contrary situation, it is recommended to use ``realtime_tools::LockFreeQueue`` to avoid missing any samples.
44+
45+
***************************************
46+
Other classes and helper methods
47+
***************************************
48+
49+
Tba.

realtime_tools/doc/realtime_publisher.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Realtime Publisher
2-
------------------
1+
RealtimePublisher
2+
---------------------
33
The ``realtime_tools::RealtimePublisher`` allows users that write C++ ros2_controllers to publish messages on a ROS topic from a hard realtime loop. The normal ROS publisher is not realtime safe, and should not be used from within the update loop of a realtime controller. The realtime publisher is a wrapper around the ROS publisher; the wrapper creates an extra non-realtime thread that publishes messages on a ROS topic. The example below shows a typical usage of the realtime publisher in the ``on_configure()`` (non-realtime method) and ``update()`` (realtime method) methods of a realtime controller:
44

55
.. code-block:: cpp

0 commit comments

Comments
 (0)