Skip to content
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

Add matched event demo for rclcpp and rclpy #607

Merged
merged 8 commits into from
Apr 13, 2023

Conversation

Barry-Xu-2018
Copy link
Contributor

Address ros2/rmw#330

Signed-off-by: Barry Xu <barry.xu@sony.com>
Copy link
Contributor

@iuhilnehc-ynos iuhilnehc-ynos left a comment

Choose a reason for hiding this comment

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

// See the License for the specific language governing permissions and
// limitations under the License.

#include "rcl/event.h"
Copy link
Contributor

@iuhilnehc-ynos iuhilnehc-ynos Mar 24, 2023

Choose a reason for hiding this comment

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

I think we should not use rcl header file in this application

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it depends on implementation, but in this demo, we do not need to include this file i think.

{
rclcpp::PublisherOptions pub_options;
pub_options.event_callbacks.matched_callback =
[this](rmw_matched_status_t & s) {
Copy link
Contributor

Choose a reason for hiding this comment

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

use rclcpp::MatchedInfo instead?

@Barry-Xu-2018
Copy link
Contributor Author

README.md need to be updated.
I will update it.

@Barry-Xu-2018
Copy link
Contributor Author

a new test is required in https://github.com/ros2/demos/tree/9fbd3e840113e183b7ccc935e17fa275fdea6540/demo_nodes_cpp/test

matched_event_detect like 'service'. What output depend on 'client' behavior.
This PR doesn't provide 'client'.
I want to use 'ros2 topic echo' and 'ros2 topic pub' command as 'client'.
Not sure whether current test framework can support it or not.

@iuhilnehc-ynos
Copy link
Contributor

matched_event_detect like 'service'. What output depend on 'client' behavior.
This PR doesn't provide 'client'.
I want to use 'ros2 topic echo' and 'ros2 topic pub' command as 'client'.
Not sure whether current test framework can support it or not.

I see. Let's hear others' opinions.

Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

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, but some comments need to be addressed.

// See the License for the specific language governing permissions and
// limitations under the License.

#include "rcl/event.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it depends on implementation, but in this demo, we do not need to include this file i think.

Comment on lines 105 to 106
bool connect_subscription_{false};
bool connect_publisher_{false};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
bool connect_subscription_{false};
bool connect_publisher_{false};
bool any_subscription_connected_{false};
bool any_publisher_connected_{false};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay

} else {
RCLCPP_INFO(
this->get_logger(),
"Current number of connected publisher is %lu", s.current_count);
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about adding current_change to show the user application can see difference? I think total_xxx would be overkill.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay

namespace demo_nodes_cpp
{

// This demo program shows detected matched event.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// This demo program shows detected matched event.
// This demo program shows matched event works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

{

// This demo program shows detected matched event.
// Matched event occur while connection between publisher and subscription is done.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Matched event occur while connection between publisher and subscription is done.
// Matched event occurs when publisher and subscription establishes the connection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

Comment on lines 35 to 39
// For checking matched event of publisher
// On another console, run below command
// $ ros2 topic echo /pub_matched_event_detect
// You can run above command many times on different consoles to check the number of connected
// subscription by the output of demo program.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that it would be better to show the complete demonstration by itself. that said, what about having the client endpoint to fire the matched event callback in the demo code, instead of ros2cli?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I will update code to remove dependency of ros2cli.

Signed-off-by: Barry Xu <barry.xu@sony.com>
@Barry-Xu-2018
Copy link
Contributor Author

matched_event_detect like 'service'. What output depend on 'client' behavior.
This PR doesn't provide 'client'.
I want to use 'ros2 topic echo' and 'ros2 topic pub' command as 'client'.
Not sure whether current test framework can support it or not.

I see. Let's hear others' opinions.

I change demo codes to remove dependency of roscli. So now I can add test. @iuhilnehc-ynos

@fujitatomoya
Copy link
Collaborator

lgtm, @iuhilnehc-ynos can you do another review on this? if it is good to go, please start the CI.

Copy link
Contributor

@iuhilnehc-ynos iuhilnehc-ynos left a comment

Choose a reason for hiding this comment

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

I just left some comments from my point of view.

class MatchedEventDetectNode : public rclcpp::Node
{
public:
DEMO_NODES_CPP_PUBLIC explicit MatchedEventDetectNode(
Copy link
Contributor

Choose a reason for hiding this comment

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

If using the main in this file, which means this file will not be built into a library, I think it's unnecessary to add DEMO_NODES_CPP_PUBLIC.

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.


#include "std_msgs/msg/string.hpp"

#include "demo_nodes_cpp/visibility_control.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove it if not to build the following classes into a library.

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. Should remove it.
Thanks.

topic_name_,
10,
[](std_msgs::msg::String::ConstSharedPtr) {});
subs_.emplace_back(sub);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to output an info message that there is a subscription coming, which will make the whole output a little more clear. (destroy_one_sub as well)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay.

subs_.emplace_back(sub);
}

DEMO_NODES_CPP_PUBLIC void destroy_one_sub(void)
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if it's a demo that we can control the whole process, I think we should design a better behavior in this method. It's just a suggestion,

rclcpp::Subscription<std_msgs::msg::String>::WeakPtr create_one_sub(void);
void destroy_one_sub(rclcpp::Subscription<std_msgs::msg::String>::WeakPtr sub);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you means test as the below

  auto sub1 = multi_sub_node->create_one_sub();
  executor.spin_some(200ms);

  auto sub2 = multi_sub_node->create_one_sub();
  executor.spin_some(200ms);

  multi_sub_node->destroy_one_sub(sub1);
  executor.spin_some(200ms);

  multi_sub_node->destroy_one_sub(sub2);
  executor.spin_some(200ms);

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes.

'''


class MatchedEventDetectNode(Node):
Copy link
Contributor

Choose a reason for hiding this comment

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

The behavior for the matched event detect in demo_nodes_cpp is different from demo_nodes_py, which might seem not good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I use the same logic as demo_nodes_cpp.

The changed number of connected subscription is -1 and current number of connected subscription is 1.
Last subscription is disconnected.
First publisher is connected.
The changed number of connected publisher is 1 and Current number of connected publisher is 2.
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
The changed number of connected publisher is 1 and Current number of connected publisher is 2.
The changed number of connected publisher is 1 and current number of connected publisher is 2.

please update README.md and matched_event_detect.cpp as well.

Signed-off-by: Barry Xu <barry.xu@sony.com>
Signed-off-by: Barry Xu <barry.xu@sony.com>
@Barry-Xu-2018
Copy link
Contributor Author

Barry-Xu-2018 commented Mar 27, 2023

I updated your comments @fujitatomoya @iuhilnehc-ynos
Please check again

self.destroy_subscription(sub)

def __sub_callback(self, msg):
True
Copy link
Contributor

@iuhilnehc-ynos iuhilnehc-ynos Mar 27, 2023

Choose a reason for hiding this comment

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

Generally, I think we will use pass instead of True here.
a better way to use an empty callback for the subscription might use

sub = self.create_subscription(String, self.__topic_name, lambda msg: ..., 10)

and then remove __sub_callback. (please update other places as well)

Copy link
Contributor

Choose a reason for hiding this comment

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

After the above update, I'll trigger the CI.

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. Revised it.

Signed-off-by: Barry Xu <barry.xu@sony.com>
@iuhilnehc-ynos
Copy link
Contributor

CI:

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

@fujitatomoya
Copy link
Collaborator

@Barry-Xu-2018 test with connextdds is failing, could you check the failure?

Signed-off-by: Barry Xu <barry.xu@sony.com>
@Barry-Xu-2018
Copy link
Contributor Author

I cannot reproduce this problem in my local environment.
I guess waiting time is too short for test.
So I extend waiting time.
Please help to run CI again @iuhilnehc-ynos

@iuhilnehc-ynos
Copy link
Contributor

CI:

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

Signed-off-by: Barry Xu <barry.xu@sony.com>
@Barry-Xu-2018
Copy link
Contributor Author

@iuhilnehc-ynos Help to run CI again.

@iuhilnehc-ynos
Copy link
Contributor

CI:

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

Signed-off-by: Barry Xu <barry.xu@sony.com>
@Barry-Xu-2018
Copy link
Contributor Author

Update to codes to ensure the program does spin until the matched event occurs.

@Barry-Xu-2018
Copy link
Contributor Author

@iuhilnehc-ynos Please help to run CI again

@iuhilnehc-ynos
Copy link
Contributor

iuhilnehc-ynos commented Mar 28, 2023

@iuhilnehc-ynos Please help to run CI again

CI:

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

@Barry-Xu-2018
Copy link
Contributor Author

CI failure is related to a bug in Fastdds.
eProsima/Fast-DDS#3395
The fix was submitted. eProsima/Fast-DDS#3396
We have to wait for this patch merged.

@fujitatomoya
Copy link
Collaborator

CI failure is related to a bug in Fastdds. eProsima/Fast-DDS#3395 The fix was submitted. eProsima/Fast-DDS#3396 We have to wait for this patch merged.

that makes sense, to avoid double triggered, update_publication_matched_status does only updating the cached publication matched event only.

@iuhilnehc-ynos
Copy link
Contributor

CI:

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

@Barry-Xu-2018
Copy link
Contributor Author

CI for Linux didn't run.
Please help to run Linux again @iuhilnehc-ynos

@iuhilnehc-ynos
Copy link
Contributor

CI for Linux didn't run. Please help to run Linux again @iuhilnehc-ynos

CI is busy building some nighty jobs. Please be patient.

@fujitatomoya
Copy link
Collaborator

@clalancette @audrow can you do us a favor? we do not have merge permission to this repo.

after either of you merged this PR, i will merge the following accordingly. (or if you can do that, that would be nice!!!)

@iuhilnehc-ynos
Copy link
Contributor

Based on eProsima/Fast-DDS#3395 (comment), we found Fast-DDS is updated again, just in case, I need to re-trigger CI:

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

@fujitatomoya
Copy link
Collaborator

it looks like eProsima/Fast-DDS#3418 brings CI failure once again?

@Barry-Xu-2018
Copy link
Contributor Author

it looks like eProsima/Fast-DDS#3418 brings CI failure once again?
Yes. @MiguelCompany explain this change in eProsima/Fast-DDS#3395 (comment).

I will consider how to resolve it.

@Barry-Xu-2018
Copy link
Contributor Author

Now depend on the fix issue ros2/rmw_fastrtps#681

@fujitatomoya
Copy link
Collaborator

CI:

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

@iuhilnehc-ynos
Copy link
Contributor

As ros2 repos changed a lot, I need to re-run CI with a new custom repos file.

CI:

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

@fujitatomoya
Copy link
Collaborator

@clalancette @mjcarroll can you merge this to rolling?

@methylDragon methylDragon merged commit a2fb913 into ros2:rolling Apr 13, 2023
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.

4 participants