ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Enum in msg

asked 2011-03-15 06:14:13 -0500

Hendrik Wiese gravatar image

Hi there,

does anybody know if there's a way to put an enum type into a message? How's it done?



edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2011-03-15 06:28:56 -0500

kwc gravatar image

You can use constants in ROS messages:

They don't map explicitly to higher-level enum types in programming languages, but they generally let you deal with the same issues.

edit flag offensive delete link more


Do you mean something like .. create an integer field, then create a series of constant fields to map integer values to the enumerated types?
Murph gravatar image Murph  ( 2011-03-15 06:49:21 -0500 )edit
@Murph: that's correct
kwc gravatar image kwc  ( 2011-03-15 09:48:30 -0500 )edit

I know this is a very old chain, however has this been implemented? Could I have a look?

arunavanag gravatar image arunavanag  ( 2017-04-27 01:48:45 -0500 )edit

answered 2013-11-29 00:10:14 -0500

lucasw gravatar image

updated 2013-11-29 00:31:14 -0500

Here is an example from joystick_drivers :

$ rosmsg show sensor_msgs/JoyFeedbackArray 
sensor_msgs/JoyFeedback[] array
uint8 TYPE_LED=0
uint8 type
uint8 id
float32 intensity

There is nothing special or required about the constants TYPE_LED and TYPE_RUMBLE being capitalized or having a prefix in common with the field 'type' for which they are supposed to be the values it ought to have.

In the usage of the enum like fields is shown for Python:

def set_feedback(self,msg):
  for feedback in msg.array:
    if feedback.type == sensor_msgs.msg.JoyFeedback.TYPE_LED and < 4:
      self.led_values[] = int(round(feedback.intensity))
    elif feedback.type == sensor_msgs.msg.JoyFeedback.TYPE_RUMBLE and < 2:

In C++ it would look like this:

if (msg->waveform == sensor_msgs::JoyFeedback::TYPE_RUMBLE)
edit flag offensive delete link more

Question Tools



Asked: 2011-03-15 06:14:13 -0500

Seen: 26,124 times

Last updated: Nov 29 '13