ros-drivers / rosserial

A ROS client library for small, embedded devices, such as Arduino. See: http://wiki.ros.org/rosserial
508 stars 527 forks source link

make_library.py Doesn't Support Float Constants #557

Open hishamyousry opened 3 years ago

hishamyousry commented 3 years ago

I have a .msg that defines the maximum value for a certain input as a constant float value, as follows: float32 ANGLE_MAX=9.6 # rad, maximum angle

When building the code on the ROS side, the generated header file handles this okay:

static const float ANGLE_MAX;

template<typename ContainerAllocator> const float
      SteeringCmd_<ContainerAllocator>::ANGLE_MAX = 9.6;

I am now trying to use rosserial_windows to generate these headers for use with a Windows client. Using the conventional make_libraries.py script, the generated header has this line instead: enum { ANGLE_MAX = 9.6 };

Needless to say, the compiler complained because there's no such thing as a float value in an enum.

After some investigation, I looked in rosserial/rosserial_client/src/rosserial_client/make_library.py and found this block of code:

if value != None:
    self.enums.append( EnumerationType(name, ty, value))
    continue

which apparently considers any variable with a constant value assigned to it as an enum type, regardless of the variable data type. This means that float constants are always declared as enums. Shouldn't there be a check for the data type before declaring it an enum?

I faced this issue on ROS Melodic, but taking a quick look in the noetic-devel branch I see that the above block of code still exists.