-
Notifications
You must be signed in to change notification settings - Fork 225
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
Conversation
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. |
9147c83
to
89eb719
Compare
Code updated and rebased with the current 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. |
rclpy/rclpy/node.py
Outdated
:raises: InvalidParameterValueException if the registered callback rejects the parameter. | ||
""" | ||
for parameter in parameters: | ||
parameter.name = namespace + parameter.name |
There was a problem hiding this comment.
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 inrclcpp
, but on the other hand the currentset_parameters
method inmaster
doesn't have a namespace option. - Adding a setter to the name.
- Using the private
_name
member (argh).
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
:raises: InvalidParameterValueException if the registered callback rejects the parameter. | ||
""" | ||
for parameter in parameters: | ||
parameter.name = namespace + parameter.name |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this 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/node.py
Outdated
:raises: InvalidParameterValueException if the registered callback rejects the parameter. | ||
""" | ||
for parameter in parameters: | ||
parameter.name = namespace + parameter.name |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Thanks for the comments @wjwwood @jacobperron ! |
- See issue #321 for details. Signed-off-by: Juan Ignacio Ubeira <jubeira@ekumenlabs.com>
0925fe4
to
8bfc19c
Compare
Signed-off-by: Juan Ignacio Ubeira <jubeira@ekumenlabs.com>
CI for linux: Windows was not available and didn't finish yet. Other than that CI looks good for this. |
@jubeira It looks like those CI runs tested all packages. For the next run I recommend |
There was a problem hiding this 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
.
rclpy/test/test_node.py
Outdated
@@ -277,6 +286,255 @@ def test_node_has_parameter_services(self): | |||
) | |||
|
|||
|
|||
class Test(unittest.TestCase): |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
@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. |
There was a problem hiding this 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
@jacobperron @wjwwood thanks again for your reviews! /cc @hidmic |
- 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>
Closes #321; refer to the issue for details.