ros / genpy

genpy
31 stars 64 forks source link

Support for special float values #126

Open glennib opened 4 years ago

glennib commented 4 years ago

I think this genmsg issue is more appropriate here.

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')

A suggestion is to add the lines

nan = float('nan')
inf = float('inf')

at the top of the output of msg_generator: https://github.com/ros/genpy/blob/5008399c9e8f936c0a7067505c2b7cc4c6c09748/src/genpy/generator.py#L817-L821

Another solution would be to have special handling of these types of values at https://github.com/ros/genpy/blob/5008399c9e8f936c0a7067505c2b7cc4c6c09748/src/genpy/generator.py#L864

dirk-thomas commented 4 years ago

As stated on the referenced ticket already: please consider to provide a pull request for that enhancement.