I got an error with the following message when building a package with custom ROS2 Message.
rosidl_adapter.parser.InvalidFieldDefinition: geometry_msgs/Twist
I'm creating a new ROS2 Package to provide definitions of my custom message type like this:
src/msgs
├── CMakeLists.txt
├── msg
│ └── TwistAccel.msg
└── package.xml
Where my custom message defined like this:
TwistAccel.msg
geometry_msgs/Twist
geometry_msgs/Accel
According to the documents of ROS2 Foxy, I modified the CMakeLists.txt and package.xml like this:
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(msgs)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"msg/TwistAccel.msg"
)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()
package.xml:
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>msgs</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="charlie@todo.todo">charlie</maintainer>
<license>TODO: License declaration</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>geometry_msgs</depend>
<build_depend>rosidl_default_generators</build_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Then I run the colcon build --packages-select msgs command to build this package. However, I got the error mentioned before.
I have also tried modifying the TwistAccel.msg content from geometry_msgs/xxx to geometry_msgs/msg/xxx, but it still raises the same InvalidFieldDefinition to that.
I guess I'm missing something in the CMakeLists.txt or in package.xml. But I don't know what that is.