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.
- Which packages should I import in package.xml?
- What specific stuff should I do in CMakeLists.txt?
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/ros_ws/build/my_package_msgs/rosidl_generator_cpp/my_package_msgs/msg/detail/my_custom_message__struct.hpp:19:10: fatal error: my_package_msgs/msg/detail/time__struct.hpp: No such file or directory 19 | #include "my_package_msgs/msg/detail/time__struct.hpp" compilation terminated.