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

refactor: make ros2param use rclpy.parameter_client #716

Merged
merged 17 commits into from
Jul 22, 2022

Conversation

ihasdapie
Copy link
Member

@ihasdapie ihasdapie commented May 25, 2022

Use rclpy.parameter_client from instead of internal implementation (Related PR: ros2/rclpy#945) to avoid duplicate logic. Certain functions (e.g. get_parameter_value) are moved over to rclpy and ros2param. Behavior of ros2param.api is left unchanged.

I'd like some review on the proposed architecture & implementation before I clean things up and write tests etc.

@ihasdapie
Copy link
Member Author

Just a sanity check:

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

Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

The refactor makes sense to me 👍

ros2param/ros2param/api/__init__.py Show resolved Hide resolved
@ihasdapie
Copy link
Member Author

ihasdapie commented May 27, 2022

There are still large swathes of code like this) scattered throughout which look like they should be replaced with get_parameter_value but are all slightly different.

@ihasdapie
Copy link
Member Author

ihasdapie commented Jun 1, 2022

build fail due to gh actions not using related branch. See:

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

Edit: build may fail due to unrelated linting nitpick in rclpy; it is now fixed.

@ihasdapie ihasdapie marked this pull request as ready for review June 1, 2022 23:03
ros2param/ros2param/api/__init__.py Outdated Show resolved Hide resolved
ros2param/ros2param/api/__init__.py Outdated Show resolved Hide resolved
ros2param/ros2param/api/__init__.py Show resolved Hide resolved
ros2param/ros2param/verb/dump.py Outdated Show resolved Hide resolved
ros2param/ros2param/api/__init__.py Outdated Show resolved Hide resolved
ros2param/ros2param/api/__init__.py Outdated Show resolved Hide resolved
ros2param/ros2param/api/__init__.py Outdated Show resolved Hide resolved
ros2param/ros2param/api/__init__.py Outdated Show resolved Hide resolved
ros2param/ros2param/api/__init__.py Outdated Show resolved Hide resolved
@ihasdapie
Copy link
Member Author

CI:

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

@ihasdapie
Copy link
Member Author

ihasdapie commented Jun 16, 2022

See: ros2/rclpy#959 (comment)

Running again with increased timeout and more --retest-until-pass

  • Linux Build Status

@ihasdapie
Copy link
Member Author

Hopefully removing the busy wait and streamlining the dump verb helps those tests pass...

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

@ihasdapie
Copy link
Member Author

CI is passing for this PR, failures unrelated

@clalancette
Copy link
Contributor

CI is passing for this PR, failures unrelated

Just to be clear, that does not seem to be the case. All of the nightly builds on Linux and Windows are green, and the last CI was not, so it does look like there is breakage here.

@ihasdapie
Copy link
Member Author

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

@clalancette Windows error seemed to be a weird flaky test. Yellow because of downstream linting error on one of my related PRs I'm still working on.

@audrow audrow changed the base branch from master to rolling June 28, 2022 14:23
@ihasdapie
Copy link
Member Author

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

Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

The behavior for ros2 param list is much better now, thanks!

ros2param/ros2param/api/__init__.py Outdated Show resolved Hide resolved
ros2param/ros2param/verb/dump.py Outdated Show resolved Hide resolved
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
ihasdapie and others added 12 commits July 22, 2022 01:29
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
This reverts commit 20ba9fe.

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Co-authored-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Co-authored-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

LGTM with green CI

@ihasdapie
Copy link
Member Author

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

@Kaju-Bubanja
Copy link

I was using load_parameter_dict and was wondering where it went? I noticed commit fc02ffe removes it, but without a note to where it went. I checked rclpy but couldn't find it. Was there a rational why this was removed?

@ihasdapie
Copy link
Member Author

ihasdapie commented Nov 2, 2022

@Kaju-Bubanja This internal api was deprecated in favor of rclpy's AsyncParameterClient's set_parameter method:

from rclpy.parameter_client import AsyncParameterClient

client = AsyncParameterClient(node, node_name)
future = client.set_parameters(list(param_dict.values()))
rclpy.spin_until_future_complete(node, future)
response = future.result()
# ... and so forth

Reference:

@Kaju-Bubanja
Copy link

@ihasdapie Any reason for that? Did something not work with the function or cause problems? Otherwise I don't see why a perfectly fine function should be removed.

@ihasdapie
Copy link
Member Author

The methods in ros2param duplicated code and had inconsistent implementations which this refactor addressed. Plus, we didn't anticipate external users using the internal ros2param methods. If you think that this method should be put back into ros2param feel free to open a PR and we can discuss there, but in my opinion the current design consolidating the parameter management logic in rclpy and calling out to it in ros2param makes more sense.

@Kaju-Bubanja
Copy link

Hmmm, I found the parse_parameter_dict function very convenient and copy pasted it into my file, in case somebody in the future searches for this issue here you go, important is to also allow_undeclared_parameters:

def parse_parameter_dict(*, namespace, parameter_dict):
    parameters = []
    for param_name, param_value in parameter_dict.items():
        full_param_name = namespace + param_name
        # Unroll nested parameters
        if type(param_value) == dict:
            parameters += parse_parameter_dict(
                    namespace=full_param_name + PARAMETER_SEPARATOR_STRING,
                    parameter_dict=param_value)
        else:
            parameter = Parameter(full_param_name, value=param_value)
            parameters.append(parameter)
    return parameters

class Foo(Node):
    def __init__(self):
        self.name = "foo"
        # allow_undeclared_parameters implicitly declares parameters when setting them, basically syntax sugar
        super().__init__(self.name, allow_undeclared_parameters=True)
    def load_parameter_dict(self, d):
        call_set_parameters(node=self, node_name=self.name, parameters=parse_parameter_dict(namespace="", parameter_dict=d))

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.

None yet

4 participants