出现这个问题就是说你起的那个文件名称格式有问题,比如说mymsg.msg就会有故障
应该改写为Mymsg.msg.这可能是个正则表达式表示一定要以大写字母开头^[A-Z]
下面提供一个可以正确执行的代码参考:
cmake_minimum_required(VERSION 3.8)
project(custom_srv)
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)
find_package(geometry_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Mymsg1.msg"
"msg/Mymsg2.msg"
"srv/Myservice1.srv"
DEPENDENCIES geometry_msgs
)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package( REQUIRED)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()
custom_srv
0.0.0
TODO: Package description
actorsun
TODO: License declaration
ament_cmake
ament_lint_auto
ament_lint_common
geometry_msgs
rosidl_default_generators
rosidl_default_runtime
rosidl_interface_packages
ament_cmake
Mymsg1.msg文件
int64 num
Mymsg2.msg文件
geometry_msgs/Point center
float64 radius
Mysrv1.srv文件
int64 a
int64 b
int64 c
---
int64 sum
可以参考这个ros2 自定义msg_ros2 自定义message-CSDN博客