Skip to content

add a demo of content filter listener#557

Merged
wjwwood merged 10 commits into
ros2:masterfrom
iuhilnehc-ynos:topic-content-filter
May 2, 2022
Merged

add a demo of content filter listener#557
wjwwood merged 10 commits into
ros2:masterfrom
iuhilnehc-ynos:topic-content-filter

Conversation

@iuhilnehc-ynos

Copy link
Copy Markdown
Contributor

Signed-off-by: Chen Lihui lihui.chen@sony.com

Signed-off-by: Chen Lihui <lihui.chen@sony.com>
@iuhilnehc-ynos

Copy link
Copy Markdown
Contributor Author

@asorbini @MiguelCompany

As we know, the content filter has operations as below,
`RelOp ::= ‘=’ | ‘>’ | ‘>=’ | ‘<’ | ‘<=’ | ‘<>’ | like``

I expected that the keyword like can work as https://www.w3schools.com/sql/sql_ref_like.asp.
Unfortunately, it seems it doesn't work.

Is there a limitation in the DDS?

Signed-off-by: Chen Lihui <lihui.chen@sony.com>
@MiguelCompany

Copy link
Copy Markdown
Contributor

@iuhilnehc-ynos On Fast DDS it should work as expected. See the test cases here

RTI Connext, according to this comment, does not support like

@iuhilnehc-ynos

Copy link
Copy Markdown
Contributor Author

@MiguelCompany

RTI Connext, according to this comment, does not support like

Thanks for your information. Sorry, I didn't notice it before.

On Fast DDS it should work as expected.

After confirming, it works fine with rmw_fastrtps_cpp.

Chen Lihui added 2 commits April 7, 2022 22:24
and comment that rmw_connextdds not supported currently

Signed-off-by: Chen Lihui <lihui.chen@sony.com>
Signed-off-by: Chen Lihui <lihui.chen@sony.com>

@ivanpauno ivanpauno left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

Could you add a test here?

@ivanpauno

Copy link
Copy Markdown
Member

@wjwwood @clalancette any objection to merge this now?
We're past the API break, but nothing depends on the demos and it seems worthwile to have a demo of a new feature.

@fujitatomoya

Copy link
Copy Markdown
Collaborator

Once this demo is merged, i will link this demo to Humble Release Note. (see ros2/ros2_documentation#2396)

@wjwwood

wjwwood commented Apr 12, 2022

Copy link
Copy Markdown
Member

I don't mind it getting merged this late, following your logic, but @clalancette should give his thoughts. I didn't review the demo code yet.

@fujitatomoya

Copy link
Copy Markdown
Collaborator

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Comment thread demo_nodes_cpp/src/topics/listener_content_filter.cpp Outdated
Comment thread demo_nodes_cpp/src/topics/listener_content_filter.cpp Outdated
Comment thread demo_nodes_cpp/src/topics/listener_content_filter.cpp Outdated
@ivanpauno

Copy link
Copy Markdown
Member

@iuhilnehc-ynos On Fast DDS it should work as expected. See the test cases here

RTI Connext, according to ros2/design#282 (comment), does not support like

Could we modify the example to work with both?

Signed-off-by: Chen Lihui <lihui.chen@sony.com>
@iuhilnehc-ynos

iuhilnehc-ynos commented Apr 13, 2022

Copy link
Copy Markdown
Contributor Author

@ivanpauno

Could you add a test here?

Sorry, I don't know how to add a test for this listener_content_filter, it seems the current test_executables_tutorial.py.in can't work as I expect.

I expect that running with colcon test --packages-select demo_nodes_cpp --ctest-args -R test_tutorial_talker_listener_content_filter__rmw_cyclonedds_cpp should fail with the patch, but it doesn't.

What I mean is if the test in the above patch can be passed by rmw_cyclonedds_cpp, it seems there is no reason to add it.

Comment thread demo_nodes_cpp/src/topics/listener_content_filter.cpp Outdated
// 'Hello World: 10'.
rclcpp::SubscriptionOptions sub_options;
sub_options.content_filter_options.filter_expression = "data = %0";
sub_options.content_filter_options.expression_parameters = {"'Hello World: 10'"};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe the number (currently 10) could be configurable by the user.
Maybe that makes the demo more interesting (?).
Feel free to ignore the comment though.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I actually agree with this comment. probably string chatter example is interesting enough to show this feature. how about filtering specific range of data? that would be one of the most common case?

@ivanpauno

Copy link
Copy Markdown
Member

I expect that running with colcon test --packages-select demo_nodes_cpp --ctest-args -R test_tutorial_talker_listener_content_filter__rmw_cyclonedds_cpp should fail with the patch, but it doesn't.

Yes, that's not going to work because the test is waiting for the output in the file to be printed

, and that happens as well if no content filter is applied.
You'll need to adapt the test, or adapt the file so it doesn't match the output if "Content filter is not enabled since it's not supported" was logged before (I'm not sure if that's possible).


Please don't share a patch, they are hard to understand without being applied to the code to have more context.
It's better to push the commit and ask the question, as github gives more context (or if you don't want to push in this branch, you can do that in a new branch/fork and share the link to the github diff).

Signed-off-by: Chen Lihui <lihui.chen@sony.com>
@fujitatomoya

Copy link
Copy Markdown
Collaborator

@iuhilnehc-ynos all comments are addressed, right? can you confirm? so that we can ask final review to @ivanpauno @wjwwood

@wjwwood wjwwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just curious why not put this kind of thing in ros2/examples instead?

Comment thread demo_nodes_cpp/src/topics/listener_content_filter.cpp Outdated
Signed-off-by: Chen Lihui <lihui.chen@sony.com>

@ivanpauno ivanpauno left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with @wjwwood approval

@fujitatomoya

Copy link
Copy Markdown
Collaborator

@wjwwood friendly ping.

} else {
RCLCPP_INFO(
this->get_logger(),
"subscribed to topic \"%s\" with filter expression \"data = 'Hello World: 10'\"",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is really fragile, since if someone updated the expression and forgot to update this is would be wrong. Violates DRY.

Can we print out the filter expression and parameters from the content_filter_options directly instead?

Comment on lines +40 to +43
// Create a subscription to the topic which can be matched with one or more compatible ROS
// publishers.
// Note that not all publishers on the same topic with the same type will be compatible:
// they must have compatible Quality of Service policies.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this comment block needed?

@wjwwood

wjwwood commented Apr 19, 2022

Copy link
Copy Markdown
Member

w.r.t. putting it in examples. I think having something here in demos is fine so long as we have a corresponding page about it or the executable is used in some documentation or tutorial. For example, the intra-process demos have this page which shows how to run it, what you should expect to see when you run it, and how it demonstrates that the intra-process feature is working:

https://github.com/ros2/ros2_documentation/blob/rolling/source/Tutorials/Intra-Process-Communication.rst

If we had something similar then this executable makes sense to me. Otherwise, I'd still say examples makes more sense. And I don't think you need a talker equivalent if it is put in examples, the purpose there is to show how to use the API, and it's not part of a tutorial or demo document that tells you to run it and observe some effect.

I hope that distinction makes sense.

@fujitatomoya

fujitatomoya commented Apr 19, 2022

Copy link
Copy Markdown
Collaborator

@wjwwood @ivanpauno
CC: @iuhilnehc-ynos

i just created ros2/examples#341.

how about the following, sounds like a plan?

@wjwwood

wjwwood commented Apr 19, 2022

Copy link
Copy Markdown
Member

ros2/ros2_documentation#2396 can link this demonstration.
adding tutorial how to use, and that doc links to ros2/examples#341

I'd flip this around so that:

We could set up a new example that uses floats or something like you said, but that would be for the demo/tutorial combo and not the minimal example.

Signed-off-by: Chen Lihui <lihui.chen@sony.com>
@fujitatomoya

Copy link
Copy Markdown
Collaborator

@iuhilnehc-ynos

We could set up a new example that uses floats or something like you said, but that would be for the demo/tutorial combo and not the minimal example.

can we address this? current code looks good to us, just adjusting data type for using float to simulate the situation to filtering the sensing data. for doing that, we need to add publisher as well.

how about following?

  • emergency temperature demonstration
    • say publisher is publishing temperature data with std_msgs/msg/Float64. make a loop to publish data -100 to +150 F in order with certain offset.
    • subscription use content filtering (if it is supported), and only receives data with “data < %0 OR data > %1” with {"-30.0", "100.0"}, then print emergency temperature.

i believe demonstrating with expected common use case would be much easier to get the picture of this feature for user.

Signed-off-by: Chen Lihui <lihui.chen@sony.com>
@iuhilnehc-ynos

Copy link
Copy Markdown
Contributor Author

@ros-pull-request-builder retest this please

@fujitatomoya fujitatomoya left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

implementation looks good to me.

Comment thread demo_nodes_cpp/CMakeLists.txt Outdated
Comment on lines +74 to +75
src/topics/temperature_publisher.cpp
src/topics/temperature_subscriber.cpp

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
src/topics/temperature_publisher.cpp
src/topics/temperature_subscriber.cpp
src/topics/content_filtering_publisher.cpp
src/topics/content_filtering_subscriber.cpp

sorry i was not clear on this, i think files, classes and components can be general names for content filtering, so that user can tell these are related to content filtering.

@ivanpauno ivanpauno left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Example looks really nice!
Thanks for the work!

@wjwwood

wjwwood commented Apr 25, 2022

Copy link
Copy Markdown
Member

Do you guys have demo documentation to go with this? Something along the lines of this document: https://docs.ros.org/en/rolling/Tutorials/Intra-Process-Communication.html

@fujitatomoya

Copy link
Copy Markdown
Collaborator

@wjwwood i will be back with PR for that, let me have a couple of days.

@wjwwood

wjwwood commented Apr 25, 2022

Copy link
Copy Markdown
Member

Sure, no problem, I would just hold this until that is ready.

Signed-off-by: Chen Lihui <lihui.chen@sony.com>
@fujitatomoya

Copy link
Copy Markdown
Collaborator

@wjwwood @ivanpauno @iuhilnehc-ynos
CC: @clalancette

i just opened ros2/ros2_documentation#2441, could you guys take a look at to give me some feedback?

@fujitatomoya

Copy link
Copy Markdown
Collaborator

either @wjwwood or @clalancette

can you merge this with ros2/ros2_documentation#2441 at the same time?

@ivanpauno

ivanpauno commented Apr 29, 2022

Copy link
Copy Markdown
Member

can you merge this with ros2/ros2_documentation#2441 at the same time?

It seems that CI wasn't run after the last changes, running it:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@fujitatomoya

Copy link
Copy Markdown
Collaborator

@ivanpauno thanks! all green, can you merge this?

@fujitatomoya

Copy link
Copy Markdown
Collaborator

@clalancette can you merge this? i already did ros2/ros2_documentation#2441

@fujitatomoya

Copy link
Copy Markdown
Collaborator

this is only required to backport humble package.

@wjwwood wjwwood merged commit a1bc6dc into ros2:master May 2, 2022
@wjwwood

wjwwood commented May 2, 2022

Copy link
Copy Markdown
Member

@Mergifyio backport humble

mergify Bot pushed a commit that referenced this pull request May 2, 2022
* add a demo of content filter listener

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* add warn message if content filter is not supported by DDS

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* keep `like` to make the demo simple

and comment that rmw_connextdds not supported currently

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* remove the macro as it will be removed in the rclcpp

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* use = instead of like

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* address reviews

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* not make this configurable from the cli

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* remove comment and update log output

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* use temperature instead of chatter

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* rename

Signed-off-by: Chen Lihui <lihui.chen@sony.com>
(cherry picked from commit a1bc6dc)
@mergify

mergify Bot commented May 2, 2022

Copy link
Copy Markdown
Contributor

backport humble

✅ Backports have been created

Details

wjwwood pushed a commit that referenced this pull request May 2, 2022
* add a demo of content filter listener

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* add warn message if content filter is not supported by DDS

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* keep `like` to make the demo simple

and comment that rmw_connextdds not supported currently

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* remove the macro as it will be removed in the rclcpp

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* use = instead of like

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* address reviews

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* not make this configurable from the cli

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* remove comment and update log output

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* use temperature instead of chatter

Signed-off-by: Chen Lihui <lihui.chen@sony.com>

* rename

Signed-off-by: Chen Lihui <lihui.chen@sony.com>
(cherry picked from commit a1bc6dc)

Co-authored-by: Chen Lihui <lihui.chen@sony.com>
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.

5 participants