Skip to content

Conversation

@EsipovPA
Copy link
Contributor

@EsipovPA EsipovPA commented Jun 25, 2025

Description

Added a tutorial for Cache message filter class for Python programming launguage.

Partially fixes #130

Did you use Generative AI?

Additional Information

@EsipovPA
Copy link
Contributor Author

EsipovPA commented Jun 25, 2025

Noticed the formatting issues in python code snippets. I've copied this examples from VSCode to Formiko editor part by part. In the editor it looked Ok, but turns out, it is not. Will fix asap.

Copy link
Contributor

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add also a link in tutorials.rst

Overview
~~~~~~~~

This tutorial demonstrates how to use the ``message_filters.Cache`` class in ROS 2 using Python. The ``Cache`` filter stores a time history of messages and allows querying based on timestamps.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One sentence per line

Suggested change
This tutorial demonstrates how to use the ``message_filters.Cache`` class in ROS 2 using Python. The ``Cache`` filter stores a time history of messages and allows querying based on timestamps.
This tutorial demonstrates how to use the ``message_filters.Cache`` class in ROS 2 using Python.
The ``Cache`` filter stores a time history of messages and allows querying based on timestamps.

Comment on lines 15 to 18
If you have not done so already `create a workspace <https://docs.ros.org/en/rolling/Tutorials/Beginner-Client-Libraries/Creating-A-Workspace/Creating-A-Workspace.html>`_ and `create a package <https://docs.ros.org/en/rolling/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html>`_


1. Create an Example Node with Includes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you have not done so already `create a workspace <https://docs.ros.org/en/rolling/Tutorials/Beginner-Client-Libraries/Creating-A-Workspace/Creating-A-Workspace.html>`_ and `create a package <https://docs.ros.org/en/rolling/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html>`_
1. Create an Example Node with Includes
If you have not done so already `create a workspace <https://docs.ros.org/en/rolling/Tutorials/Beginner-Client-Libraries/Creating-A-Workspace/Creating-A-Workspace.html>`_ and `create a package <https://docs.ros.org/en/rolling/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html>`_
1. Create an Example Node with Includes


1. Create an Example Node with Includes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Let's assume, you've already created an empty ros package for Python. The next step is to create a new Python file inside your package, e.g., ``cache_tutorial.py``, and create an example node:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Let's assume, you've already created an empty ros package for Python. The next step is to create a new Python file inside your package, e.g., ``cache_tutorial.py``, and create an example node:
Let's assume, you've already created an empty ros package for Python.
The next step is to create a new Python file inside your package, e.g., ``cache_tutorial.py``, and create an example node:

qos = QoSProfile(depth=10)

# Publisher and Subscriber
self.publisher = self.create_publisher(String, 'input', qos_profile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identation looks wrong


.. code-block:: python

self.subscriber_filter = Subscriber(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identation

qos = QoSProfile(depth=10)

# Publisher and Subscriber
self.publisher = self.create_publisher(String, 'input', qos_profile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

.. code-block:: python

# Simulate publishing via timer
self.publisher_timer = self.create_timer(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identation


.. code-block:: python

def publisher_timer_callback(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identation

@EsipovPA EsipovPA force-pushed the add-tutorials branch 3 times, most recently from 328bd0b to fcf4994 Compare June 26, 2025 09:32
@EsipovPA
Copy link
Contributor Author

EsipovPA commented Jun 26, 2025

@ahcorde Thank you for providing a review so quickly! I've updated the code, fixed the indentations and added the other changes, you've recommended. It would be great if you could have another look at this PR at your convenience.

@EsipovPA EsipovPA requested a review from ahcorde June 26, 2025 09:44
self.cahce_filter = Cache(
self.subscriber_filter,
cache_size=5,
allow_headerless=True, # To allow cahcing basic String message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
allow_headerless=True, # To allow cahcing basic String message
allow_headerless=True, # To allow caching basic String message

self.cahce_filter = Cache(
self.subscriber_filter,
cache_size=5,
allow_headerless=True, # To allow cahcing basic String message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
allow_headerless=True, # To allow cahcing basic String message
allow_headerless=True, # To allow caching basic String message

"/example/topic",
qos_profile=qos_profile,
)
self.cahce_filter = Cache(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.cahce_filter = Cache(
self.cache = Cache(

Comment on lines 251 to 259
.. code-block:: bash

colcon build && . install/setup.bash

Or, if you're using ZSH:

.. code-block:: bash

colcon build && . install/setup.zsh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. code-block:: bash
colcon build && . install/setup.bash
Or, if you're using ZSH:
.. code-block:: bash
colcon build && . install/setup.zsh
.. tabs::
.. group-tab:: Linux
.. code-block:: console
$ colcon build && . install/setup.bash
.. group-tab:: macOS
.. code-block:: console
$ colcon build && . install/setup.bash
.. group-tab:: Windows
.. code-block:: console
$ colcon build
$ call C:\dev\ros2\local_setup.bat

@EsipovPA
Copy link
Contributor Author

@ahcorde Thanks again for updates! I've fixed the typos and changed the naming as you've suggested, and updated the build/install section.


From the root of your workspace:

.. tab:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. tab:
.. tabs:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've noticed this right after pushing. Already fixed. :)

Signed-off-by: EsipovPA <esipov.p@mail.ru>
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
@ahcorde ahcorde merged commit 001129d into ros2:rolling Jun 27, 2025
2 checks passed
@ahcorde
Copy link
Contributor

ahcorde commented Jun 27, 2025

Thank you / Спасибо @EsipovPA

@ahcorde
Copy link
Contributor

ahcorde commented Jun 27, 2025

https://github.com/Mergifyio backport kilted jazzy humble

@mergify
Copy link

mergify bot commented Jun 27, 2025

backport kilted jazzy humble

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jun 27, 2025
Signed-off-by: EsipovPA <esipov.p@mail.ru>
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
(cherry picked from commit 001129d)
mergify bot pushed a commit that referenced this pull request Jun 27, 2025
Signed-off-by: EsipovPA <esipov.p@mail.ru>
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
(cherry picked from commit 001129d)
mergify bot pushed a commit that referenced this pull request Jun 27, 2025
Signed-off-by: EsipovPA <esipov.p@mail.ru>
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
(cherry picked from commit 001129d)
ahcorde added a commit that referenced this pull request Jun 27, 2025
(cherry picked from commit 001129d)

Signed-off-by: EsipovPA <esipov.p@mail.ru>
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Co-authored-by: Pavel Esipov <38457822+EsipovPA@users.noreply.github.com>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
ahcorde added a commit that referenced this pull request Jun 27, 2025
(cherry picked from commit 001129d)

Signed-off-by: EsipovPA <esipov.p@mail.ru>
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Co-authored-by: Pavel Esipov <38457822+EsipovPA@users.noreply.github.com>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
ahcorde added a commit that referenced this pull request Jun 27, 2025
(cherry picked from commit 001129d)

Signed-off-by: EsipovPA <esipov.p@mail.ru>
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Co-authored-by: Pavel Esipov <38457822+EsipovPA@users.noreply.github.com>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
@EsipovPA EsipovPA deleted the add-tutorials branch July 15, 2025 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend Tutorials Section

2 participants