-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add support for NaN constants and NaN defaults in ROS IDL #789
base: rolling
Are you sure you want to change the base?
Conversation
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 green CI
e7223a0
to
5280456
Compare
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
Thanks. Do you want to approve the workflow that would kick off a build on the build farm to see how it fares? I tried the backport to |
NaN is not a valid JSON symbol http://json.org/, but there are several files use rosidl/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py Lines 476 to 486 in 0775e10
it would be nice to check if this does not break those json operation. maybe we can add documentation that says we manages as described in #351, |
i am not sure if we should do backport. if this does not break user space, it seems okay. on the other hand, this can be new enhancement, so it can be available from on next distribution to avoid possible risk? any thoughts? |
I forked ROSIDL internally for the time being for humble; we're using both NaN constants and defaults in our messages and it's passing CI with the changes (C++ and python tests). I haven't tried other tooling yet. If we want to let this simmer with the community for a bit while I can work on figuring out JSON and IDL support for NaN, that sounds good. It would be great to get this in for Jazzy; existing ROS messages like BatteryState are supposed to be using NaN, but instead default to |
Don't merge this yet. I found some issues with the generated python code that were caught only at runtime on From Looks like a small change, but I think I also need to look into the comparison operations and how they treat NaN. Because NaN doesn't equal itself in IEEE-754, comparisons get tricky. def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
if self.header != other.header:
return False
if self.my_maybe_nan_value != other.my_maybe_nan_value :
return False
return True I have a fix, but need to get time for approval to push it upstream (open source). |
The branch we have been using internally is now open source here: |
Here's a sample message aggregating all the changes from both proposed PR's. It works with You can publish the default
Or set a value to NaN in the CLI.
Here's the message:
And you can echo it:
Whatever original issues I had are fixed, so I'm marking this ready for review. Let's make sure someone else can repeat these tests. |
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.
Only one minor suggestion, otherwise everything looks good to me! I think this is a really useful feature.
I merged in rolling
locally (no conflicts, as you said) and built and verified all the generated files. I think the CI failure is just from not being up-to-date with rolling, the ones I looked at seem unrelated to these changes.
* Add nan default example and tests * Add NaN constant example and tests * Test NaNs on float64 and float32 in C++ Signed-off-by: Ryan Friedman <[email protected]>
24aeed3
to
65140bd
Compare
It's rebased. Let's see how CI does. |
Co-authored-by: Henry Moore <[email protected]> Signed-off-by: Ryan <[email protected]>
65140bd
to
2e0e779
Compare
@fujitatomoya What are you thoughts on this? If you like it, I'll rebase. |
To chime in, I think this would be a really useful capability. A lot of ros2_control stuff in particular utilizes NaN values for sentinel or default values, and being able to have messages use these by default without needing to make factory functions would be really great. |
@Ryanf55 i think this is useful feature. but i do not have maintainer permission on this repo, so someone else with maintainer permission needs to review and give approval for us. @ros2/team |
Signed-off-by: Marco A. Gutierrez <[email protected]>
Pulls: #789 |
@Ryanf55 can you check the windows failure? |
Purpose
Add support for
NaN
floating-point constants and defaults forfloat
anddouble
c/c++ types which translate to a quiet NaN in C++ perIEEE 754
.Ticket
See ros2/ros2_documentation#4135.
Currently, you can set a NaN value for a message field when using the CLI, but there is no way to define a constant as NaN, or to set a default as a NaN.
Details
As implemented, the
NAN
literal is case-insensitive because it uses the python3float()
function. Because the DDS IDL 4.2 standard does not specify this special value as part of the standard, I propose following the python convention for now.If this needs to be a certain case for other tools, they can convert it.
float()
method.Note that in the tests, you can't use
TEST_BASIC_TYPE_FIELD_ASSIGNMENT
.EXPECT_EQ
will return false with two NaN values. Instead, you have to usestd::isnan
to check a value is set to NaN.I created an OMG IDL ticket to explain the problem that it's not supported in IDL.
Because of the way that ROSIDL works and generates the C/C++ directly, I do not believe the lack of support in the OMG IDL 4.2 standard should block this PR.
References
Ticket
Relates to #351
Future work
humble
on approval+inf
and-inf