0
$\begingroup$

Rosanswers logo

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


Originally posted by Obeseturtle on ROS Answers with karma: 185 on 2019-02-05

Post score: 4


Original comments

Comment by gvdhoorn on 2019-02-05:\

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?

Comment by Obeseturtle on 2019-02-05:
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.

Comment by gvdhoorn on 2019-02-05:
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).

Comment by Obeseturtle on 2019-02-05:
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?

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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

Originally posted by Obeseturtle with karma: 185 on 2019-02-05

This answer was ACCEPTED on the original site

Post score: 8


Original comments

Comment by Obeseturtle on 2019-02-06:
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.

Comment by fiji3119 on 2020-05-28:
Just what I was looking for - Thanks! Was having same error.

Comment by fabbro on 2022-03-08:
I was having the same error. My problem was that in the .msg file I had Header header instead of std_msgs/Header header. After fixing it, my package for the interfaces builds (I am on ROS2 too).

Comment by aniltirli on 2023-03-24:
@Obeseturtle Could you figure out "empty field" problem ? I am also not seeing any values under stamp and frame_id.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.