|
1 | 1 | :github_url: https://github.com/ros-controls/realtime_tools/blob/{REPOS_FILE_BRANCH}/doc/index.rst |
2 | 2 |
|
| 3 | +############## |
3 | 4 | realtime_tools |
4 | | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 5 | +############## |
5 | 6 |
|
6 | 7 | Contains a set of tools that can be used from a hard realtime thread, without breaking the realtime behavior. |
7 | 8 |
|
| 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 | +.. --------------------- |
8 | 27 | .. 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. |
0 commit comments