Add range constraints for applicable array parameters#2828
Add range constraints for applicable array parameters#2828ahcorde merged 5 commits intoros2:rollingfrom
Conversation
…nteger and double) Signed-off-by: Alex Youngs <alexyoungs@hatchbed.com>
82763c0 to
2ab7fec
Compare
Signed-off-by: Alex Youngs <alexyoungs@hatchbed.com>
2ab7fec to
b46fbbe
Compare
Signed-off-by: Alex Youngs <alexyoungs@hatchbed.com>
|
@agyoungs this sounds reasonable. thanks for creating PR 👍 is this good to review? |
|
@fujitatomoya Yeah, it's ready for review. I noticed one of the linting checks failed so I was going to refactor the test cases into a separate function, but I thought that might make it less apparent what changed for the review. I'm happy to resolve the linting failure in whatever way is preferred |
|
I have one minor remark, the '__check_parameter_value_in_range' function is now too long in my opinion. I would split it up, and have one function per parameter type. |
|
This looks reasonable to me. I agree with working to reduce the length/complexity of the calls with some modularity/reuse of the single checks within the array. For more complicated checks or application specific checks with recovery logic we do have validation callbacks that can be registered on the parameter provider. I see one limitation that this would provide is that you couldn't provide application specific logic such as choosing to normalize the change instead of rejecting the change that you would be able to do in the custom validation callback. It might make sense to apply this default constraint only if there's not a custom validation callback? |
fujitatomoya
left a comment
There was a problem hiding this comment.
@agyoungs thanks for the PR.
test covers the most cases as aligned with integer and double type 🚀
Signed-off-by: Alex Youngs <alexyoungs@hatchbed.com>
fujitatomoya
left a comment
There was a problem hiding this comment.
lgtm with green CI.
|
@jmachowinski i will go ahead to start CI. please have an another look. |
|
Pulls: #2828 |
@tfoote if I'm understanding correctly, the existing snippet below is relevant. I'm not 100% sure if you're referring to a specific situation, but I see a few cases here:
So the last major bullet above has a couple cases that would definitely interfere with a custom callback only if that callback was expecting to use the range constraints for something else. You mentioned we could potentially disable the internal check if the parameter has a param check callback. I'm assuming that this would only apply to the array parameters. The limitation here is that one would have to implement their own range check (assuming this becomes a standard internal check) and then whatever custom check they wanted to perform on the array if they want both the standard check and their own custom check. In my opinion this feels more like an override, and if all the parameters aren't subjected to a user defined override then probably none of them should be. You currently can't do a custom range check (using the range constraint) on a So I think the question is, is this considered an obvious check? If not, it probably doesn't make sense to make it a standard internal check. |
I didn't read this closely enough. I didn't really break up the |
|
CI looks like got cut off, i will restart the CI. |
tfoote
left a comment
There was a problem hiding this comment.
Yeah, the prevalidation and ability to prefilter and adjust out of range values is probably too much of a corner case. Keeping it simple that it will pre-validate the ranges for a declared range is simpler to explain and makes sense and is consistent with what we were already doing for other types.
This looks a lot better with the refactored checking for the unitary types reused inside the for loops.
|
@agyoungs cpplint is not happy, can you fix that? |
Signed-off-by: Alex Youngs <alexyoungs@hatchbed.com>
90262e6 to
45bf07e
Compare
I went to refactor the test since it complained it was too long. But then I found a few superfluous test cases that brought the line count back within the required range. I think that fixed it, although I still see a failing check although I'm not sure what's failing |
|
Pulls: #2828 |
|
Do we need to backport this to other ROS versions? |
|
we can backport this but this changes the behavior, maybe it should stay in rolling? |
I noticed that array numeric parameters (integer and double) didn't have any range checking. To me it seemed that if you had an array and bounds you would simply just want each element of the array to be within those bounds. So instead of requiring a new constraint class for array types I thought it made sense to apply the constraint to each element.
Additional thoughts: Would this be limiting for potential future constraints for arrays? The only additional thing I could think of for an array would be min/max length, although I don't have an immediate use-case for that.
If there are array specific constraints to be implemented in the future, they can exist as a separate class and validated in a similar manner. I don't think this limits the ability to add array specific constraints and allows re-use of the already implemented constraint checks of the base type.