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

Parameter API enhancements #325

Merged
merged 4 commits into from
May 4, 2019
Merged

Conversation

jubeira
Copy link
Contributor

@jubeira jubeira commented Apr 26, 2019

Closes #321; refer to the issue for details.

@jubeira jubeira added the in progress Actively being worked on (Kanban column) label Apr 26, 2019
@jubeira
Copy link
Contributor Author

jubeira commented Apr 26, 2019

This is a draft for now; there are still multiple TODOs around the code and testing to be done before promoting it to a PR.
If anyone's interested in taking a preliminary look and providing feedback, it is more than welcome!

rclpy/rclpy/exceptions.py Outdated Show resolved Hide resolved
rclpy/rclpy/node.py Outdated Show resolved Hide resolved
rclpy/rclpy/node.py Outdated Show resolved Hide resolved
rclpy/rclpy/node.py Show resolved Hide resolved
@jubeira jubeira marked this pull request as ready for review April 30, 2019 19:14
@jubeira jubeira changed the title [WIP] Parameter API enhancements Parameter API enhancements Apr 30, 2019
@jubeira jubeira force-pushed the issue/#321_enhance_parameter_api branch from 9147c83 to 89eb719 Compare April 30, 2019 19:45
@jubeira
Copy link
Contributor Author

jubeira commented Apr 30, 2019

Code updated and rebased with the current master.
This is ready for review; the only pending tasks are adding proper test cases for the new API, and improving exception handling. Existing

Note that this PR should get in before the API freeze. The implementation reused the existing codebase as much as possible; the intention was to comply with the new API changing it as little as possible. Following that line, I would suggest to correct implementation details that may appear after the API freeze.

@hidmic
Copy link
Contributor

hidmic commented Apr 30, 2019

CI (full run):

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

rclpy/rclpy/exceptions.py Outdated Show resolved Hide resolved
rclpy/rclpy/node.py Outdated Show resolved Hide resolved
rclpy/rclpy/node.py Outdated Show resolved Hide resolved
rclpy/rclpy/node.py Outdated Show resolved Hide resolved
rclpy/rclpy/node.py Outdated Show resolved Hide resolved
rclpy/test/test_create_node.py Outdated Show resolved Hide resolved
:raises: InvalidParameterValueException if the registered callback rejects the parameter.
"""
for parameter in parameters:
parameter.name = namespace + parameter.name
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Writing tests I just realized that this is not possible (name can't be set after creating Parameter object).
I can think of these alternatives, in order of preference:

  • Creating new parameters with same value, type and descriptor but with a new name containing the namespace.
  • Suppressing namespace parameter. This is introduced to match the behavior in rclcpp, but on the other hand the current set_parameters method in master doesn't have a namespace option.
  • Adding a setter to the name.
  • Using the private _name member (argh).

@hidmic thoughts?
/cc @wjwwood input on this is welcome!

This comment was marked as resolved.

This comment was marked as outdated.

Copy link
Contributor Author

@jubeira jubeira May 2, 2019

Choose a reason for hiding this comment

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

See a proposed fix in a39ea62.

In rclcpp, declare_parameter takes a name, a value and a descriptor, but set_parameter takes a rclcpp::Parameter. Following that line, I left set_parameters with the same signature, and changed declare_parameters to take the pieces of the parameter as separate arguments in a tuple.
In other words, its @jacobperron 's second suggestion, considering ParameterDescriptor as well.

def declare_parameter(self, name: str, parameter: ParameterValue, descriptor: ParameterDescriptor) -> Parameter:
    ...
def declare_parameters(self, namespace: str, parameters: List[Tuple[str, ParameterValue, ParameterDescriptor]]) -> List[Parameter]:
    ...

/cc @hidmic

Copy link
Member

Choose a reason for hiding this comment

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

For what it is worth, there's no reason C++ doesn't provide a set_parameters(vector<pair<string, ParameterValue>>) nor is there a reason against declare_parameters(string, vector<pair<Parameter, descriptor>>), other than that I ran out of time to keep adding convenient signatures. Many of the other signatures that seem less obvious were added by request before my big refactor.

rclpy/rclpy/node.py Outdated Show resolved Hide resolved
rclpy/rclpy/node.py Show resolved Hide resolved
:raises: InvalidParameterValueException if the registered callback rejects the parameter.
"""
for parameter in parameters:
parameter.name = namespace + parameter.name

This comment was marked as resolved.

rclpy/rclpy/node.py Show resolved Hide resolved
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.

Partial review.

