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

ros2 msg field name reservations

asked 2023-04-19 00:28:08 -0500

fury.nerd gravatar image

updated 2023-04-19 00:34:44 -0500

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/inter...

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

can i have some help? thx

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2023-04-21 05:27:41 -0500

nofear123 gravatar image

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.

edit flag offensive delete link more
0

answered 2023-04-19 03:09:11 -0500

ljaniec gravatar image

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.

edit flag offensive delete link more

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...

fury.nerd gravatar image fury.nerd  ( 2023-04-19 03:16:24 -0500 )edit

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.

ljaniec gravatar image ljaniec  ( 2023-04-19 03:57:18 -0500 )edit

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

fury.nerd gravatar image fury.nerd  ( 2023-04-19 20:39:52 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2023-04-19 00:28:08 -0500

Seen: 163 times

Last updated: Apr 21 '23