-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add Topic Keys tutorials #5573
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
base: rolling
Are you sure you want to change the base?
Add Topic Keys tutorials #5573
Conversation
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
a14dc46
to
1d46bd0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some general comments
- use
..code-block: console, then use
$` in every command included in the block - Support cmd for al tier 1 platforms
ament_target_dependencies
is deprecated, please change it totarget_link_libraries
.. code-block:: bash | ||
|
||
docker run -it --rm osrt/ros:{DISTRO}-desktop | ||
|
||
Then, within the container, source the ROS 2 installation with: | ||
|
||
.. code-block:: bash | ||
|
||
source /opt/ros/{DISTRO}/setup.bash | ||
|
||
#. Running the tutorial on the local host. | ||
Please, follow the :doc:`installation instructions <../../../Installation>` for details on installing ROS 2. | ||
|
||
Source the following file to setup the ROS 2 environment: | ||
|
||
.. code-block:: bash | ||
|
||
source /opt/ros/{DISTRO}/setup.bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: bash | |
docker run -it --rm osrt/ros:{DISTRO}-desktop | |
Then, within the container, source the ROS 2 installation with: | |
.. code-block:: bash | |
source /opt/ros/{DISTRO}/setup.bash | |
#. Running the tutorial on the local host. | |
Please, follow the :doc:`installation instructions <../../../Installation>` for details on installing ROS 2. | |
Source the following file to setup the ROS 2 environment: | |
.. code-block:: bash | |
source /opt/ros/{DISTRO}/setup.bash | |
.. code-block:: console | |
$ docker run -it --rm osrt/ros:{DISTRO}-desktop | |
Then, within the container, source the ROS 2 installation with: | |
.. code-block:: console | |
$ source /opt/ros/{DISTRO}/setup.bash | |
#. Running the tutorial on the local host. | |
Please, follow the :doc:`installation instructions <../../../Installation>` for details on installing ROS 2. | |
Source the following file to setup the ROS 2 environment: | |
.. code-block:: console | |
$ source /opt/ros/{DISTRO}/setup.bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also extend source /opt/ros/{DISTRO}/setup.bash
with different plantforms (including windows)
.. code-block:: bash | ||
|
||
# Create directory structure | ||
mkdir -p ~/tutorial_ws/src/demo_keys_filtering_cpp | ||
mkdir ~/tutorial_ws/src/demo_keys_filtering_cpp/msg | ||
mkdir ~/tutorial_ws/src/demo_keys_filtering_cpp/src | ||
mkdir ~/tutorial_ws/src/demo_keys_filtering_cpp/launch | ||
cd ~/tutorial_ws/src/demo_keys_filtering_cpp | ||
|
||
# Download demo package source code | ||
wget -O CMakeLists.txt https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/CMakeLists.txt | ||
wget -O package.xml https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/package.xml | ||
wget -O README.md https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/README.md | ||
wget -O msg/KeyedSensorDataMsg.msg https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/msg/KeyedSensorDataMsg.msg | ||
wget -O src/filtered_keyed_sensor.cpp https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/src/filtered_keyed_sensor.cpp | ||
wget -O src/filtered_keyed_controller.cpp https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/src/filtered_keyed_controller.cpp | ||
wget -O launch/keyed_sensors_launch.py https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/launch/keyed_sensors_launch.py | ||
|
||
The resulting directory structure should be: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: bash | |
# Create directory structure | |
mkdir -p ~/tutorial_ws/src/demo_keys_filtering_cpp | |
mkdir ~/tutorial_ws/src/demo_keys_filtering_cpp/msg | |
mkdir ~/tutorial_ws/src/demo_keys_filtering_cpp/src | |
mkdir ~/tutorial_ws/src/demo_keys_filtering_cpp/launch | |
cd ~/tutorial_ws/src/demo_keys_filtering_cpp | |
# Download demo package source code | |
wget -O CMakeLists.txt https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/CMakeLists.txt | |
wget -O package.xml https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/package.xml | |
wget -O README.md https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/README.md | |
wget -O msg/KeyedSensorDataMsg.msg https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/msg/KeyedSensorDataMsg.msg | |
wget -O src/filtered_keyed_sensor.cpp https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/src/filtered_keyed_sensor.cpp | |
wget -O src/filtered_keyed_controller.cpp https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/src/filtered_keyed_controller.cpp | |
wget -O launch/keyed_sensors_launch.py https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/launch/keyed_sensors_launch.py | |
The resulting directory structure should be: | |
.. code-block:: console | |
# Create directory structure | |
$ mkdir -p ~/tutorial_ws/src/demo_keys_filtering_cpp | |
$ mkdir ~/tutorial_ws/src/demo_keys_filtering_cpp/msg | |
$ mkdir ~/tutorial_ws/src/demo_keys_filtering_cpp/src | |
$ mkdir ~/tutorial_ws/src/demo_keys_filtering_cpp/launch | |
$ cd ~/tutorial_ws/src/demo_keys_filtering_cpp | |
# Download demo package source code | |
$ wget -O CMakeLists.txt https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/CMakeLists.txt | |
$ wget -O package.xml https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/package.xml | |
$ wget -O README.md https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/README.md | |
$ wget -O msg/KeyedSensorDataMsg.msg https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/msg/KeyedSensorDataMsg.msg | |
$ wget -O src/filtered_keyed_sensor.cpp https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/src/filtered_keyed_sensor.cpp | |
$ wget -O src/filtered_keyed_controller.cpp https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/src/filtered_keyed_controller.cpp | |
$ wget -O launch/keyed_sensors_launch.py https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Topic-Keys/resources/Filtered/launch/keyed_sensors_launch.py | |
The resulting directory structure should be: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also CMD support for other platforms
|
||
* ``filtered_keyed_controller.cpp``: This is the source code for a controller node that filters keyed sensor data in reception, being the most relevant lines the ones that define the filter expression and Quality of Service settings: | ||
|
||
.. code-block:: bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: bash | |
.. code-block:: cpp |
* ``filtered_keyed_sensor.cpp``: This is the source code for a sensor node that publishes keyed sensor data. | ||
The most relevant lines are the ones that create the publication with a particular Quality of Service settings that enables the controller to late join the application but still receiving the latest update for every instance with the use of topic keys. | ||
|
||
.. code-block:: bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: bash | |
.. code-block:: cpp |
|
||
Generate the corresponding IDL definition from the provided ``KeyedSensorDataMsg.msg`` file, using the ``msg2idl.py`` script from the ``rosidl_adapter`` package. | ||
|
||
.. code-block:: bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: bash | |
.. code-block:: console |
// Create a callback function for when messages are received. | ||
setvbuf(stdout, NULL, _IONBF, BUFSIZ); | ||
auto callback = | ||
[this](demo_keys_filtering_cpp::msg::KeyedSensorDataMsg::ConstSharedPtr msg) -> void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include <memory>
"subscribed to topic \"%s\" with content filter options \"%s, {%s}\"", | ||
sub_->get_topic_name(), | ||
sub_options.content_filter_options.filter_expression.c_str(), | ||
rcpputils::join(sub_options.content_filter_options.expression_parameters, ", ").c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include header
period_ = std::chrono::milliseconds(id_ * 1000); | ||
measurement_ = distribution_(generator_); | ||
|
||
setvbuf(stdout, NULL, _IONBF, BUFSIZ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include <cstdio>
uint16_t id_{0}; | ||
std::chrono::milliseconds period_{1000}; | ||
std::default_random_engine generator_; | ||
std::uniform_real_distribution<float> distribution_{50.0, 90.0}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::uniform_real_distribution<float> distribution_{50.0, 90.0}; | |
std::uniform_real_distribution<float> distribution_{50.0f, 90.0f}; |
} | ||
|
||
private: | ||
uint16_t id_{0}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include <cstdint>
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
Friendly ping @fujitatomoya, you may also be interested in reviewing this |
CC: @MiguelCompany |
I suppose @fgallegosalido and @lobolanja, who made the changes in the Connext RMW, might want to take a look |
We'll take a look into it. Thanks for the heads up! |
@@ -0,0 +1,51 @@ | |||
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copyright year should be 2025. Review other files too.
Tutorials look good to me. Just a minor comment on the licensing year. |
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
Following the Topic instances support, this PR adds two tutorials for exemplifying the use of topic instances in ROS 2.