genmsg
genmsg copied to clipboard
Special Float Generation
In cases where constants in messages are set to special floats, for example:
float32 a = NaN
float32 p = Inf
float32 n = -Inf
The successfully generated Python script declare those as:
a = nan
p = inf
n = -inf
However, those causes NameError
as nan
, inf
don't exist.
The following works in Python:
a = float('nan')
p = float('inf')
n = float('-inf')
That would be a great addition. Please consider to provide a pull request for that enhancement.
I think the issue may be with this line in genpy: https://github.com/ros/genpy/blob/5008399c9e8f936c0a7067505c2b7cc4c6c09748/src/genpy/generator.py#L864
yield ' %s = %s' % (c.name, c.val)
# where c.name is the constant name and c.val is the actual value
# when converted to string, c.val just becomes nan
There should probably be a check for special values and provide the appropriate strings OR we should add the lines
nan = float('nan')
inf = float('inf')
at the top.
I have created a new issue https://github.com/ros/genpy/issues/126. Perhaps this issue can be closed, as I don't think we can fix it from genmsg?
Perhaps this issue can be closed, as I don't think we can fix it from genmsg?
genmsg
provides the parsing logic and the cross-language API. So the concept needs to be added here first and then genpy
can use it to generate Python specific code. gencpp
(and other languages) will need to be updated accordingly.