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.
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
namespaceparameter. This is introduced to match the behavior inrclcpp, but on the other hand the currentset_parametersmethod inmasterdoesn't have a namespace option. - Adding a setter to the name.
- Using the private
_namemember (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.
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.
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.
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 |
rclpy/test/test_node.py
Outdated
| ) | ||
|
|
||
|
|
||
| class Test(unittest.TestCase): |
There was a problem hiding this comment.
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.
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.
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. |
wjwwood
left a comment
There was a problem hiding this comment.
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>
Original PR #325 by jubeira Original: ros2/rclpy#325
Merged from original PR #325 Original: ros2/rclpy#325
Original PR #325 by jubeira Original: ros2/rclpy#325
Merged from original PR #325 Original: ros2/rclpy#325
Closes #321; refer to the issue for details.