Robotics StackExchange | Archived questions

ros2 msg field name reservations

I tried to use the followin self-defined msg interface:

# MyInterface.msg
MyHeader header

and

# MyHeader.msg
uint8 id
Point3f origin

it looks like the field name header in MyInterface.msg is reserved, the msg package could be built successful, but when i use the msg to initialize a subscription by

sub_ = this->create_subscription<my_interface::msg::MyHeader>("stub_topic", 10, std::bind(&ClassNmae::sub_cb, this, _1));

and I got errors when build:

...
/opt/ros/galactic/include/libstatistics_collector/topic_statistics_collector/received_message_age.hpp:79:33: error: ‘const _header_type’ {aka ‘const struct my_interface::msg::MyHeader_<std::allocator<void> >’} has no member named ‘stamp’
   79 |     const auto stamp = m.header.stamp;
      |                        ~~~~~~~~~^~~~~
...

by changing header to a more regular word like my_header, the error disappeared.

my question is:

  1. is this a field name reservation related issues?
  2. if it is, where can i find some official docs explain about this?

i have refered to http://design.ros2.org/articles/interface_definition.html#naming-of-messages-and-services

but only found limited informations and no direct clues about my question.

can i have some help? thx

Asked by fury.nerd on 2023-04-19 00:28:08 UTC

Comments

Answers

You code with create_subscription has error in the std::bind - you have &ClassNmae::sub_cb here + there is no stamp in the MyHeader.msg definition.

Did you want to use std_msgs/Header.msg? It is a different thing, widely used, so the name clash was possible.

Asked by ljaniec on 2023-04-19 03:09:11 UTC

Comments

thanks for answering, but in the callback funcion sub_cb, i involved nothing about stamp, I only accessing legal fields defined in MyHeader.msg and MyInterface.msg.

i understand std_msgs/Header.msg is widely used, but as you mentioned, is different and not concerned in my case...

as the errors nav to some buitin method in rclcpp, whereas if i change header to a more regular word like my_header, the error disappeared. i still doubt it is a reservation issue, like weird defines (e.g. string string), but wish to find some official description...

Asked by fury.nerd on 2023-04-19 03:16:24 UTC

Ok, I think other parts of the nodes are checking the header for stamp then. It seems like an undocumented code requirement. I also couldn't find an official description in ROS2 repositories nor documentation. Can you try to modify your my_interfaces package and its MyInterface.msg definition with my_interface/MyHeader header? Just to be sure.

Asked by ljaniec on 2023-04-19 03:57:18 UTC

tested my_interface/MyHeader header, but same error...looks like header is indeed a reserved field name...

Asked by fury.nerd on 2023-04-19 20:39:52 UTC

Hi, I encountered the same issue. I modify the MyHeader header into MyHeader my_header to solve it.

That works although I don't know why that work. Perhaps the header field is not permitted in customized msg.

Asked by nofear123 on 2023-04-21 05:27:41 UTC

Comments