Add matched event demo for rclcpp and rclpy#607
Conversation
Signed-off-by: Barry Xu <barry.xu@sony.com>
There was a problem hiding this comment.
a new test is required in https://github.com/ros2/demos/tree/9fbd3e840113e183b7ccc935e17fa275fdea6540/demo_nodes_cpp/test
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "rcl/event.h" |
There was a problem hiding this comment.
I think we should not use rcl header file in this application
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
use rclcpp::MatchedInfo instead?
|
README.md need to be updated. |
|
I see. Let's hear others' opinions. |
fujitatomoya
left a comment
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
I think it depends on implementation, but in this demo, we do not need to include this file i think.
| bool connect_subscription_{false}; | ||
| bool connect_publisher_{false}; |
There was a problem hiding this comment.
| bool connect_subscription_{false}; | |
| bool connect_publisher_{false}; | |
| bool any_subscription_connected_{false}; | |
| bool any_publisher_connected_{false}; |
| } else { | ||
| RCLCPP_INFO( | ||
| this->get_logger(), | ||
| "Current number of connected publisher is %lu", s.current_count); |
There was a problem hiding this comment.
How about adding current_change to show the user application can see difference? I think total_xxx would be overkill.
| namespace demo_nodes_cpp | ||
| { | ||
|
|
||
| // This demo program shows detected matched event. |
There was a problem hiding this comment.
| // This demo program shows detected matched event. | |
| // This demo program shows matched event works. |
| { | ||
|
|
||
| // This demo program shows detected matched event. | ||
| // Matched event occur while connection between publisher and subscription is done. |
There was a problem hiding this comment.
| // Matched event occur while connection between publisher and subscription is done. | |
| // Matched event occurs when publisher and subscription establishes the connection. |
| // 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Okay. I will update code to remove dependency of ros2cli.
Signed-off-by: Barry Xu <barry.xu@sony.com>
I change demo codes to remove dependency of roscli. So now I can add test. @iuhilnehc-ynos |
|
lgtm, @iuhilnehc-ynos can you do another review on this? if it is good to go, please start the CI. |
iuhilnehc-ynos
left a comment
There was a problem hiding this comment.
I just left some comments from my point of view.
| class MatchedEventDetectNode : public rclcpp::Node | ||
| { | ||
| public: | ||
| DEMO_NODES_CPP_PUBLIC explicit MatchedEventDetectNode( |
There was a problem hiding this comment.
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.
|
|
||
| #include "std_msgs/msg/string.hpp" | ||
|
|
||
| #include "demo_nodes_cpp/visibility_control.h" |
There was a problem hiding this comment.
Please remove it if not to build the following classes into a library.
There was a problem hiding this comment.
Yes. Should remove it.
Thanks.
| topic_name_, | ||
| 10, | ||
| [](std_msgs::msg::String::ConstSharedPtr) {}); | ||
| subs_.emplace_back(sub); |
There was a problem hiding this comment.
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)
| subs_.emplace_back(sub); | ||
| } | ||
|
|
||
| DEMO_NODES_CPP_PUBLIC void destroy_one_sub(void) |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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);| ''' | ||
|
|
||
|
|
||
| class MatchedEventDetectNode(Node): |
There was a problem hiding this comment.
The behavior for the matched event detect in demo_nodes_cpp is different from demo_nodes_py, which might seem not good.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
| 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>
|
I updated your comments @fujitatomoya @iuhilnehc-ynos |
| self.destroy_subscription(sub) | ||
|
|
||
| def __sub_callback(self, msg): | ||
| True |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
After the above update, I'll trigger the CI.
There was a problem hiding this comment.
Yes. Revised it.
Signed-off-by: Barry Xu <barry.xu@sony.com>
|
@Barry-Xu-2018 test with connextdds is failing, could you check the failure? |
Signed-off-by: Barry Xu <barry.xu@sony.com>
|
I cannot reproduce this problem in my local environment. |
Signed-off-by: Barry Xu <barry.xu@sony.com>
|
@iuhilnehc-ynos Help to run CI again. |
Signed-off-by: Barry Xu <barry.xu@sony.com>
|
Update to codes to ensure the program does spin until the matched event occurs. |
|
@iuhilnehc-ynos Please help to run CI again |
CI: |
|
CI failure is related to a bug in Fastdds. |
that makes sense, to avoid double triggered, |
|
CI for Linux didn't run. |
CI is busy building some nighty jobs. Please be patient. |
|
@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!!!) |
|
Based on eProsima/Fast-DDS#3395 (comment), we found |
|
it looks like eProsima/Fast-DDS#3418 brings CI failure once again? |
I will consider how to resolve it. |
|
Now depend on the fix issue ros2/rmw_fastrtps#681 |
|
@clalancette @mjcarroll can you merge this to rolling? |
Address ros2/rmw#330