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

Sub-node name is ignored in service name resolving #2734

Open
PfeifferMicha opened this issue Feb 6, 2025 · 4 comments
Open

Sub-node name is ignored in service name resolving #2734

PfeifferMicha opened this issue Feb 6, 2025 · 4 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@PfeifferMicha
Copy link

PfeifferMicha commented Feb 6, 2025

When I create sub-nodes using Node::create_sub_node() and then resolve a private name on this sub-node, the sub-namespace is ignored.

    auto nh_left = this->create_sub_node( "left" );
    std::string resolved_service_name = nh_left->get_node_base_interface()->resolve_topic_or_service_name( 
                                                                                                                                                   "~/set_camera_info", true, false );

Resolves to: /test_cam_info_manager/set_camera_info
But I would expect it to resolve to: /test_cam_info_manager/**left**/set_camera_info

Background:
In order to create two CameraInfoManager's for a stereo setup, I need some way to push the CameraInfoManagers into a sub-namespace. I thought this is exactly what sub-nodes are for, but it's not working. Original issue: ros-perception/image_common#341

Note: In rolling release, I believe this can be circumvented because CameraInfoManager has a new namespace parameter, but this is not the case in jazzy.

Required Info:

  • Operating System:
    • Ubuntu 24.04
  • Installation type:
    • binaries
  • Version or commit hash:
    • jazzy
  • Client library (if applicable):
    • rclcpp
@fujitatomoya
Copy link
Collaborator

@PfeifferMicha thanks for creating issue, this looks like bug.

one question, can you reproduce this issue with rolling build as well? self-contained example would be appreciated.

@PfeifferMicha
Copy link
Author

Thanks for the reply!

Here's my minimal example. Please see the Readme for description of the error/expected outcome.
https://github.com/PfeifferMicha/test_cam_info_manager

I tried with the CI nightly rolling build from here:
https://ci.ros2.org/view/packaging/job/packaging_linux/lastBuild/
Revision: 022da8a9eaa83b4ae8f7b770bdd2a4c700bf1d70

The error is still there.

@audrow audrow added the bug Something isn't working label Feb 20, 2025
@wjwwood
Copy link
Member

wjwwood commented Feb 28, 2025

The reason for this is that the "sub-node" feature exists only in the rclcpp::Node class. It does not extend down into the NodeInterface classes, therefore the way that the CameraInfoManager is using a NodeInterface rather than a Node. So I don't consider it to be a bug exactly, but just a limitation of the sub-node feature.

You lose the feature when you do nh_left->get_node_base_interface(), and it's the same for both Services and Topics.

There's a few options to move forward here:

  • you could have the CameraInfoManager take a Node, which I don't really recommend, because we've been pushing people to take the interfaces instead
  • you could extend the sub-node feature down into the node interfaces classes, but that's tricky because you may have multiple sub nodes going at one time, but it could be done I think
  • you could extract the sub namespace with Node::get_sub_namespace() or similar, and pass it to the CameraInfoManager along side the node interface

see:

/// Return the sub-namespace, if this is a sub-node, otherwise an empty string.
/**
* The returned sub-namespace is either the accumulated sub-namespaces which
* were given to one-to-many create_sub_node() calls, or an empty string if
* this is an original node instance, i.e. not a sub-node.
*
* For example, consider:
*
* ```cpp
* auto node = std::make_shared<rclcpp::Node>("my_node", "my_ns");
* node->get_sub_namespace(); // -> ""
* auto sub_node1 = node->create_sub_node("a");
* sub_node1->get_sub_namespace(); // -> "a"
* auto sub_node2 = sub_node1->create_sub_node("b");
* sub_node2->get_sub_namespace(); // -> "a/b"
* auto sub_node3 = node->create_sub_node("foo");
* sub_node3->get_sub_namespace(); // -> "foo"
* node->get_sub_namespace(); // -> ""
* ```
*
* get_namespace() will return the original node namespace, and will not
* include the sub-namespace if one exists.
* To get that you need to call the get_effective_namespace() method.
*
* \sa get_namespace()
* \sa get_effective_namespace()
* \return the sub-namespace string, not including the node's original namespace
*/
RCLCPP_PUBLIC
const std::string &
get_sub_namespace() const;
/// Return the effective namespace that is used when creating entities.
/**
* The returned namespace is a concatenation of the node namespace and the
* accumulated sub-namespaces, which is used as the namespace when creating
* entities which have relative names.
*
* For example, consider:
*
* ```cpp
* auto node = std::make_shared<rclcpp::Node>("my_node", "my_ns");
* node->get_effective_namespace(); // -> "/my_ns"
* auto sub_node1 = node->create_sub_node("a");
* sub_node1->get_effective_namespace(); // -> "/my_ns/a"
* auto sub_node2 = sub_node1->create_sub_node("b");
* sub_node2->get_effective_namespace(); // -> "/my_ns/a/b"
* auto sub_node3 = node->create_sub_node("foo");
* sub_node3->get_effective_namespace(); // -> "/my_ns/foo"
* node->get_effective_namespace(); // -> "/my_ns"
* ```
*
* \sa get_namespace()
* \sa get_sub_namespace()
* \return the sub-namespace string, not including the node's original namespace
*/
RCLCPP_PUBLIC
const std::string &
get_effective_namespace() const;

@wjwwood wjwwood removed their assignment Feb 28, 2025
@alsora alsora added the help wanted Extra attention is needed label Mar 13, 2025
@alsora
Copy link
Collaborator

alsora commented Mar 13, 2025

Hi @PfeifferMicha , any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants