Skip to content

fixup parameters and sub-nodes #731

Closed

Description

@wjwwood

This is a follow up from #495 (comment).

Currently how parameters and "sub-nodes" interact is not documented and is not consistent or tested. That needs to be documented, audited, and tested.

Activity

  1. added
    enhancement
    help wanted
    on May 21, 2019
  2. self-assigned this
    on May 21, 2019
  3. mikeferguson commented on Jun 7, 2020

    @mikeferguson

    So, is this ticket basically tracking that sub nodes do not actually use the sub_namespace in the name of the parameter? For example:

    auto subnode = parent->create_sub_node("controller_name");
    std::string controller_type = subnode->declare_parameter<std::string>("type", "");
    

    I would expect the parameter to be "controller_name/type", but instead "ros2 param list" shows only a parameter named "type"? Is this expected behavior? Is this a bug?

  4. fujitatomoya commented on Jun 8, 2020

    @fujitatomoya
    Collaborator

    I am not sure about this either, I'd like to know.

    I would expect the parameter to be "controller_name/type", but instead "ros2 param list" shows only a parameter named "type"?

    currently, yes. only type is declared w/o namespace.

    I think that this is bug, it should be extended with sub_namespace?

  5. wjwwood commented on Jun 8, 2020

    @wjwwood
    MemberAuthor

    Yeah @mikeferguson I consider it a bug, or at least I think it will be surprising to most users.

    The issue (why I didn't just fix it on the spot) is that the way the node class is separated into parts complicates this. The subnode feature was added to Node, but not to one of the components, meaning it's hard to use from the NodeParameters class. This is just my recollection of the issue, but maybe it's easier to fix now, I don't know off hand without trying to do it.

  6. jlack1987 commented on Sep 21, 2021

    @jlack1987

    I'm willing to spend some time attempting to fix this issue, but i'd appreciate it if I could get a more involved devs input on a suggested fix/implementation. I can just run off and implement a fix, but I don't want to end up spending a lot of time on a fix and it not being an acceptable implementation

  7. fujitatomoya commented on Sep 22, 2021

    @fujitatomoya
    Collaborator

    just sharing the update. we had a quick chat on this in MW WG. we consider this is bug, all entities of sub-nodes should be extended and propagated with sub-nodes namespace. (topics, services and parameters) as @wjwwood mentioned #731 (comment) these should be tested well.

  8. jlack1987 commented on Oct 6, 2021

    @jlack1987

    I'm curious if this could be solved by injecting the sub namespace into the parameter name in the call here. The reason i'm curious if this is an adequate solution is based on how the declare_parameters call behaves in that it already takes a namespace and, in the case where the namespace arg is non-empty, creates parameters that are namespace.name.

    So would it be valid to simply namespace parameters into the sub_namespace_ which is already available and if it's empty it'll continue to behave as it does now for a non-subordinate node? I'm relatively new to ros2 so there may be fallout from this strategy that I'm currently unaware. Would appreciate it if I could get a devs input on this. Thanks!

    Edit:
    I think additionally there's an inconsistency with there being no API call to set_parameters that takes a namespace. At least it's not clear to me why there is no such call but there is a declare_parameters call that accepts a namespace. In the case where allow_undeclared_parameters is true I would think that call should be ok

  9. jlack1987 commented on Oct 6, 2021

    @jlack1987

    I have also found that if you declare parameters with a sub node n with,

    std::map<std::string, double> parameters = { { "a", 1. }, { "b", 2. }, { "c", 3. } };
    n->declare_parameters(n->get_sub_namespace(), parameters);
    

    and then retrieve those params with,

    n->get_parameter<double>(n->get_sub_namespace() + ".b", param_b);
    rclcpp::Parameter param = n->get_parameter(n->get_sub_namespace() + ".b");
    

    that the second call there does get the correct parameter, but the first call doesn't find it and returns what looks like some uninitialized number(7.892878e-293 in one run for example). This is because the templated call prepends the parameter name with the sub node namespace, but the other two API calls for getting a parameter don't do that

  10. aprotyas commented on Oct 6, 2021

    @aprotyas
    Member

    rclcpp::Parameter param = n->get_parameter(n->get_sub_namespace() + ".b");

    Quite uninformed thought - and not to divert the topic of conversation here - but aren't namespaces delimited by "/" and not "."?

  11. jlack1987 commented on Oct 6, 2021

    @jlack1987

    haha yeah I was surprised by this as well @aprotyas. Idk if that's a typo that squeaked through review or what but that single declare_parameters call prepends the param name with a .. I'm guessing since the . key is right next to a / that it went unnoticed?

  12. clalancette commented on Oct 6, 2021

    @clalancette
    Contributor

    rclcpp::Parameter param = n->get_parameter(n->get_sub_namespace() + ".b");

    Quite uninformed thought - and not to divert the topic of conversation here - but aren't namespaces delimited by "/" and not "."?

    Yes, but parameter "levels" are separated by ., which I think is what this is asking for. I'm not sure though, I'd need to look at the code more closely to see the context.

  13. jlack1987 commented on Oct 6, 2021

    @jlack1987

    Is this notion of "parameter level" documented somewhere? I did a quick search and didn't see anything

  14. clalancette commented on Oct 6, 2021

    @clalancette
    Contributor

    It's basically this: https://docs.ros.org/en/rolling/How-To-Guides/Node-arguments.html#setting-parameters-from-yaml-files

    That is, when you declare a parameter in YAML like:

    parameter_blackboard:
        ros__parameters:
            some_int: 42
            some_lists:
                some_integers: [1, 2, 3, 4]
                some_doubles : [3.14, 2.718]
    

    Then you retrieve them using names like some_int, some_lists.some_integers, and some_lists.some_doubles.

  15. added a commit that references this issue on Oct 18, 2021
  16. jlack1987 commented on Jan 3, 2022

    @jlack1987

    I had a PR for this here, but the approach was ultimately flawed so I closed it; however, there is a good deal of discussion in there that someone may find useful so I just wanted to link to it here.

  17. fujitatomoya commented on Jan 3, 2022

    @fujitatomoya
    Collaborator

    I added this to next MW WG topic not to miss it.

  18. wjwwood commented on Jan 12, 2022

    @wjwwood
    MemberAuthor

    @wjwwood to leave an idea about how to do this without creating new NodeParameter instances, but still get namespacing for parameter methods of the node class.

  19. matemat13 commented on Apr 7, 2025

    @matemat13

    Did this ever get resolved? It seems that namespaced parameters of subnodes are still broken (not behaving as expected).

  20. nirwester commented on Jun 2, 2025

    @nirwester

    Is this fully solved by #2822 ?

  21. fujitatomoya commented on Jun 2, 2025

    @fujitatomoya
    Collaborator

    @nirwester yeah i think so, thanks for letting me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

documentationenhancementhelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions