ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How to add a Time field in a custom message file

asked 2020-09-28 11:35:38 -0500

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.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2020-09-28 11:39:13 -0500

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
...
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-09-28 11:35:38 -0500

Seen: 2,100 times

Last updated: Sep 28 '20