ros2: embedding a msg as a field in a custom msg
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).
"manually"?
Are you referring to prefixing the field type with the fully qualified package name that hosts the message?
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 copingstd_msgs/Header
message definition to my custom message. I feel like this is wrong though.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).
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?