Ask Your Question
1

ros2: embedding a msg as a field in a custom msg

asked 2019-02-05 01:10:36 -0500

Obeseturtle gravatar image

updated 2019-02-05 08:22:17 -0500

gvdhoorn gravatar image

Hi,

In ROS, I could import other messages using headers.

Header header
int32 cout
int32 nch
int32 lenght

This way I could include std_msg's stamp and frame_id. Other wise, I have to add them manually but I am not sure if this is ideal or not.

unit32 seq
builtin_interfaces/Time stamp
string frame_id    
int32 count
int32 nch
int32 lenght

I tried using std_msgs/Header header but I received error message.

Message interface 'std_msgs/Header' contains an unknown field type: std_msgs/Header header

I added find_package(std_msgs REQUIRED) to my CMakelist, I am not sure if I am missing anything else

I looked at how other ROS2 msg's used the messages I wanted to use but it seems they are doing it manually as well link text. I was wondering if it would be okay for me to do this too(writing it manually).

edit retag flag offensive close merge delete

Comments

I was wondering if it would be okay for me to do this too(writing it manually).

"manually"?

Are you referring to prefixing the field type with the fully qualified package name that hosts the message?

gvdhoorn gravatar imagegvdhoorn ( 2019-02-05 02:08:05 -0500 )edit

If by prefixing you mean adding the std_msgs/Header to my custom message then no. Doing this will result in an error as pointed in the description. By "manually" I meant coping std_msgs/Header message definition to my custom message. I feel like this is wrong though.

Obeseturtle gravatar imageObeseturtle ( 2019-02-05 02:43:18 -0500 )edit

No, copying (sub) message types into your own custom message is not needed, and would undermine the entire idea of software reuse (which also applies to message/type definitions).

gvdhoorn gravatar imagegvdhoorn ( 2019-02-05 02:45:52 -0500 )edit

So, that would mean there is a way of importing the message I want to use to the custom message(I am sorry for not using the correct terms) Since I want to add the messages defined in std_msgs/Header to my custom message, is there a line of code I am missing?

Obeseturtle gravatar imageObeseturtle ( 2019-02-05 03:22:40 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-02-05 03:36:40 -0500

Obeseturtle gravatar image

The issue I was having was caused by not adding the std_msgs to the dependencies of my CMakelist.

find_package(std_msgs REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  ${msg_files}
  DEPENDENCIES builtin_interfaces std_msgs

Using std_msgs/Header on my custom message's .msg file no longer produces an error.

std_msgs/Header header
string frame_id    
int32 count
int32 nch
int32 lenght
edit flag offensive delete link more

Comments

Although I am able to use the message now, when I try ros2 topic echo , the embedded message is not being printed, to be more specific std_msgs/Header header's stamp. Although I receive no error messages when assigning a value to it when publishing the message, echo will return an empty field.

Obeseturtle gravatar imageObeseturtle ( 2019-02-06 03:08:08 -0500 )edit

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-02-05 01:10:36 -0500

Seen: 171 times

Last updated: Feb 05