Skip to content

Commit 0e3e9b1

Browse files
Add new tutorials (#692)
The tutorials contain the code for the new Connext Guide.
1 parent 89a721e commit 0e3e9b1

File tree

142 files changed

+6524
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+6524
-24
lines changed

README.md

+30-24
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
# rticonnextdds-examples
1+
# RTI Connext Examples
22

3-
This repository includes examples on how to use specific features of RTI
4-
Connext DDS.
3+
This repository includes:
54

6-
To contribute enhancements or additional examples to the repository, follow the
7-
instructions on our [RTI Connext DDS Examples
8-
Wiki](https://github.com/rticommunity/rticonnextdds-examples/wiki). Your
9-
contributions will be reviewed and as soon as they are approved they will
10-
automatically be included in the [RTI Community Portal Examples
11-
Section](http://community.rti.com). See [CONTRIBUTING.md](https://github.com/rticommunity/rticonnextdds-examples/blob/master/CONTRIBUTING.md)
12-
for further information about how to contribute with new examples to this repository.
5+
- Code examples on how to use specific Connext features (under [examples/](./examples))
6+
- Supporting code for learning materials (under [tutorials/](./tutorials))
7+
8+
## Cloning the repository
9+
10+
To clone the repository you will need to run `git clone` as follows to download
11+
both the repository and its submodule dependencies:
12+
13+
```bash
14+
git clone --recurse-submodule https://github.com/rticommunity/rticonnextdds-examples.git
15+
```
16+
17+
If you forget to clone the repository with `--recurse-submodule`, simply run
18+
the following command to pull all the dependencies:
19+
20+
```bash
21+
git submodule update --init --recursive
22+
```
23+
24+
## Versioning
1325

1426
The examples contained in the
1527
[master](https://github.com/rticommunity/rticonnextdds-examples/tree/master)
@@ -29,18 +41,12 @@ versions of RTI Connext DDS, please check out the appropriate branch:
2941
- [release/5.1.0](https://github.com/rticommunity/rticonnextdds-examples/tree/release/5.1.0)
3042
- [release/5.0.0](https://github.com/rticommunity/rticonnextdds-examples/tree/release/5.0.0)
3143

32-
## Cloning Repository
33-
34-
To clone the repository you will need to run `git clone` as follows to download
35-
both the repository and its submodule dependencies:
36-
37-
```bash
38-
git clone --recurse-submodule https://github.com/rticommunity/rticonnextdds-examples.git
39-
```
40-
41-
If you forget to clone the repository with `--recurse-submodule`, simply run
42-
the following command to pull all the dependencies:
44+
## How to contribute
4345

44-
```bash
45-
git submodule update --init --recursive
46-
```
46+
To contribute enhancements or additional examples to the repository, follow the
47+
instructions on our [RTI Connext DDS Examples
48+
Wiki](https://github.com/rticommunity/rticonnextdds-examples/wiki). Your
49+
contributions will be reviewed and as soon as they are approved they will
50+
automatically be included in the [RTI Community Portal Examples
51+
Section](http://community.rti.com). See [CONTRIBUTING.md](https://github.com/rticommunity/rticonnextdds-examples/blob/master/CONTRIBUTING.md)
52+
for further information about how to contribute with new examples to this repository.

tutorials/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# RTI Connext Tutorials
2+
3+
The code included in this directory is the supporting material for the tutorials
4+
in the
5+
[Connext Developer](https://community.rti.com/static/documentation/developers/index.html)
6+
page.
7+
8+
Please follow the instructions for each tutorial under *Learn*.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#
2+
# (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved.
3+
#
4+
# RTI grants Licensee a license to use, modify, compile, and create derivative
5+
# works of the Software. Licensee has the right to distribute object form
6+
# only for use with RTI products. The Software is provided "as is", with no
7+
# warranty of any type, including any warranty for fitness for any purpose.
8+
# RTI is under no obligation to maintain or support the Software. RTI shall
9+
# not be liable for any incidental or consequential damages arising out of the
10+
# use or inability to use the software.
11+
#
12+
13+
cmake_minimum_required(VERSION 3.11)
14+
project(connext-tutorial-content-filtering)
15+
list(APPEND CMAKE_MODULE_PATH
16+
"${CMAKE_CURRENT_SOURCE_DIR}/../../../resources/cmake/Modules"
17+
)
18+
include(ConnextDdsConfigureCmakeUtils)
19+
connextdds_configure_cmake_utils()
20+
21+
# Include ConnextDdsAddExample.cmake from resources/cmake
22+
include(ConnextDdsAddExample)
23+
24+
connextdds_call_codegen(
25+
IDL "home_automation"
26+
LANG "C++11"
27+
PREFIX "home_automation"
28+
)
29+
30+
connextdds_add_application(
31+
TARGET "publisher"
32+
LANG "C++11"
33+
OUTPUT_NAME "home_automation_publisher"
34+
SOURCES
35+
$<TARGET_OBJECTS:home_automation_CXX11_obj>
36+
"${CMAKE_CURRENT_SOURCE_DIR}/home_automation_publisher.cxx"
37+
DEPENDENCIES
38+
${_CONNEXT_DEPENDENCIES}
39+
)
40+
41+
connextdds_add_application(
42+
TARGET "subscriber"
43+
LANG "C++11"
44+
OUTPUT_NAME "home_automation_subscriber"
45+
SOURCES
46+
$<TARGET_OBJECTS:home_automation_CXX11_obj>
47+
"${CMAKE_CURRENT_SOURCE_DIR}/home_automation_subscriber.cxx"
48+
DEPENDENCIES
49+
${_CONNEXT_DEPENDENCIES}
50+
)
51+
52+
connextdds_add_application(
53+
TARGET "subscriber_update_filter"
54+
LANG "C++11"
55+
OUTPUT_NAME "home_automation_subscriber_update_filter"
56+
SOURCES
57+
$<TARGET_OBJECTS:home_automation_CXX11_obj>
58+
"${CMAKE_CURRENT_SOURCE_DIR}/home_automation_subscriber_update_filter.cxx"
59+
DEPENDENCIES
60+
${_CONNEXT_DEPENDENCIES}
61+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Tutorial: Content Filtering
2+
3+
This code is part of the Connext
4+
[Content Filtering](https://community.rti.com/static/documentation/developers/learn/content-filtering.html)
5+
tutorial.
6+
7+
## Building the Example :wrench:
8+
9+
You can build the example following the instructions in the tutorial, or you can
10+
build it using CMake as follows.
11+
12+
1. Generate the build files:
13+
14+
```sh
15+
mkdir build
16+
cd build
17+
cmake ..
18+
```
19+
20+
This command will try to find the location of your Connext installation. If it
21+
can't find it, specify it with the ``-DCONNEXTDDS_DIR`` option, for example:
22+
23+
```sh
24+
cmake -DCONNEXTDDS_DIR=/home/rti/rti_connext_dds-x.y.z ..
25+
```
26+
27+
If you are compiling for windows you may also need to specify the
28+
[generator](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html),
29+
and platform.
30+
31+
```sh
32+
cmake .. -G "Visual Studio 17 2022" -A x64
33+
```
34+
35+
2. Build the applications:
36+
37+
```sh
38+
cmake --build .
39+
```
40+
41+
If you are using a multi-configuration generator, such as Visual Studio
42+
solutions, you can specify the configuration mode to build as follows:
43+
44+
```sh
45+
cmake --build . --config Release|Debug
46+
```
47+
48+
## Running the Example :rocket:
49+
50+
See the tutorial for instructions.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
(c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved.
4+
RTI grants Licensee a license to use, modify, compile, and create derivative
5+
works of the Software. Licensee has the right to distribute object form only
6+
for use with RTI products. The Software is provided "as is", with no warranty
7+
of any type, including any warranty for fitness for any purpose. RTI is under
8+
no obligation to maintain or support the Software. RTI shall not be liable for
9+
any incidental or consequential damages arising out of the use or inability to
10+
use the software.
11+
-->
12+
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://community.rti.com/schema/current/rti_dds_profiles.xsd">
13+
<qos_library name="MyLibrary">
14+
<qos_profile name="MyProfile" is_default_qos="true">
15+
<base_name>
16+
<element>BuiltinQosLib::Generic.StrictReliable</element>
17+
</base_name>
18+
</qos_profile>
19+
</qos_library>
20+
</dds>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved.
3+
*
4+
* RTI grants Licensee a license to use, modify, compile, and create derivative
5+
* works of the Software. Licensee has the right to distribute object form
6+
* only for use with RTI products. The Software is provided "as is", with no
7+
* warranty of any type, including any warranty for fitness for any purpose.
8+
* RTI is under no obligation to maintain or support the Software. RTI shall
9+
* not be liable for any incidental or consequential damages arising out of the
10+
* use or inability to use the software.
11+
*/
12+
13+
struct DeviceStatus {
14+
@key string sensor_name;
15+
string room_name;
16+
boolean is_open;
17+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved.
3+
//
4+
// RTI grants Licensee a license to use, modify, compile, and create derivative
5+
// works of the Software. Licensee has the right to distribute object form
6+
// only for use with RTI products. The Software is provided "as is", with no
7+
// warranty of any type, including any warranty for fitness for any purpose.
8+
// RTI is under no obligation to maintain or support the Software. RTI shall
9+
// not be liable for any incidental or consequential damages arising out of the
10+
// use or inability to use the software.
11+
//
12+
13+
#include <iostream>
14+
#include <thread>
15+
#include <rti/rti.hpp>
16+
#include "home_automation.hpp"
17+
18+
void publish_sensor(
19+
const std::string &sensor_name,
20+
const std::string &room_name)
21+
{
22+
dds::domain::DomainParticipant participant(0);
23+
dds::topic::Topic<DeviceStatus> topic(participant, "WindowStatus");
24+
dds::pub::DataWriter<DeviceStatus> writer(topic);
25+
26+
DeviceStatus device_status { sensor_name, room_name, false };
27+
for (int i = 0; i < 1000; i++) {
28+
device_status.is_open(!device_status.is_open());
29+
writer.write(device_status);
30+
std::this_thread::sleep_for(std::chrono::seconds(2));
31+
}
32+
}
33+
34+
int main(int argc, char **argv)
35+
{
36+
std::string sensor_name = (argc > 1) ? argv[1] : "Window1";
37+
std::string room_name = (argc > 2) ? argv[2] : "LivingRoom";
38+
publish_sensor(sensor_name, room_name);
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved.
3+
//
4+
// RTI grants Licensee a license to use, modify, compile, and create derivative
5+
// works of the Software. Licensee has the right to distribute object form
6+
// only for use with RTI products. The Software is provided "as is", with no
7+
// warranty of any type, including any warranty for fitness for any purpose.
8+
// RTI is under no obligation to maintain or support the Software. RTI shall
9+
// not be liable for any incidental or consequential damages arising out of the
10+
// use or inability to use the software.
11+
//
12+
13+
#include <iostream>
14+
#include <thread>
15+
16+
#include "rti/rti.hpp"
17+
#include "rti/sub/SampleProcessor.hpp"
18+
#include "home_automation.hpp"
19+
20+
int main(int argc, char **argv)
21+
{
22+
dds::domain::DomainParticipant participant(0);
23+
dds::topic::Topic<DeviceStatus> topic(participant, "WindowStatus");
24+
dds::topic::ContentFilteredTopic<DeviceStatus> content_filtered_topic(
25+
topic,
26+
"FilterRoomAndOpenWindows",
27+
dds::topic::Filter("is_open = true and room_name = 'LivingRoom'"));
28+
dds::sub::DataReader<DeviceStatus> reader(content_filtered_topic);
29+
30+
rti::sub::SampleProcessor sample_processor;
31+
sample_processor.attach_reader(
32+
reader,
33+
[](const rti::sub::LoanedSample<DeviceStatus> &sample) {
34+
if (sample.info().valid()) { // ignore samples with only
35+
// meta-data
36+
std::cout << "WARNING: " << sample.data().sensor_name()
37+
<< " in " << sample.data().room_name()
38+
<< " is open!" << std::endl;
39+
}
40+
});
41+
42+
while (true) { // wait in a loop
43+
std::this_thread::sleep_for(std::chrono::seconds(4));
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved.
3+
//
4+
// RTI grants Licensee a license to use, modify, compile, and create derivative
5+
// works of the Software. Licensee has the right to distribute object form
6+
// only for use with RTI products. The Software is provided "as is", with no
7+
// warranty of any type, including any warranty for fitness for any purpose.
8+
// RTI is under no obligation to maintain or support the Software. RTI shall
9+
// not be liable for any incidental or consequential damages arising out of the
10+
// use or inability to use the software.
11+
//
12+
13+
#include <iostream>
14+
#include <thread>
15+
16+
#include "rti/rti.hpp"
17+
#include "rti/sub/SampleProcessor.hpp"
18+
#include "home_automation.hpp"
19+
20+
int main(int argc, char **argv)
21+
{
22+
dds::domain::DomainParticipant participant(0);
23+
dds::topic::Topic<DeviceStatus> topic(participant, "WindowStatus");
24+
dds::core::StringSeq parameters(1, "'LivingRoom'");
25+
dds::topic::ContentFilteredTopic<DeviceStatus> content_filtered_topic(
26+
topic,
27+
"FilterRoomAndOpenWindows",
28+
dds::topic::Filter(
29+
"is_open = true and room_name = %0",
30+
parameters));
31+
dds::sub::DataReader<DeviceStatus> reader(content_filtered_topic);
32+
33+
parameters[0] = "'Kitchen'";
34+
content_filtered_topic.filter_parameters(
35+
parameters.begin(),
36+
parameters.end());
37+
38+
rti::sub::SampleProcessor sample_processor;
39+
sample_processor.attach_reader(
40+
reader,
41+
[](const rti::sub::LoanedSample<DeviceStatus> &sample) {
42+
if (sample.info().valid()) { // ignore samples with only
43+
// meta-data
44+
std::cout << "WARNING: " << sample.data().sensor_name()
45+
<< " in " << sample.data().room_name()
46+
<< " is open!" << std::endl;
47+
}
48+
});
49+
50+
while (true) { // wait in a loop
51+
std::this_thread::sleep_for(std::chrono::seconds(4));
52+
}
53+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Tutorial: Content Filtering
2+
3+
This code is part of the Connext
4+
[Content Filtering](https://community.rti.com/static/documentation/developers/learn/content-filtering.html)
5+
tutorial and is included here in full for convenience.
6+
7+
Please see the tutorial for instructions.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
(c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved.
4+
RTI grants Licensee a license to use, modify, compile, and create derivative
5+
works of the Software. Licensee has the right to distribute object form only
6+
for use with RTI products. The Software is provided "as is", with no warranty
7+
of any type, including any warranty for fitness for any purpose. RTI is under
8+
no obligation to maintain or support the Software. RTI shall not be liable for
9+
any incidental or consequential damages arising out of the use or inability to
10+
use the software.
11+
-->
12+
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://community.rti.com/schema/current/rti_dds_profiles.xsd">
13+
<qos_library name="MyLibrary">
14+
<qos_profile name="MyProfile" is_default_qos="true">
15+
<base_name>
16+
<element>BuiltinQosLib::Generic.StrictReliable</element>
17+
</base_name>
18+
</qos_profile>
19+
</qos_library>
20+
</dds>

0 commit comments

Comments
 (0)