rclpy/rclpy/validate_parameter_name.py Show resolved Hide resolved
rclpy/rclpy/validate_parameter_name.py Outdated Show resolved Hide resolved
rclpy/rclpy/node.py Show resolved Hide resolved
rclpy/rclpy/node.py Outdated Show resolved Hide resolved
rclpy/rclpy/node.py Outdated Show resolved Hide resolved
:raises: InvalidParameterValueException if the registered callback rejects the parameter.
"""
for parameter in parameters:
parameter.name = namespace + parameter.name

This comment was marked as outdated.

rclpy/rclpy/node.py Outdated Show resolved Hide resolved
rclpy/rclpy/node.py Outdated Show resolved Hide resolved
rclpy/rclpy/node.py Outdated Show resolved Hide resolved
rclpy/rclpy/node.py Outdated Show resolved Hide resolved
rclpy/rclpy/validate_parameter_name.py Outdated Show resolved Hide resolved
rclpy/rclpy/validate_parameter_name.py Outdated Show resolved Hide resolved
@jubeira
Copy link
Contributor Author

jubeira commented May 2, 2019

Thanks for the comments @wjwwood @jacobperron !
I've just pushed some more changes addressing them. I still need to add more test cases, but this seems to be taking shape. I'll rebase to fix the conflicts before proceeding.

- See issue #321 for details.

Signed-off-by: Juan Ignacio Ubeira <jubeira@ekumenlabs.com>
@jubeira jubeira force-pushed the issue/#321_enhance_parameter_api branch from 0925fe4 to 8bfc19c Compare May 2, 2019 20:55
Signed-off-by: Juan Ignacio Ubeira <jubeira@ekumenlabs.com>
@jubeira
Copy link
Contributor Author

jubeira commented May 3, 2019

CI for linux:

  • Linux: Build Status
  • Linux-aarch64: Build Status
  • MacOS: Build Status

Windows was not available and didn't finish yet. Other than that CI looks good for this.
@wjwwood any more thoughts or comments? Do you think this can get in the API freeze?

@sloretz
Copy link
Contributor

sloretz commented May 3, 2019

@jubeira It looks like those CI runs tested all packages. For the next run I recommend --packages-above rclpy in the tests args to reduce the time CI takes

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.

It might be good to add a few tests exercising describe_parameter, describe_parameters, and undeclare_parameter.

@@ -277,6 +286,255 @@ def test_node_has_parameter_services(self):
)


class Test(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

nit: rename this test fixture to be more descriptive. Maybe TestNodeParameters? Since the previous test fixture is not testing the node's parameter methods anyways, it could probably keep the name TestNode.

def test_declare_parameter(self):
result_foo = self.node.declare_parameter(
'foo', ParameterValue(
type=Parameter.Type.INTEGER.value, integer_value=42), ParameterDescriptor())
Copy link
Member

Choose a reason for hiding this comment

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

nit: for readability I would put each argument to declare_parameter on a new line.

Same for all instances below.

self.assertEqual(result_baz.value, 2.41)
self.assertEqual(self.node.get_parameter('foo').value, 42)
self.assertEqual(self.node.get_parameter('bar').value, 'hello')
self.assertEqual(self.node.get_parameter('baz').value, 2.41)
Copy link
Member

Choose a reason for hiding this comment

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

Might be good to test calls where only the name or name and value are provided.

rclpy/test/test_node.py Show resolved Hide resolved
@jacobperron
Copy link
Member

@jubeira My recent review is just minor nitpicks. Also, I'm okay if we want to put the additional tests in a follow-up PR.

Copy link
Member

@wjwwood wjwwood 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 a suggestion that's non-blocking

rclpy/rclpy/node.py Show resolved Hide resolved
@jubeira
Copy link
Contributor Author

jubeira commented May 3, 2019

@jacobperron @wjwwood thanks again for your reviews!
If you are OK with it, I'd suggest merging this one and opening a ticket to track down the missing suggestions and test cases. I can do the follow-up.

/cc @hidmic

Juan Ignacio Ubeira added 2 commits May 3, 2019 15:54
- Minor typos and naming fixes for test_node.

Signed-off-by: Juan Ignacio Ubeira <jubeira@ekumenlabs.com>
Signed-off-by: Juan Ignacio Ubeira <jubeira@ekumenlabs.com>
@jubeira
Copy link
Contributor Author

jubeira commented May 4, 2019

CI:

  • Linux: Build Status
  • Linux-aarch64: Build Status
  • Mac OS: Build Status
  • Windows Build Status

Overall looks good; the failing cases seem to be unrelated.

@jubeira jubeira merged commit d340737 into master May 4, 2019
@jubeira jubeira removed the in progress Actively being worked on (Kanban column) label May 4, 2019
@jubeira jubeira deleted the issue/#321_enhance_parameter_api branch May 4, 2019 00:52
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.

Enhance parameters API - declarations and descriptors
5 participants