Robotics StackExchange | Archived questions

How to add a Time field in a custom message file

I am trying to create a custom message type using a .msg file in ROS2. The message generation works properly for basic fields such as int8, float32, etc.

However I am finding difficulties adding a Time field.

I noticed that the Time message should be located in the builtin_interfaces. I configure CMakeLists.txt and package.xml file to consider that but it does not work.

find_package(ament_cmake REQUIRED)
find_package(std_msgs REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
"msg/MyCustomMessage.msg"
DEPENDENCIES builtin_interfaces)

package.xml:

<package>
...
<buildtool_depend>ament_cmake</buildtool_depend>
  <build_depend>rosidl_default_generators</build_depend>
  <exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>

<depend>std_msgs</depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<depend>builtin_interfaces</depend>
...
</package>

Error: /home/geus/Desktop/rosws/build/mypackagemsgs/rosidlgeneratorcpp/mypackagemsgs/msg/detail/mycustommessagestruct.hpp:19:10: fatal error: mypackagemsgs/msg/detail/timestruct.hpp: No such file or directory 19 | #include "mypackagemsgs/msg/detail/time_struct.hpp" compilation terminated.

Asked by Pablo Iñigo Blasco on 2020-09-28 11:35:38 UTC

Comments

Answers

Found. You have to add the package prefix into the .msg Time field. Below, It is shown an example of .msg file chunk:

builtin_interfaces/Time stamp
int8 value1
...

Asked by Pablo Iñigo Blasco on 2020-09-28 11:39:13 UTC

Comments