Ask Your Question

genmsg.base.InvalidMsgSpec: array is not a legal constant type

asked 2016-09-27 10:41:11 -0500

spmaniato gravatar image

updated 2016-09-27 11:37:11 -0500

According to , "With the exception of time and duration, you may declare any built-in type as a constant."

However, when I try this:

uint8[3] color
uint8[3] BLACK = {0,0,0}

I get:

genmsg.base.InvalidMsgSpec: [...] uint8[3] is not a legal constant type

I've also tried [0,0,0] and (0,0,0) but it didn't make a difference. The error is about the the type, not the value. std_msgs/UInt8[3] didn't work either.

Am I messing up the syntax or is it just that ROS msg constants cannot be arrays?

PS1. My goal here is to create constants for common RGB colors, such as BLACK, RED, GREEN, BLUE.

PS2. Can I somehow leverage std_msgs/ColorRGBA in order to define these constants in my custom message?

Update: As Dirk's answer points out, arrays of built-in types are not built-in types themselves. For my usecase (RGB colors), I ended up using a single integer to represent the 3 RGB values. See, for example,

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-09-27 10:58:39 -0500

Dirk Thomas gravatar image

Arrays are not built-in types. Therefore you can't define constants of type array.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-09-27 10:41:11 -0500

Seen: 645 times

Last updated: Sep 27 '16