Naming conventions for ros2 msgs

Hi,

Will it be allowed to put ‘_’ in the name of a ros2 msg?

In ros2 wiki it is not defined: https://github.com/ros2/ros2/wiki/About-ROS-Interfaces

In ros1 wiki it is mentioned to put the name in camelcase and therefore no underscore seems to be allowed: http://wiki.ros.org/ROS/Patterns/Conventions under 2.3 Messages

Is this also the case for ros2?

For ROS 2 the format of the interface files is specified in http://design.ros2.org/articles/interface_definition.html#naming-of-messages-and-services. The naming scheme for the filename hasn’t changed since ROS 1 and still only allows alphanumeric characters.

1 Like

I realize this is an old thread, but (I hope) this is related: is there documentation somewhere about the naming conventions for the generated message headers in ROS 2? The .msg files are all CamelCase, but the .hpp file names all seem to be converted to snake_case, which was a bit confusing at first.

@dirk-thomas’s link above mentions

Both file names must use an upper camel case name and only consist of alphanumeric characters.

So that’s for .msg & .srv files.

As for snake_case headers, that’s just file naming convention. While it doesn’t explicitly talk about it, the Introduction to msg and srv interfaces tutorial (although it’s a draft) does use snake_case headers.

@christophebedard Thanks, yes, I realize that now. My confusion was that, from the tutorial, I thought it just made the file names lower case (in the tutorial Num.msg becomes num.hpp). So I had defined a message file like Foo3D.msg and I tried including it as foo3D.hpp, which didn’t work. I had to use foo3_d.hpp.

Hey i know it’s an old thread but I’m learning ROS now and I’ve been trying to find info on precisely this.
So what I gather is that the msg and or srv should be named with camel case and then it will become an .hpp of the form "all lowercases and an underscore before every upercase in the the original camelcase name + .hpp?

Thanks for any clarification

Yes, that’s pretty much it.

2 Likes

Specifically, this is called snake case.

Isn’t this pascal case?

Camel case would start the identifier with a lower-case letter.

thank you!
So… if I named a .msg “Sensor3DState.msg” what would the .hpp be?
sensor3_Dstate.hpp? sensor3_d_state.hpp?
Or I should I also never name anything that allows for 2 Caps to be together… which i guess makes sense.
and also… why does it seem to be an obvious thing? i dont see it mentioned or explained anywhere. Granted im a noob to it all but is like everyone understands it and is obvious. But I dont see it explained. Is it a C++ thing or a ROS thing?

Thanks!

I dont know… i know i know nothing. :confused:

I believe it will be the latter: sensor3_d_state.hpp (though I’m not 100% sure of that). Easy enough to test.

It’s a ROS thing. And you are right, I don’t see it anywhere explicitly mentioned in the documentation. I guess an obvious place to put it would be in Interface definition using .msg / .srv / .action files , though I can see a case for putting it in the documentation on ROS 2 Documentation — ROS 2 Documentation: Rolling documentation (which is generated from GitHub - ros2/ros2_documentation: ROS 2 docs repository). If you’d be willing to open a PR explaining it, I’d be happy to review.