Conversation
sloretz
left a comment
There was a problem hiding this comment.
Hi @fmrico, thanks for the pull request! This is raises some questions in my mind about what #531 is asking for.
It looks like the SubNode approach requires all API's on the node to be duplicated. One of the comments on #351 seems propose that a Node and a SubNode be the same class with a hidden private Node implementation that they both call to avoid duplicating APIs. That sounds like a huge change to implement in one pull request.
Any ideas on how to iterate towards Node and SubNode being the same class without duplicating the APIs in the meantime?
| @@ -0,0 +1,227 @@ | |||
| // Copyright 2014 Open Source Robotics Foundation, Inc. | |||
| @@ -0,0 +1,485 @@ | |||
| // Copyright 2014 Open Source Robotics Foundation, Inc. | |||
| namespace rclcpp | ||
| { | ||
|
|
||
| class Node; |
There was a problem hiding this comment.
No need to forward declare Node since rclcpp/node.hpp was included above
| CallbackT && callback, | ||
| const rmw_qos_profile_t & qos_profile = rmw_qos_profile_default, | ||
| rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr, | ||
| bool ignore_local_publications = false, |
There was a problem hiding this comment.
This approach copies a lot of code. I'm concerned maintaining default values for arguments like this one in two places will be difficult to do in the future. @wjwwood posted this comment about making a sub node and a node the same class.
| const std::string | ||
| SubNode::add_extended_ns_prefix(const std::string & original_name) const | ||
| { | ||
| return std::string(original_->get_namespace()) + "/" + extended_namespace_ + "/" + original_name; |
There was a problem hiding this comment.
This works for relative names foo or foo/bar, but I'm not sure about the behavior for fully qualified or private names ~/bar.
ROS 1 threw ros::InvalidNameException when trying to create a publisher/subscriber/etc with a private name, asking instead that the NodeHandle be created with a private namespace. In ROS 2 the create_...() APIs allow private names. I'm not sure how to handle all the cases, but there is a proposal here: #531 (comment)
| auto node = std::make_shared<rclcpp::Node>("my_node", "/ns"); | ||
| auto subnode = node->create_sub_node("/sub_ns"); | ||
| EXPECT_STREQ("my_node", subnode->get_name()); | ||
| EXPECT_STREQ("/ns/sub_ns", subnode->get_namespace()); |
There was a problem hiding this comment.
Given that the subnode's namespace is fully qualified, I think this result should be /sub_ns. This also matches ROS 1 when a fully qualified name is given as a child NodeHandle namespace.
#include "ros/ros.h"
#include "std_msgs/String.h"
int main(int argc, char ** argv)
{
ros::init(argc, argv, "name");
ros::NodeHandle n;
ros::NodeHandle nsub(n, "/sub_ns");
ros::Publisher pub = nsub4.advertise<std_msgs::String>("nsub/relaive", 1000);
ros::spin();
return 0;
}launched with /path/to/above/executable __ns:=/orig_ns
Creates the topic /sub_ns/nsub/relative, not /orig_ns/sub_ns/...
There was a problem hiding this comment.
We could also consider making it so that "sub nodes" can only use relative name prefix or a prefix starting with a ~. That would avoid the issue of ignoring the node namespace.
|
Yeah, unfortunately I think the design issues here (like the amount of duplicated code) are going to impede progress. Maybe we could try and setup a voice chat at some point to hash out some of the details. @fmrico are you interested at all in doing that? |
|
Hi, Yes, there is a lot of duplicated code because I did not want that SubNode inherits from Node, but the interface had to be the same. I could reconsider this or find another solution. @wjwwood I am interested in doing that. |
Resolves ros2#552 Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Barry Xu <barry.xu@sony.com>
Hi all,
This PR is related to issue #531 , providing a SubNode class (implemented as a Proxy Pattern). This let to have code like:
which produces these topics:
This is a possible starting point to have the desired functionality.
Best